makefile dependency-list creator
Mike Roberson
miker at hou4b.UUCP
Wed Oct 3 10:51:52 AEST 1984
[ peel back foil to expose tater tots ]
If you've ever gone thorugh a marathon typing session of entering a
program from memory, you realize it's tough figuring out the makefile
dependency lists for your program. Well, herein lies an automated
means of laziness.
These scripts, (odeph and hdepo), create makefile dependency-lists.
The input to these scripts is as in the following example.
Given the input as:
grep include *.c | odeph >ch.mk
grep include *.c | hdepo >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 <dotc >ch.mk
hdepo <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
#########-cut-#########-cut-#########-cut-#########-cut-#########-cut-#########
#! /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.
Given the input as:
grep include *.c | odeph >ch.mk
grep include *.c | hdepo >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 <dotc >ch.mk
hdepo <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)
!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
do
mv $i $1
done
rm dep_init
set -
!DONE!dep_mv!BIP!
chmod +x $DEPENDENCY/dep_mv
#
echo $DEPENDENCY/odeph
cat >$DEPENDENCY/odeph <<'!DONE!odeph!BIP!'
#! /bin/sh
tr -s " " " " |
awk -f $DEPENDENCY/dep.pass1.awk |
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 |
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:%s\n", one, ss
}
}
}
END { printf "\n" }
!DONE!dep.pass1.awk!BIP!
#########-cut-#########-cut-#########-cut-#########-cut-#########-cut-#########
--
"may you be the subject of retroactive birth control."
Mike "The Guy in Suspenders" Roberson UUCP: {ihnp4,akgua,houxm}!hou4b!miker
More information about the Comp.lang.c
mailing list