makefile dependency-list creator
David J. Hawley
djhawley at wateng.UUCP
Thu Oct 4 06:05:56 AEST 1984
I've modified the dependency-list creator to handle "include <lib1/lib2/..>"
more appropriately. The new version checks <inc> files against a list of
directories, hopefully compatible with the cc(1) list, to determine the
full pathnames, which are included in the output dependency files.
I used the original distribution packaging. I hope it works!
Be nice, this is my first submission.
David Hawley
U of Waterloo, the-town-of-the-same-name, Ontario Canada
XXXXXXXXXXXXXXXXXX cut here XXXXXXXXXXXXXXXXXXXX cut here #####################
#! /bin/sh
export PATH || (echo "You didn't use (Bourne) sh, you bip!" ; kill $$)
#
DEPENDENCY=${1-HOME/bin}
echo "all files will be put in the directory \"$DEPENDENCY\", ok? (<rub> = no)\c"
read foople
#
echo $DEPENDENCY/READ.ME
cat >$DEPENDENCY/READ.ME <<'!DONE!READ.ME!BIP!'
1) Run dep_init to install the files in a certain directory, as:
dep_init $HOME/bin
which expands "$HOME/bin" and substitutes it for '$DEPENDENCY' in each file;
or:
dep_init '$HOME/bin'
which substitutes '$HOME/bin' for '$DEPENDENCY' in each file.
2) Then run dep_mv as:
dep_mv $HOME/bin
but not as:
dep_mv '$HOME/bin'
These scripts take input as in the following example.
( In the examples that follow, <lib> is an optional argument corresponding
to the "inclib" part of the cc(1) "-Iinclib" option.
The name of the standard library "/usr/include" is hardcoded into the file
"dep.pass2.sh"
)
Given the input as:
grep include *.c | odeph <lib> >ch.mk
grep include *.c | hdepo <lib> >hc.mk
or a file, (dotc), containing:
file1.c:#include <stdio.h>
file1.c:#include <filea.h>
file2.c:#include <stdio.h>
file2.c:#include "fileb.h"
file3.c:#include <stdio.h>
file3.c:#include <filea.h>
file4.c:#include <stdio.h>
file4.c:#include <filea.h>
file4.c:#include "fileb.h"
file5.c:#include <stdio.h>
file5.c:#include "fileb.h"
redirected into the scripts, as:
odeph <lib> <dotc >ch.mk
hdepo <lib> <dotc >hc.mk
The script 'odeph' produces a makefile dependence list, (ch.mk),
of the form:
file1.o : stdio.h filea.h
file2.o : stdio.h fileb.h
file3.o : stdio.h filea.h
file4.o : stdio.h filea.h fileb.h
file5.o : stdio.h fileb.h
The script 'hdepo' produces a makefile dependence list, (hc.mk),
of the form:
file1.o file3.o file4.o : filea.h
file2.o file4.o file5.o : fileb.h
file1.o file2.o file3.o file4.o file5.o : stdio.h
--
Mike "The Guy in Suspenders" Roberson UUCP: {ihnp4,akgua,houxm}!hou4b!miker
AT&T-Island, Holmdel, NJ Ph: (201)834-3067 (8:15-5:15 Eastern)
Modified by
David J Hawley UUCP: utzoo!watmath!wateng!djhawley
UofWaterloo, Waterloo, Ont, Canada
!DONE!READ.ME!BIP!
#
echo $DEPENDENCY/dep_init
cat >$DEPENDENCY/dep_init <<'!DONE!dep_init!BIP!'
#! /bin/sh
if [ $# != 1 ]; then
echo "usage: $0 path_name | 'path_name'"
exit
fi
#
echo "g|\$DEPENDENCY|s||$1|g" >dep.ed.script
echo "w" >>dep.ed.script
echo "q" >>dep.ed.script
for i in odeph hdepo dep.pass1
do
ed $i <dep.ed.script
done
rm dep.ed.script
!DONE!dep_init!BIP!
chmod +x $DEPENDENCY/dep_init
#
echo $DEPENDENCY/dep_mv
cat >$DEPENDENCY/dep_mv <<'!DONE!dep_mv!BIP!'
#! /bin/sh
if [ $# != 1 ]; then
echo "usage: $0 path_name"
exit
fi
set -x
for i in READ.ME dep_mv odeph hdepo dep.pass1 odeph.awk hdepo.awk dep.pass1.awk dep.pass2.sh
do
mv $i $1
done
rm dep_init
set -
!DONE!dep_mv!BIP!
chmod +x $DEPENDENCY/dep_mv
#
echo $DEPENDENCY/dep.pass2.sh
cat >$DEPENDENCY/dep.pass2.sh <<'!DONE!dep.pass2.sh!BIP!'
#! /bin/sh
# first parameter is the "lib" part of the -Ilib option used in "cc", or null
# if not specified
Ilib=$1
# The next line specifies the standard library(s) to search
stdlib="/usr/include"
#
while read dotO type dotH
do
case $type in
\?)
ndotH="\?/$dotH"
for i in $Ilib $stdlib
do if test -f $i/$dotH
then ndotH=$i/$dotH
break
fi
done
echo "$dotO:$ndotH"
;;
"") echo $dotO $type $dotH
;;
*)
echo "$dotO:$dotH"
;;
esac
done
!DONE!dep.pass2.sh!BIP!
chmod u+x $DEPENDENCY/dep.pass2.sh
#
echo $DEPENDENCY/odeph
cat >$DEPENDENCY/odeph <<'!DONE!odeph!BIP!'
#! /bin/sh
tr -s " " " " |
awk -f $DEPENDENCY/dep.pass1.awk |
sh $DEPENDENCY/dep.pass2.sh $1 |
sort |
awk -f $DEPENDENCY/odeph.awk
!DONE!odeph!BIP!
chmod u+x $DEPENDENCY/odeph
#
echo $DEPENDENCY/hdepo
cat >$DEPENDENCY/hdepo <<'!DONE!hdepo!BIP!'
#! /bin/sh
tr -s " " " " |
awk -f $DEPENDENCY/dep.pass1.awk |
sh $DEPENDENCY/dep.pass2.sh $1 |
sort -t: +1 |
awk -f $DEPENDENCY/hdepo.awk
!DONE!hdepo!BIP!
chmod u+x $DEPENDENCY/hdepo
#
echo $DEPENDENCY/dep.pass1
cat >$DEPENDENCY/dep.pass1 <<'!DONE!dep.pass1!BIP!'
#! /bin/sh
awk -f $DEPENDENCY/dep.pass1.awk
!DONE!dep.pass1!BIP!
chmod u+x $DEPENDENCY/dep.pass1
#
echo $DEPENDENCY/odeph.awk
cat >$DEPENDENCY/odeph.awk <<'!DONE!odeph.awk!BIP!'
BEGIN { FS = ":" }
$1 != prev { printf "\n\n%s:", $1 ; prev = $1 }
$1 == prev { printf " %s", $2 }
END { printf "\n" }
!DONE!odeph.awk!BIP!
#
echo $DEPENDENCY/hdepo.awk
cat >$DEPENDENCY/hdepo.awk <<'!DONE!hdepo.awk!BIP!'
BEGIN { FS = ":" }
$2 == "" { next }
$2 != prev {
if (prev)
printf ": %s\n\n", prev
prev = $2
}
$2 == prev { printf "%s ", $1 }
END { printf ": %s\n", prev }
!DONE!hdepo.awk!BIP!
#
echo $DEPENDENCY/dep.pass1
cat >$DEPENDENCY/dep.pass1.awk <<'!DONE!dep.pass1.awk!BIP!'
BEGIN { FS = ":" }
$2 ~ /^#/ {
i = index($2, "<") + 1
if (i - 1) {
e = index($2, ">")
ss = substr($2, i, e - i)
e = index($1, ".c") - 1
one = substr($1, 1, e)
printf "%s.o ? %s\n", one, ss
} else {
i = index($2, "\"") + 1
if (i - 1) {
ss = substr($2, i);
e = index(ss, "\"")
ss = substr(ss, 1, e - 1)
e = index($1, ".c") - 1
one = substr($1, 1, e)
printf "%s.o X %s\n", one, ss
}
}
}
END { printf "\n" }
!DONE!dep.pass1.awk!BIP!
################ cut here ############################ cut here ################
More information about the Comp.lang.c
mailing list