# The program "make" looks for a file called "Makefile" or "makefile" in # the current directory. It will not find the file if it is called "MAKEFILE" # or "Makefile.txt" # Any line beginning with a `#' sign is a comment and will be # ignored by the "make" command. # Choose the compiler. (There are others!) CC = gcc # List our usual flags. These ones make the compiler very careful. CFLAGS = -pipe -ansi -pedantic -Wall -Wpointer-arith -Wcast-qual \ -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes \ -Wmissing-prototypes # We need to include the mathematical library if we want to use "sqrt", # for example. We might want other libraries too, and in that case we # would add them here. LIBS = -lm # To run a debugger, we want to compile with the "-g" flag set. # The first line below defines the debugging flag. The second sets # "NEWFLAGS" to contain the debugging flag if the user's command line is: # make DEBUG=TRUE # (instead of just plain "make" as usual). And the third line below # adds NEWFLAGS to the end of the standard list of flags. DEBUGFLAGS = -g NEWFLAGS = $(DEBUG:TRUE=$(DEBUGFLAGS)) CFLAGS += $(NEWFLAGS) # Within a makefile, you can ask "make" to call practically any Unix command. # Ordinarily the command itself is displayed before it is executed, but if # you begin the line in the makefile with "@", the command is not displayed. # These lines cause "make" to display its flag settings if it is called without # any arguments. @echo "Flag settings with options as called:" @echo DEBUGFLAGS=$(DEBUGFLAGS) @echo NEWFLAGS=$(NEWFLAGS) @echo CFLAGS=$(CFLAGS) # The next entry lets us compile all the executables at once. # If "make" seems not to be doing anything, the output files are presumably # up to date already. To see them all being compiled, just remove the # executable files and call make again. all: hello careful math hello : hello.c $(CC) $(CFLAGS) -o hello hello.c chmod 755 hello # The "chmod" line makes it so that you can use the executable file # "hello". If the line were left out, I could use it but not you. # Notice that all the commands to construct "hello" are on lines # following the line "hello : ". And notice that the commands ARE # ALL INDENTED BY ONE TAB STOP. No tab, no work! careful : careful.c $(CC) $(CFLAGS) -o careful careful.c chmod 755 careful math: math.c $(CC) $(CFLAGS) -o math math.c $(LIBS) chmod 755 math # This entry lets us use "make clean" to get rid of junk files. clean: rm -f a.out core *.o