Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!radar!cadillac!pebbles!ned From: ned@pebbles.cad.mcc.com (Ned Nowotny) Newsgroups: comp.unix.programmer Subject: Re: mkdep program for SysV (Xenix/Unix) Message-ID: <14370@cadillac.CAD.MCC.COM> Date: 3 Jan 91 20:02:00 GMT References: <1990Dec13.010143@cs.yale.edu> <1990Dec14.023842.21164@robobar.co.uk> <14203@cadillac.CAD.MCC.COM> Sender: news@cadillac.CAD.MCC.COM Reply-To: ned%cad@MCC.COM (Ned Nowotny) Organization: MCC CAD Program, Austin, TX Lines: 69 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.