make depend script for SysV
David Herron -- One of the vertebrae
david at ms.uky.edu
Sat Mar 25 07:50:12 AEST 1989
In article <11300 at s.ms.uky.edu>, david at ms.uky.edu (David Herron -- One of the vertebrae) writes:
> I just came up with a make depend script for use on System V
> and other systems whose cc/cpp gives the following two flags:
Well, a buncha people asked for it so here it is ... The following is the make depend
from my working copy of MMDF. (MMDF users, this will be 'official' shortly :-)).
The uncommented sections are what I am using right now on a ATT6386 with SysVr3.2
to which I'm porting MMDF.
The idea is to run "cc -E -H" and munge the output of that to be "file.o: the-include-file"
and feed that into a duplicate of the original awk script written on cc -M sites.
Output from cc -E -H is:
stdout: the result from cpp on the source file
stderr: any error messages go here as does a list of included files.
the included files are output one per line.
I throw stdout to /dev/null and massage stderr with an awk script which either
munges an included file to "file.o: the-include-file" or prints an error message
on /dev/tty. Hopefully there won't be any error messages.
A kudo. In the middle of the script I "rm -f $$i.deps $$i.out". "$$i.out" isn't
used anylonger but was there during my debugging.
Originally this scripthad the "-M" hard coded, but since the Ultrix people changed it
to be "-Em" I introduced the "THE_M_FLAG" business.
Finally, I don't claim any ownership over this. I've seen these same scripts
floating around in many a Makefile. I *hope* that everybody puts these to use
in their own Makefile's. I'd like to know if someone can clean this up any.
#
# #include dependencies
#
# Two versions are supplied. One for sites with cc -M (4.3BSD)
# and one for those that don't have it. Comment out the one
# you do not want.
# This one is for sites without cc -M
# depend:
# cat </dev/null >x.c
# for i in $(MODULES); do \
# (echo $$i.o: $$i.c >>makedep; \
# grep '^#[ ]*include' x.c $$i.c | sed \
# -e 's,c:[^"]*"\./\([^"]*\)".*,o: \1,' \
# -e 's,c:[^"]*"/\([^"]*\)".*,o: /\1,' \
# -e 's,c:[^"]*"\([^"]*\)".*,o: ../../h/\1,' \
# -e 's,c:[^<]*<\(.*\)>.*,o: /usr/include/\1,' \
# >>makedep); done
# echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
# echo '$$r makedep' >>eddep
# echo 'w' >>eddep
# cp Makefile.real Makefile.bak
# ed - Makefile.real < eddep
# rm eddep makedep x.c
# echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.real
# echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.real
# echo '# see make depend above' >> Makefile.real
THE_M_FLAG= -E -H
# This one is for sites with cc -M
depend:
# ( for i in ${MODULES} ; do \
# ${CC} ${THE_M_FLAG} ${CFLAGS} $$i.c ; done ) | \
# awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
# else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
# else rec = rec " " $$2 } } \
# END { print rec } ' > makedep
( for i in ${MODULES} ; do \
echo $$i >/tmp/curfile; echo "$$i.o: $$i.c" ; \
${CC} ${THE_M_FLAG} ${CFLAGS} $$i.c >/dev/null 2>$$i.deps; \
awk <$$i.deps 'NF > 1 { print >"/dev/tty"; next } \
{print "'`cat /tmp/curfile`'.o: " $$1}' ; \
rm -f $$i.deps $$i.out; done ) | \
awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
else rec = rec " " $$2 } } \
END { print rec } ' > makedep
# awk 'NF == 2 { file = $$2; next } \
# NF == 1 { if (length(rec) == 0) { rec = file ".o: " } \
# if (length(rec $$1) > 70) { \
# print rec $$1; rec = "" } else { \
# rec = rec " " $$1 } \
# }'; done ) >makedep
echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
echo '$$r makedep' >>eddep
echo 'w' >>eddep
cp Makefile.real Makefile.bak
ed - Makefile.real < eddep
rm eddep makedep
echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.real
echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.real
echo '# see make depend above' >> Makefile.real
--
<- David Herron; an MMDF guy <david at ms.uky.edu>
<- ska: David le casse\*' {rutgers,uunet}!ukma!david, david at UKMA.BITNET
<-
<- The problem with mnemonics is they mean different things to different people.
More information about the Comp.unix.wizards
mailing list