# tell it what compiler to use CC=g++ # turn on all warnings and high optimization CFLAGS=-Wall # list the compile flags LDFLAGS=-Wall # linking flags could be different # list the programs to build here TARGETS=foo bar # the name of the text files for the formatted source and output TEXT=prog.txt FOO_OUT=foo.txt BAR_OUT=bar.txt help: @echo "all: builds targets" @echo "run: builds and runs both, outputs to text files" @echo "text: creates text for source and output" @echo "clean: removes all binaries and the text file" all: $(TARGETS) run: all ./bar > $(BAR_OUT) ./foo > $(FOO_OUT) text: run pr -n -l 56 Makefile *.h *.cpp \ $(BAR_OUT) $(FOO_OUT) > $(TEXT) # standard macro expansions in make # $^ : all dependancies # $< : first dependancy - warning : it better be a .cpp file # $@ : target # dependancy list bar: listcon.o bar.o $(CC) $(LDFLAGS) $^ -o $@ foo: listcon.o foo.o $(CC) $(LDFLAGS) $^ -o $@ bar.o: bar.cpp listcon.h list.h $(CC) $(CFLAGS) -c $< foo.o: foo.cpp listcon.h list.h queue.h stack.h $(CC) $(CFLAGS) -c $< listcon.o: listcon.cpp listcon.h dnode.h $(CC) $(CFLAGS) -c $< # remove the binaries to include the .o files and the text files clean: -rm -f *.o $(TARGETS) $(TEXT) $(BAR_OUT) $(FOO_OUT)