# An example of a decent makefile. For examples of truly spectacular # makefiles, look at the Linux kernel source. You may not even need # all the features I'm using here! # A few convenience variables. They come in handy later. BAD_PROGRAMS = not_null_ending_string mem_leak dang_ref GOOD_PROGRAMS = file_open_close input_read malloc_fish \ sort recursive_factorial proc_quick hostname \ strtok_r_path PROGRAMS = $(GOOD_PROGRAMS) $(BAD_PROGRAMS) CFLAGS = -Wall -Wextra -std=gnu99 CC = gcc # Already proving their worth! all: $(PROGRAMS) # Implicit rule - any time we need a .o file in an explicit rule, # we look for a .c file with the same base name # and make a .o file out of it. %.o : %.c $(CC) $(CFLAGS) -c $< % : %.o $(CC) -o $@ $^ # One more time, convenience of variables! clean: rm -f *.o $(PROGRAMS) tmp