# $Id: Makefile 738 2008-02-09 00:55:52Z phf $ # # Simple Makefile with a few targets, including the common # targets "all" to build all targets in the project as well # as "clean" to remove targets and temporary files, getting # back a "clean slate". # # Note that it is *very* important to use *tabs* in lines # that contain commands, *not* spaces! Strange file format, # but that's what it is, no use complaining about it. :-/ CFLAGS=-ansi -pedantic -Wall -Wextra -std=c99 -O CC=gcc # The first target is what gets built if you just say # "make" on the command line; it's "tradition" to call # it "all" and build all other targets from it. all: cat wc functions grep arrays rpn # You can provide an explicit command to build the target, # but in this case you shouldn't since the default rule is # quite good enough... :-) cat: cat.c # gcc $(CFLAGS) -o cat cat.c functions: functions.c # For the RPN calculator we need to do a little more, since # we want to build stack.o and rpn.o separately, then link.o # Again, note the $^ special allowing us to refer to all the # dependencies without listing them again redundantly. :-) # Also, stack.o and rpn.o get build correctly with default # rules, so nothing else is necassry to state explicitly. rpn: stack.o rpn.o gcc $(CFLAGS) $^ -o rpn # for the others, we just rely on the defaults... # Example for various indentation styles, including Peter's # preferred style (well, not quite, but close)... :-) Note # that this works only with GNU indent, BSD indent (OS X) # doesn't know what -gnu or -kr is; so install GNU indent # if you want to follow these. indent: indent -gnu grep.c -o grep_gnu.c indent -kr grep.c -o grep_kr.c indent -orig grep.c -o grep_bsd.c indent -kr -nce -ncdw -ci2 -cli2 -i2 grep.c -o grep_phf.c # The "clean" target doesn't produce anything, so we mark # it "PHONY"; if you want the details, just google around. .PHONY: clean clean: rm -rf cat wc functions grep grep_*.c arrays *.o rpn