ronald@robobar.co.uk (Ronald S H Khoo) (12/14/90)
[ OK guys, where *do* you ask about things like makefile makers ? comp.unix.programmer ? alt.sport.toe.wrestling ? I'll try the former :-) ] [ Now I'm going to *expect* a followup telling me what the current crop of mkdeps do that cc -M doesn't. Or do people distribute makedepend just because some people don't have cc -M ? Answers on a postcard to Craig Shergold, please, or follow up :-) ] fields-doug@cs.yale.edu (Doug Fields) writes: > Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which > I assume adds to the end a zillion dependencies [ to the end of Makefiles ] > Anyway, I could really use [ mkdep ], or one which does > something similar, for those Makefiles and as a general utility. One fast and accurate way to make dependencies for makefiles is to use gcc -M. (Doug's asking about Xenix/Sys V, so he'd need gcc. BSD cc has -M doesn't it?) For example, you could add something like depend: sed "/^# DELETE ME/q" Makefile > Makefile.new gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new mv Makefile.new Makefile # DELETE ME to the end of your makefile. Then "make depend" would do just that. This works especially well when your dependencies change a lot depending on what -I and -D flags you change in CFLAGS, just run make depend again. Just make sure you haven't got a file called "depend" in the current directory :-) -- ronald@robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)
dougm@ico.isc.com (Doug McCallum) (12/15/90)
In article <1990Dec14.023842.21164@robobar.co.uk> ronald@robobar.co.uk (Ronald S H Khoo) writes: ... >One fast and accurate way to make dependencies for makefiles is to use gcc -M. >(Doug's asking about Xenix/Sys V, so he'd need gcc. BSD cc has -M doesn't it?) ... The System V.3 cc has an option similar to the -M option. cc -P -H $CFLAGS file.c 2>&1 | sed "s;^;file.c:;" is almost what -M does.
allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (12/16/90)
As quoted from <1990Dec14.023842.21164@robobar.co.uk> by ronald@robobar.co.uk (Ronald S H Khoo): +--------------- | fields-doug@cs.yale.edu (Doug Fields) writes: | | > Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which | > I assume adds to the end a zillion dependencies [ to the end of Makefiles ] | > Anyway, I could really use [ mkdep ], or one which does | > something similar, for those Makefiles and as a general utility. | | One fast and accurate way to make dependencies for makefiles is to use gcc -M. | (Doug's asking about Xenix/Sys V, so he'd need gcc. BSD cc has -M doesn't it?) +--------------- If I remember correctly, BSD cc has -M but it has to be massaged to produce dependencies. gcc has -M and -E -M (I think that's correct); the latter produces dependencies in Makefile format. I have a Perl script that computes dependencies, which I use in preference to gcc. Part of the reason is that it doesn't feel as weird as running a C compiler on random non-C source [ ;-) ] and part of the reason is some misgivings about letting gcc anywhere near my Unify ACCELL 4GL scripts, copyleft notwithstanding. Neither is a hard-and-fast reason, and little would change if I made my mkdep script call gcc -E -M, except that my mkdep does a little cleanup on the resulting filenames. In particular, I seem to remember it keeping an eye on Makefile macro definitions and substituting them in place of leading pathname components. (It's been a while since I bothered to look at the output; once you trust a tool, you don't worry it to death.) ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY
Sm@cerberus.bhpese.oz.au (Scott Merrilees) (12/17/90)
fields-doug@cs.yale.edu (Doug Fields) writes: > Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which > I assume adds to the end a zillion dependencies [ to the end of Makefiles ] > Anyway, I could really use [ mkdep ], or one which does > something similar, for those Makefiles and as a general utility. I got a makedepend program from the X11 tapes, which seems to work well. I had a mkdep program, but it worked less well. The makedepend program is quite modest in size, and is a shell/awk/sed script. Sm -- Scott Merrilees, BHP Information Technology, Newcastle, Australia Internet: Sm@bhpese.oz.au Phone: +61 49 402132
ronald@robobar.co.uk (Ronald S H Khoo) (12/18/90)
allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes: > If I remember correctly, BSD cc has -M but it has to be massaged to produce > dependencies. gcc has -M and -E -M (I think that's correct); the latter > produces dependencies in Makefile format. Maybe gcc's changed since you last looked at its options. I quote the relevant portion of "man gcc" (which says 1.36 on it, but is the one distributed with gcc 1.37.1, ie the current gcc) > once you trust a tool, you don't worry it to death.) An excellent point. Begin excerpt from /usr/man/cat.G/gcc.G:----------------------------------- -M Tell the preprocessor to output a rule suitable for make(1) describing the dependencies of each source file. For each source file, the preprocessor outputs one make-rule whose target is the object file name for that source file and whose dependencies are all the files #included in it. This rule may be a single line or may be continued with \-newline if it is long. -M implies -E. -MM Like -M but the output mentions only the user-header files included with #include "file". System header files included with #include <file> are omitted. -MM implies -E. End excerpt from /usr/man/cat.G/gcc.G:----------------------------------- -- ronald@robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)
ned@pebbles.cad.mcc.com (Ned Nowotny) (12/22/90)
In article <1990Dec14.023842.21164@robobar.co.uk> ronald@robobar.co.uk (Ronald S H Khoo) writes: >One fast and accurate way to make dependencies for makefiles is to use gcc -M. >(Doug's asking about Xenix/Sys V, so he'd need gcc. BSD cc has -M doesn't it?) > >For example, you could add something like > > depend: > sed "/^# DELETE ME/q" Makefile > Makefile.new > gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new > mv Makefile.new Makefile > > # DELETE ME > Or, Makefile.depend: $(SRCS) $(HDRS) for src in $(SRCS) ; \ do \ $(CC) $(CFLAGS) -E $${src} | \ grep '^# *1 ' | \ sed 's@[^"]*"\([^"]*\)".*@\1 \\@' | \ grep -v "$${src}" | \ sort -u >> $@ ; \ echo "$${src}" >> $@ ; \ done if your compiler does not have -M but does have -E. Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX 78720 Ph: (512) 338-3715 ARPA: ned@mcc.com UUCP: ...!cs.utexas.edu!milano!cadillac!ned ------------------------------------------------------------------------------- "We have ways to make you scream." - Intel advertisement in the June 1989 DDJ.
ned@pebbles.cad.mcc.com (Ned Nowotny) (01/04/91)
In article <14203@cadillac.CAD.MCC.COM> ned%cad@MCC.COM (Ned Nowotny) writes: =>In article <1990Dec14.023842.21164@robobar.co.uk> ronald@robobar.co.uk (Ronald S H Khoo) writes: =>>One fast and accurate way to make dependencies for makefiles is to use =>>gcc -M. (Doug's asking about Xenix/Sys V, so he'd need gcc. BSD cc has =>>-M doesn't it?) =>> =>>For example, you could add something like =>> =>> depend: =>> sed "/^# DELETE ME/q" Makefile > Makefile.new =>> gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new =>> mv Makefile.new Makefile =>> >> # DELETE ME =>> => =>Or, => =>Makefile.depend: $(SRCS) $(HDRS) => for src in $(SRCS) ; \ => do \ => $(CC) $(CFLAGS) -E $${src} | \ => grep '^# *1 ' | \ => sed 's@[^"]*"\([^"]*\)".*@\1 \\@' | \ => grep -v "$${src}" | \ => sort -u >> $@ ; \ => echo "$${src}" >> $@ ; \ => done => => =>if your compiler does not have -M but does have -E. => To which Gilles Courcoux at the Unisys Network Computing Group responded via email: =>You're overloading your system with processes and your file system =>with numerous open, lseek and close. Take a closer look at sed(1) =>and sh(1). Worse, you don't give the left handside member of the =>dependency (ending here in .o). Try: => =>Makefile.depend: $(SRCS) $(HDRS) => for src in $(SRCS) ; \ => do \ => obj=`expr $$src : '\([^.]*\)\..*' \| $$src`.o export obj; \ => $(CC) $(CFLAGS) -E $${src} \ => | sed -e '/^# *1 /!d' -e "s@[^\"]*\"\([^\"]*\)\".*@$${obj}: \1@" \ => | sort -u; \ => done > $@ => He is quite right that I failed to provide the left-hand side of the dependency. I cut the text from a make dependency which included a case statement so that dependencies could be generated for both C and C++. The following line is the missing part which should immediately follow the "do" in my example: echo $${src} | sed -e 's@\([^.]*\)\..*@\1.o: \\@' >> $@ ; \ To give credit where credit is due, my example is based on a pipeline written by Steven P. Reiss at Brown University. The pipeline is used in the Field Environment. In any case, Gilles Courcoux has provided a better pipeline for generating dependencies from the more common -E C compiler flag. Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX 78720 Ph: (512) 338-3715 ARPA: ned@mcc.com UUCP: ...!cs.utexas.edu!milano!cadillac!ned ------------------------------------------------------------------------------- "We have ways to make you scream." - Intel advertisement in the June 1989 DDJ.