Path: utzoo!mnetor!uunet!husc6!think!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpsemc!bd From: bd@hpsemc.UUCP (bob desinger) Newsgroups: comp.sources.wanted Subject: Re: Desperately Seeking Makefile Maker Message-ID: <3610003@hpsemc.UUCP> Date: 18 Dec 87 21:15:14 GMT References: <1034@cpocd2.UUCP> Organization: HP SEMC, Cupertino, CA Lines: 143 Lloyd Zusman writes [edited]: "What about nested includes? What about #includes that use double quotes or angle brackets?" Chris Torek wrote a script called `depend' that handles those. It appears below. Run it with a command like `depend *.c' and your output will appear on stdout in make-rule format. Marshall Rose wrote some rules for `make' that append the dependency list to your Makefile. It's below too, in "makedepend". You just suck it into your Makefile, edit the line mentioned there to be edited, and type `make depend'. It examines the files you specify, creating the list of dependencies. If you don't have an existing list of dependencies in your Makefile, it injects it into the Makefile. If you already have one in the right format, it updates the list (actually, it wipes the old list clean and re-creates a new one from scratch). But what if you want to do more than just generate dependency lists? Lloyd further writes: > There is something much better called 'mkmf' that makes makefiles. It > handles the above cases just fine and produces a useful makefile. As > far as I know, it's "netware", which means it's public domain and is > distributed over the net. Written by Peter Nicklin, a program called `mkmf' was distributed with 4.2BSD. Be careful about sending that one around; it was on the Contributed Sources tape, so I'm not sure if it's okay to send it to anyone or if recipients need the usual BSD (and AT&T) source licenses. There's another script called, I think, `makemake' that really did appear on the Usenet as public-domain software. I couldn't find it in my archives; maybe I threw it away after months of non-use. Anyone have it? bob desinger Hewlett-Packard Co., Cupertino, CA #! /bin/sh # This is a shell archive. Remove anything before this line, # then unwrap it by saving it in a file and typing "sh file". # # Wrapped by bd at hpsemc on Fri Dec 18 12:41:38 1987 # Contents: # depends makedepend PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH echo 'At the end, you should see the message "End of shell archive."' echo Extracting depends cat >depends <<'@//E*O*F depends//' : getdep - get dependency lists. # In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) # Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris : change ":" comments to "#" comments if your shell supports those; : the result will run faster. : find cpp cpp=unknown for where in /lib /usr/lib /bin /usr/bin; do if test -f $where/cpp; then cpp=$where/cpp; break; fi done if test $cpp = unknown; then echo "I cannot find cpp, sorry" 1>&2; exit 1 fi : handle arguments incl= for i do case "$i" in -I*) incl="$incl $i";; *) : assume source file : put '$dep' in front of dependencies dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'` : Find includes, remove leading numerics, remove ./, : remove double quotes, and remove trailing numerics. : Sort that, discarding duplicates, and add '$dep'. $cpp $incl "$i" | grep "^#" | sed -e 's/# [0-9]* //' -e 's,"./,",' -e 's/"\(.*\)"/\1/' \ -e 's/ [ 0-9]*$//' | sort -u | sed -e "s/^/$dep: /";; esac done @//E*O*F depends// set `wc -lwc makedepend <<'@//E*O*F makedepend//' # @(#)makedepend 1.2 87/03/19 ################## # Dependencies # ################## # Replace the three sample modules below with the source-file basenames # used in this directory. (The samples below assume your sources are # named date.c, dtime.c, and dtimep.c) MODULES = date dtime dtimep # Stop editing. depend:; for m in $(MODULES); do ( \ i=`basename $$m .c`; \ echo $$i.o: $$i.c >> makedep; \ grep '^#[ ]*include' $$i.c | \ sed -e 's,[^"]*"/\([^"]*\)".*,'$$i'.o: /\1,' \ -e 's,[^"]*"\([^"]*\)".*,'$$i'.o: \1,' \ -e 's,[^<]*<\(.*\)>.*,'$$i'.o: /usr/include/\1,' \ >> makedep \ ); done echo '/^# DO NOT DELETE THIS LINE/+2,$$d' > eddep echo '$$r makedep' >> eddep echo 'w' >> eddep cp Makefile Makefile.old ed - Makefile < eddep rm eddep makedep echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile # DO NOT DELETE THIS LINE # DEPENDENCIES START HERE # DEPENDENCIES MUST END AT END OF FILE # IF YOU PUT STUFF HERE IT WILL GO AWAY @//E*O*F makedepend// set `wc -lwc