Path: utzoo!attcan!uunet!decwrl!bacchus.pa.dec.com!deccrl!shlump.nac.dec.com!bonz!fjs From: fjs@bonz.ogo.dec.com (Jay Shields) Newsgroups: comp.software-eng Subject: Re: Anyone know of a "better" 'make' than vanilla System-V's?. Message-ID: <1990Oct11.100046@bonz.ogo.dec.com> Date: 11 Oct 90 14:00:46 GMT Sender: newsdaemon@shlump.nac.dec.com Reply-To: fjs@bonz.ogo.dec.com (Jay Shields) Organization: Digital Equipment Corporation Lines: 105 In article <1990Oct3.000440.5275@hades.ausonics.oz.au> greyham@hades.ausonics.oz.au (Greyham Stoney) writes: >* Dependancies must be explicitly listed in the Makefile; and they are never > kept up to date: No ammount of forcing people is going to keep them up > to date, and it's a pretty pointless exercise anyway. [...] > Why can't the dependancies be discerned from the source file at > make time? If you don't have Imake or any of the other tools mentioned, and if you just want to improve your current makefiles, the sample makefile below containes an example of the "depend" target that a few other articles have mentioned. It's a pretty simplistic example, of course, but it should give you the basic idea. The "depend" target can be used pretty much as-is in your Makefiles if you just define the macros correctly. BTW, just in case it's not totally clear from the example below, when you run "make depend", the Makefile will be regenerated with a new set of dependencies for each source file. The old Makefile will be stored in a file called makeback. If there is no difference in the old and new Makefiles, makeback will not be created. Assumptions, Limitations, Notes and other stuff: 1. This works for C code only! 2. Your C preprocessor must support the -M switch (some compilers allow you to get the same results using: cc -Em) 3. The use of @- on the depend rule line may be dangerous. The - (which ignores errors) is needed because the cmp function returns a value of 1 if the two makefiles are different, which will stop the make if the - is not there. If you remove the - for safety reasons, be sure to remove the check for differences between the two makefiles. 4. Lots of others, but give it a shot! 5. No warrantee expressed or implied! 8-)> Makefile: ######################################################################## # CSRC macro defines all of the C programs in you current directory CSRC = fake_prog.c # Use CPP to define your C pre-processor CPP = /lib/cpp # Some cc options should be passed on to the pre-processor (such as -D). # Others (Such as -l) should not. CFLAGS could then be composed of CPP_FLAGS # plus misc. flags. CPP_FLAGS = -Dfakedefine # INCLUDE_LIBS tells the C pre-processor where to look for include files. You # really should have such a macro already defined for use with cc. INCLUDE_LIBS = -I/usr/src/include_dir # Here's the depend target. depend: @-sed '/^###DEPENDENCIES/,$$d' < Makefile > tmp_make ; \ echo "###DEPENDENCIES Follow. Do not delete this line" >> tmp_make ; \ echo >> tmp_make ; \ for i in $(CSRC); \ do \ $(CPP) -M $(CPP_FLAGS) $$i $(INCLUDE_LIBS) | sort -r | uniq >> tmp_make ; \ echo >> tmp_make ; \ done >> tmp_make ; \ echo >> tmp_make ; \ echo "# End of Dependency list" >> tmp_make ; \ echo "# Anything after this line will be deleted" >> tmp_make ; \ echo "# when the next \"make depend\" is done." >> tmp_make ; \ cmp Makefile tmp_make > tmp_compare ; \ if [ -s tmp_compare ] ; then \ mv Makefile makeback ; \ mv tmp_make Makefile ; \ else \ rm -f tmp_make ; \ fi ; \ rm -f tmp_compare ; \ chmod 664 Makefile # ###DEPENDENCIES Follow. Do not delete this line fake_prog.o: fake_prog.c fake_prog.o: /usr/include/stdio.h fake_prog.o: /usr/include/sys/types.h fake_prog.o: /usr/src/include_dir/fake_inc.h # End of Dependency list # Anything after this line will be deleted # when the next "make depend" is done. ######################################################################## The list of dependencies below the ###DEPENDENCIES line are just an example of the type of list generated for each source file. Hope this helps! -- F. Jay Shields "I know how to make friends. How do imake friends?" Digital Equipment Corporation Littleton, MA fjs@bonz.ogo.dec.com (508) 952-3238