Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Dec 1994 14:45:50 +0100
From:      Wolfram Schneider <wosch@cs.tu-berlin.de>
To:        hackers@freebsd.org
Subject:   optimized mkdep
Message-ID:  <199412311345.OAA07627@beryll.cs.tu-berlin.de>

next in thread | raw e-mail | index | archive | help

``make depend'' use to much processes. The following patches save 12
processes for every ``make depend''. ``Make world'' call ``make
depend'' ~500x => 6000 processes!!!


Tested in /usr/src/usr.sbin/sa


Current, without optimization: 20 processes

$ make depend
rm -f .depend
files="";  if [ "$files" != "" ]; then  mkdep -a    $files;  fi
files="main.c pdb.c usrdb.c";  if [ "$files" != "" ]; then  mkdep -a   $files;  fi
files="  ";  if [ "$files" != "  " ]; then  mkdep -a    $files;  fi
make       -       w        ttyp5      0.53 secs Sat Dec 23 19:57
sh         -       w        ttyp5      0.03 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.03 secs Sat Dec 23 19:57
sh         -       w        ttyp5      0.05 secs Sat Dec 23 19:57
sh         -       w        ttyp5      0.12 secs Sat Dec 23 19:57
rm         -       w        ttyp5      0.02 secs Sat Dec 23 19:57
cat        -       w        ttyp5      0.03 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.02 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.02 secs Sat Dec 23 19:57
sed        -       w        ttyp5      0.17 secs Sat Dec 23 19:57
cc         -       w        ttyp5      0.17 secs Sat Dec 23 19:57
cpp        -       w        ttyp5      0.66 secs Sat Dec 23 19:57
cpp        -       w        ttyp5      0.75 secs Sat Dec 23 19:57
cpp        -       w        ttyp5      0.92 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.02 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.05 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.03 secs Sat Dec 23 19:57
sh         -       w        ttyp5      0.05 secs Sat Dec 23 19:57
[          -       w        ttyp5      0.02 secs Sat Dec 23 19:57
rm         -       w        ttyp5      0.06 secs Sat Dec 23 19:57


bsd.dep.mk.opt + mkdep: 15 processes

$ make depend
rm -f .depend;  files="";  case "$files" in "");; *)  mkdep -a    $files;; esac;  files="main.c pdb.c usrdb.c";  case "$files" in "");; *)  mkdep -a   $files; esac;  files="  ";  case "$files" in "  ");; *)  mkdep -a    $files; esac
make       -       w        ttyp5      0.52 secs Sat Dec 23 20:00
sh         -       w        ttyp5      0.08 secs Sat Dec 23 20:00
sh         -       w        ttyp5      0.12 secs Sat Dec 23 20:00
rm         -       w        ttyp5      0.03 secs Sat Dec 23 20:00
cat        -       w        ttyp5      0.02 secs Sat Dec 23 20:00
[          -       w        ttyp5      0.02 secs Sat Dec 23 20:00
[          -       w        ttyp5      0.03 secs Sat Dec 23 20:00
sed        -       w        ttyp5      0.16 secs Sat Dec 23 20:00
cc         -       w        ttyp5      0.17 secs Sat Dec 23 20:00
cpp        -       w        ttyp5      0.69 secs Sat Dec 23 20:00
cpp        -       w        ttyp5      0.75 secs Sat Dec 23 20:00
cpp        -       w        ttyp5      0.89 secs Sat Dec 23 20:00
[          -       w        ttyp5      0.02 secs Sat Dec 23 20:00
[          -       w        ttyp5      0.06 secs Sat Dec 23 20:00
rm         -       w        ttyp5      0.02 secs Sat Dec 23 20:00


bsd.dep.mk.opt + mkdep.perl: 8 processes

$ make depend
rm -f .depend;  files="";  case "$files" in "");; *)  mkdep.perl -a    $files;; esac;  files="main.c pdb.c usrdb.c";  case "$files" in "");; *)  mkdep.perl -a   $files; esac;  files="  ";  case "$files" in "  ");; *)  mkdep.perl -a    $files; esac
make       -       w        ttyp5      0.53 secs Sat Dec 23 20:02
sh         -       w        ttyp5      0.03 secs Sat Dec 23 20:02
perl       -       w        ttyp5      0.19 secs Sat Dec 23 20:02
cc         -       w        ttyp5      0.17 secs Sat Dec 23 20:02
cpp        -       w        ttyp5      0.66 secs Sat Dec 23 20:02
cpp        -       w        ttyp5      0.75 secs Sat Dec 23 20:02
cpp        -       w        ttyp5      0.92 secs Sat Dec 23 20:02
rm         -       w        ttyp5      0.03 secs Sat Dec 23 20:02


Gruß Wolfram

#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 12/31/1994 13:41 UTC by wosch@beryll
# Source directory /tmp_amd/fiesta/export/all3/w/wosch/tmp/send
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   3217 -rwxr-xr-x mkdep.perl
#   1061 -rwxr-xr-x bsd.dep.mk.opt
#
# ============= mkdep.perl ==============
if test -f 'mkdep.perl' -a X"$1" != X"-c"; then
	echo 'x - skipping mkdep.perl (File already exists)'
else
echo 'x - extracting mkdep.perl (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mkdep.perl' &&
#!/usr/bin/perl
#
# Copyright (c) 1994 Wolfram Schneider. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by Wolfram Schneider
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# mkdep - construct Makefile dependency list
#               Email: Wolfram Schneider <wosch@cs.tu-berlin.de>
X
$depend=".depend";		# default dependency file is .depend
$append=0;			# 
$pflag=0;			# 
X
sub usage {
X    warn <<EOF;
usage: mkdep [-p] [-f depend_file] [cc_flags] file ...
EOF
X    exit 1;
}
X
@argv='';
while ($_ = $ARGV[0], /^-/) {
X    shift @ARGV;
X    last if /^--$/;
X
X    # -a appends to the depend file
X    if    (/^-a$/) { $append = 1 } 
X    # -f allows you to select a makefile name
X    elsif (/^-f$/) { $depend=$_; shift @ARGV }
X    # the -p flag produces "program: program.c" style dependencies
X    # so .o's don't get produced
X    elsif (/^-p$/) { $pflag = 1 }
X    else { push(@argv, $_); last; }
}
&usage if $#ARGV < 0;		# 
push(@argv, @ARGV);
X
X
# For C sources, mkdep must use exactly the same cpp and predefined flags
# as the compiler would.  This is easily arranged by letting the compiler
# pick the cpp.  mkdep must be told the cpp to use for exceptional cases.
if ($ENV{'MKDEP_CPP'}) {
X    $cpp = $ENV{'MKDEP_CPP'};
} else {
X    $cpp="cc -E";
}
X
X
# Quote metacharacters for sh -c (exec, open etc.)
$a = join($", @argv);
$a =~  s|([^\w /.-])|\\$1|g;	
X
open(CPP, "$cpp -M $a |");
X
@array='';
if ($pflag) {
X    while(<CPP>) {
X	s|\.o:|:|; 
X	s| \./| |g;
X	push(@array, $_);
X    }
} else {
X    while(<CPP>) {
X	s| \./| |g;
X	push(@array, $_);
X    }
}
close CPP;
X
if(($? >> 8) != 0) {
X    warn "mkdep: compile failed.\n";
X    exit 1;
}
X
if ($append) {
X    open(D, ">> $depend");
} else {
X    open(D, "> $depend");
}
X
print D @array;
close D;
X
Xexit 0;
SHAR_EOF
chmod 0755 mkdep.perl ||
echo 'restore of mkdep.perl failed'
Wc_c="`wc -c < 'mkdep.perl'`"
test 3217 -eq "$Wc_c" ||
	echo 'mkdep.perl: original size 3217, current size' "$Wc_c"
fi
# ============= bsd.dep.mk.opt ==============
if test -f 'bsd.dep.mk.opt' -a X"$1" != X"-c"; then
	echo 'x - skipping bsd.dep.mk.opt (File already exists)'
else
echo 'x - extracting bsd.dep.mk.opt (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bsd.dep.mk.opt' &&
#	$Id: bsd.dep.mk,v 1.1 1994/08/04 21:10:07 wollman Exp $
X
# some of the rules involve .h sources, so remove them from mkdep line
MD=mkdep.perl
.if !target(depend)
depend: beforedepend .depend afterdepend
.if defined(SRCS)
.depend: ${SRCS}
X	rm -f .depend; \
X	files="${.ALLSRC:M*.[sS]}"; \
X	case "$$files" in "");; *) \
X	  ${MD} -a ${MKDEP} ${CFLAGS:M-[ID]*} ${AINC} $$files;; esac; \
X	files="${.ALLSRC:M*.c}"; \
X	case "$$files" in "");; *) \
X	  ${MD} -a ${MKDEP} ${CFLAGS:M-[ID]*} $$files; esac; \
X	files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
X	case "$$files" in "  ");; *) \
X	  ${MD} -a ${MKDEP} ${CXXFLAGS:M-nostd*} ${CXXFLAGS:M-[ID]*} $$files;\
X	esac
.else
.depend:
.endif
.if !target(beforedepend)
beforedepend:
.endif
.if !target(afterdepend)
afterdepend:
.endif
.endif
X
.if !target(tags)
.if defined(SRCS)
tags: ${SRCS}
X	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
X	    sed "s;\${.CURDIR}/;;" > tags
.else
tags:
.endif
.endif
X
.if defined(SRCS)
clean:
cleandir: cleandepend
cleandepend:
X	rm -f .depend ${.CURDIR}/tags
.endif
SHAR_EOF
chmod 0755 bsd.dep.mk.opt ||
echo 'restore of bsd.dep.mk.opt failed'
Wc_c="`wc -c < 'bsd.dep.mk.opt'`"
test 1061 -eq "$Wc_c" ||
	echo 'bsd.dep.mk.opt: original size 1061, current size' "$Wc_c"
fi
exit 0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199412311345.OAA07627>