miker@hou4b.UUCP (Mike Roberson) (10/03/84)
[ 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
peter@rlgvax.UUCP (Peter Klosky) (10/03/84)
XXX > These scripts, (odeph and hdepo), create makefile dependency-lists. > Given the input as: grep include *.c | odeph >ch.mk > The script 'odeph' produces a makefile dependence list, (ch.mk): > file1.o : stdio.h filea.h This is a very nice simple minded little program, but what about using include files that in turn include other include files depending on this or that. More on this later ...
djhawley@wateng.UUCP (David J. Hawley) (10/03/84)
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 ################