mkdep program for SysV (Xenix/Unix)

Ned Nowotny ned at pebbles.cad.mcc.com
Fri Jan 4 07:02:00 AEST 1991


In article <14203 at cadillac.CAD.MCC.COM> ned%cad at MCC.COM (Ned Nowotny) writes:
=>In article <1990Dec14.023842.21164 at robobar.co.uk> ronald at 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 at mcc.com                   UUCP: ...!cs.utexas.edu!milano!cadillac!ned
-------------------------------------------------------------------------------
"We have ways to make you scream." - Intel advertisement in the June 1989 DDJ.



More information about the Comp.unix.programmer mailing list