Re: [kbuild-devel] Re: State of the new config & build system

Martin Mares
2002-01-06T16:16:35Z

Hi Keith,

> That is exactly what kbuild 2.5 does. The slowdown occurs when
> massaging the -MD dependencies from absolute names to relative path
> names. To support separate source and object trees, renaming of trees,
> different names in local and NFS mode etc., the massage code needs a
> list of where all the files are before it can convert the absolute
> dependencies produced by gcc. Reading and indexing that file for every
> compile is _slow_.

I didn't follow the thread from the very beginning nor did I study
your makefiles carefully, because I don't have much time for kernel
hacking these days, but maybe I won't miss the pond :)

Is there any reason for processing all the files for each compile
instead of merging them to a single file once at the start of the make?

I use it in one of my projects, there is the relevant part of the
Makefile:

# Black magic with dependencies. It would be more correct to make "depend.new"
# a prerequisite for "depend", but "depend.new" often has the same timestamp
# as "depend" which would confuse make a lot and either force remaking anyway
# or (as in current versions of GNU make) erroneously skipping the remaking.

-include depend

depend: force
if [ -s depend.new ] ; then build/mergedeps depend depend.new ; >depend.new ; fi

force:

# Implicit rules

obj/%.o: %.c
DEPENDENCIES_OUTPUT="depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<

The DEPENDENCIES_OUTPUT mode is much more convenient than gcc -Mx as it
avoids scattering the relevant information over many files. The mergedeps
script is a simple Perl script which takes care of merging the dependencies
gathered during the previous run of make to the depend file for the next
run. It can do a lot of fixups and translations, here is a trivial
example:

#!/usr/bin/perl

@ARGV == 2 or die "Usage: mergedeps <update>";
foreach $a (@ARGV) {
open F, "$a" or next;
$t = "";
while (<F>) {
$t .= $_;
if (! /\\$/) {
($t =~ /^(.*):/) || die "Parse error at $t";
$rules{$1} = $t;
$t = "";
}
}
close F;
}
open(F,">" . $ARGV[0]) || die "Unable to write output file";
foreach $a (sort keys %rules) {
print F $rules{$a};
}
close F;

Have a nice fortnight
--
Martin `MJ' Mares <mj@ucw.cz> http://atrey.karlin.mff.cuni.cz/~mj/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
Light-year? One-third less calories than a regular year.