## ## sample makefile, written by Jeff Juliano for COMP 121L class on Sept 10 ## ## The '#' character at the beginning of a line means that the line is a ## comment. I use a double '##' to denote editorial comments, ## and a single '#' to mark "code" that I have temporarily commented out. ## ## a makefile should be in the same directory as your project. It ## should be named either "Makefile" or "makefile". The capitalize ## version is better, because make will use that one if both versions exist. ## the next 2 lines specify the compiler and the compiler switches ## the compiler switch -g tells the compiler to compile in a ## way that a debuGger will understand the program ## the -Wall switch turns on all warnings (you should ALWAYS do this) ## the -ffor-scope switch fixes a bug in the current version of g++ ## if you don't use g++, get rid of -Wall and -ffor-scope CXX = g++ CXXFLAGS = -g -Wall -ffor-scope ## create a variable containing the names of all the .C files SRCS = array.C string.C string.array.C menu.C demo.C ## create a variable containing the names of all the .o files ## compute the value from SRCS OBJS = $(SRCS:.C=.o) ######################### rules follow ################################## ## this will link all the files and call the executable "demo" ## Note: the link rule must be the first rule in the makefile demo: $(OBJS) g++ -o $@ $(OBJS) ## the following is a list of dependencies ## NOTE: there are no compilation rules given, do the default will be used array.o: array.C array.h string.o: string.C string.h string.array.o: string.array.C string.array.h array.h string.h menu.o: menu.C menu.h demo.o: demo.C string.array.h menu.h ## Default rule for compiling all .C files without an explicit rule ## You can override the default by simply providing an explicit one ## This is read "to go to a .o from a .C, do the following rule" ## ## as before, a -c flag is needed to tell it to compile and not link ## $< expands to the name of the first file to the right of the colon ## $@ expands to the name to the left of the colon %.o : %.C $(CXX) $(CXXFLAGS) -c $< -o $@ ## this rule will remove the executable and all the .o files ## note that there are no dependencies clean: /bin/rm -f $(OBJS) demo
原文链接:http://www.unc.edu/~mserre/mfEx/mf3