UNIXworkcode

1 # $Id: Makefile.depend,v 1.5 2003/05/20 00:27:55 n8gray Exp $ 2 # 3 # This is a _generic_ Makefile to generate a dependency file 4 # using GNUmake and gcc. 5 # Advantage of this method (as compared to "makedepend(1)") 6 # is that one can easily filter out dependencies on 7 # non-application (i.e. system) headers using the -MM flag 8 # of gcc. The reason to demand GNUMake is basically to have a nice, 9 # simple rule for $(SRCS) as done below (and for the variable 10 # transformations). 11 # So one doesn't have to modify this file and manually add/update 12 # the source file list! 13 # 14 # To use it just you probably just have to edit the 15 # variables in the *CONFIG section* as you see fit. 16 17 18 # ***************** CONFIG section ***************** 19 20 GCC=gcc 21 DEFINES= 22 CPPFLAGS=-I$(HOME)/include 23 DEPENDFILE=dependencies 24 SHELL=/bin/sh 25 26 # Headers are required to determine _all_ files 27 # on which the dependency file itself may depend 28 SRCS=$(wildcard *.c) 29 HDRS=$(wildcard ../source/*.h) $(wildcard ../util/*.h) 30 31 # *************** End CONFIG section ************ 32 33 34 35 # ************** Now the generic part *********** 36 37 .SUFFIXES: .c .o. deps 38 .PHONY: all default deps new 39 40 41 DEPS=$(SRCS:.c=.deps) 42 43 default: all 44 45 # This is the more conservative approach 46 full: clean new deps 47 48 # And this a more sophisticated one 49 all: $(DEPENDFILE) 50 51 # Remove old file, create new one and add CVS info line at top 52 new: 53 /bin/rm -f $(DEPENDFILE) 54 echo '# $$''Id''$$' >$(DEPENDFILE) 55 56 57 $(DEPENDFILE): new $(SRCS) $(HDRS) 58 $(GCC) $(CPPFLAGS) $(DEFINES) -MM $(SRCS) >>$(DEPENDFILE) 59 60 deps: $(DEPS) 61 62 %.deps: %.c 63 $(GCC) $(CPPFLAGS) $(DEFINES) -MM $< >>$(DEPENDFILE) 64 65 verify_config: 66