Re: Space, speed etc...

Yuri Per (yuri@pts.mipt.ru)
Thu, 14 Mar 1996 11:40:44 +0300 (GMT+0300)


I've written new dependency checker. On my computer it works 3 times faster
then old (the same time as grep '# *include' `find -name '*.[chS]'`).
To test it apply following patch, then use 'make qdep' to make dependencies.

Vadim E. Kogan on Mar 10 wrote:
>
> 2. Speed - `make dep`
>
> a. Tell me please why it's needed?
>
> b. IMHO 'gawk -f ....../depend.awk *[hcS]` can be replaced by:
> grep #include *[hcS] > tmpfile
> small_C(!!!)_prog tmpfile > .depend
> or
> grep #include *[hcS] | small_prog > .depend
>
> If not, tell me (Im lamer ;)
>
> c. make dep takes ~1-2h on 386sx25/4Mb :-((
> It AT LEAST depends unneeded files - like scsi in 1.
>
> d. make dep depends ALL - including linux/include - ANY time it runs :-((
>
> e. IMHO if I install kernel src in /usr/src && I haven't modify it ->
> `make dep` that was made by my friend will b SAME (right?) If yes,
> then maybe in linux-x.x.xx.tar.gz must be all dependencies?
>

diff -u --recursive linux.1.3.73/Makefile linux/Makefile
--- linux.1.3.73/Makefile Tue Mar 12 21:54:50 1996
+++ linux/Makefile Wed Mar 13 22:43:02 1996
@@ -129,6 +129,7 @@
drivers/net/net.a
LIBS =$(TOPDIR)/lib/lib.a
SUBDIRS =kernel drivers mm fs net ipc lib
+DEPDIRS =$(SUBDIRS) ./init $(HPATH)/linux $(HPATH)/net $(HPATH)/asm/

ifeq ($(CONFIG_ISDN),y)
DRIVERS := $(DRIVERS) drivers/isdn/isdn.a
@@ -391,3 +392,6 @@
rm -f $@
$(AWK) -f scripts/depend.awk `find $(HPATH) -name \*.h ! -name modversions.h -print` > .$@
mv .$@ $@
+
+qdep: symlinks
+ $(AWK) -f scripts/qdepend.awk `find $(DEPDIRS) -name '*.[chS]' ! -name modversions.h -depth -print`
diff -u --recursive linux.1.3.73/scripts/qdepend.awk linux/scripts/qdepend.awk
--- linux.1.3.73/scripts/qdepend.awk Wed Mar 13 23:28:58 1996
+++ linux/scripts/qdepend.awk Wed Mar 13 23:00:34 1996
@@ -0,0 +1,119 @@
+# This is an awk script which does dependencies. We do NOT want it to
+# recursivly follow #include directives.
+#
+# The HPATH environment variable should be set to indicate where to look
+# for include files. The -I infront of the path is optional.
+
+#
+# Surely there is a more elegant way to see if a file exists. Anyone know
+# what it is?
+#
+function fileExists(f) {
+ if(dummy=FILEHASH[f]) {
+ if(dummy=="1") {
+ return 1
+ } else {
+ return 0
+ }
+ }
+ dummy = getline dummy < f
+ if(dummy >= 0) {
+ close(f)
+ FILEHASH[f]="1"
+ return 1
+ } else {
+ FILEHASH[f]="0"
+ return 0
+ }
+}
+
+function endfile() {
+ if (hasdep) {
+ printf "\n" > depfile
+ if(cmd) {
+ printf "\t%s\n", cmd > depfile
+ }
+ }
+}
+
+BEGIN{
+ if(!(TOPDIR=ENVIRON["TOPDIR"])) {
+ print "Environment variable TOPDIR is not set"
+ exit 1
+ }
+ sub("[/ ]*$","",TOPDIR)
+ split(ENVIRON["HPATH"],parray," ")
+ for(path in parray) {
+ sub("^-I","",parray[path])
+ sub("[/ ]*$","",parray[path])
+ }
+}
+
+/^#[ \t]*include[ \t]*[<\"].+[>\"]/ {
+ found=0
+ if(LASTFILE!=FILENAME) {
+ endfile()
+ hasdep=0
+ cmd=""
+ LASTFILE=FILENAME
+ depname=FILENAME
+ relpath=FILENAME
+ sub("\\.[cS]$",".o",depname)
+ if (depname==FILENAME) {
+ cmd="@touch $@"
+ }
+ sub("^./","",depname)
+ sub("[^/]*$","",relpath)
+ relpath=relpath"/"
+ sub("//","/",relpath)
+ if(relpath ~ "^\\.") {
+ relpath=""
+ }
+ depfile=relpath".depend"
+ if(relpath ~ "^/") {
+ depfile=".hdepend"
+ }
+ if(LASTDEPFILE && LASTDEPFILE!=depfile) {
+ close(LASTDEPFILE)
+ LASTDEPFILE=""
+ }
+ }
+ fname=$0
+ sub("^#[ \t]*include[ \t]*[<\"]","",fname)
+ sub("[>\"].*","",fname)
+ if($0 ~ "^#[ \t]*include[ \t]*\"") {
+ name=fname
+ if(name !~ "^/" ) {
+ name=relpath""name
+ }
+ if(fileExists(name)) {
+ found=1
+ fname=name
+ }
+ }
+ if(!found) {
+ for(path in parray) {
+ if(fileExists(parray[path]"/"fname)) {
+ fname=parray[path]"/"fname
+ found=1
+ break
+ }
+ }
+ }
+ if(found) {
+ if(!hasdep) {
+ if(!LASTDEPFILE) {
+ printf "Writing %s\n",depfile > "/dev/stderr"
+ LASTDEPFILE=depfile
+ }
+ printf "%s:",depname > depfile
+ hasdep=1
+ }
+ printf "\t\\\n\t%s",fname > depfile
+ }
+}
+
+
+END{
+ endfile()
+}