######################################################################### # # Intelligent Makefile # # Copyright (C) 1998 Markus Mottl # ######################################################################### # Note: you may also call this makefile with the appropriate variables # e.g.: "make CXXFLAGS=-g" # Place the names of your sources to link and of the binary here SOURCES = reent.cc reent.l reent.y BINARY = reent # Add a list of trash files that should be deleted if necessary TRASH = # Eventually set include- and library-paths and the libraries to link INCDIRS = LIBDIRS = LIBS = LDFLAGS = ######################################################################### SHELL = /bin/sh # -Wsign-compare and -Wuninitialized (in -Wall) turned off because of problems # with some libraries! (STL) # Turn these warnings temporarily on if you want to check *your* code! WARN = -Wall # some programs (lex/yacc) may produce code that has unused variables... NOWARNAUTO = CXX = g++ CXXFLAGS = INCFLAGS = $(patsubst %,-I%, $(INCDIRS)) ALL_CXXFLAGS = $(WARN) $(CXXFLAGS) $(INCFLAGS) LD = $(CXX) ALL_LDFLAGS = $(LDFLAGS) $(patsubst %,-L%, $(LIBDIRS)) $(patsubst %,-l%, $(LIBS)) LEX = flex LFLAGS = -+ YACC = bison YFLAGS = -d FILTERED = $(filter %.cc %.c %.l %.y, $(SOURCES)) OBJECTS_3 := $(FILTERED:.l=.l.o) OBJECTS_2 := $(OBJECTS_3:.y=.tab.o) OBJECTS_1 := $(OBJECTS_2:.cc=.o) OBJECTS := $(OBJECTS_1:.c=.o) DEP_SOURCES_3 := $(filter %.y %.l, $(FILTERED)) DEP_SOURCES_2 := $(DEP_SOURCES_3:.l=.l.C) DEP_SOURCES_1 := $(DEP_SOURCES_2:.y=.tab.C) DEP_SOURCES := $(DEP_SOURCES_1) $(patsubst %.y,%.tab.h, $(filter %.y, $(FILTERED))) MAKEDEPS_3 := $(FILTERED:.l=.l.d) MAKEDEPS_2 := $(MAKEDEPS_3:.y=.tab.d) MAKEDEPS_1 := $(MAKEDEPS_2:.cc=.d) MAKEDEPS := $(MAKEDEPS_1:.c=.d) TARGETS := $(strip $(BINARY) $(OBJECTS) $(DEP_SOURCES) $(MAKEDEPS)) ######################################################################### # GENERAL RULES all: $(BINARY) %.o: %.cc $(CXX) -c $(ALL_CXXFLAGS) $< %.o: %.C $(CXX) -c $(ALL_CXXFLAGS) $(NOWARNAUTO) $< .PRECIOUS: %.l.C %.l.C: %.l $(LEX) $(LFLAGS) -o$@ $< .PRECIOUS: %.tab.C %.tab.C %.tab.h: %.y $(YACC) $(YFLAGS) -b $* $< @mv $*.tab.c $*.tab.C %.d: %.cc @echo making $@ from $< @rm -f $@ @$(CXX) -M -MG $(ALL_CXXFLAGS) $< | \ sed -e 's/$*\.o/& $@/g' > $@.tmp @mv $@.tmp $@ %.d: %.C @echo making $@ from $< @rm -f $@ @$(CXX) -M -MG $(ALL_CXXFLAGS) $< | \ sed -e 's/$*\.o/& $@/g' > $@.tmp @mv $@.tmp $@ $(BINARY): $(OBJECTS) $(LD) -o $(BINARY) $(OBJECTS) $(ALL_LDFLAGS) ######################################################################### # MAINTAINANCE RULES .PHONY: clean clean: rm -f core $(TARGETS) $(TRASH) ######################################################################### ifndef omit_deps -include $(MAKEDEPS) endif