C + Make
Chris Torek
chris at mimsy.umd.edu
Sat Sep 15 00:54:08 AEST 1990
[Although this is not strictly a `C topic', a sufficient number of C
systems come with a `make' program that I decided to leave it here.]
In article <1990Sep11.165709.24875 at sj.ate.slb.com>
mullen at sj.ate.slb.com (Lew Mullen) writes:
>There are several "dependency makers" on the net. They are
>based on a feature of make, that a target may have more than one
>dependency line, but only one may have commands with it ...
Actually, strinctly speaking this is not quite right. Unix make (and
any clones that follow it sufficiently well) allow more than one `recipe'
if and only if double-colon rules are used:
foo::
@echo foo
foo::
@echo bar
`make foo' prints `foo\nbar\n'.
>[This] makes it possible to create a self-editing Makefile,
>which updates it's own dependency "section".
I have two recommendations, both of which were learned through experience.
These are:
1. Put the dependency-making in a separate program. The method by which
dependency extraction is done varies from system to system. This way
all the details are in one place (the `mkdep' script or whatever).
2. Do not make `mkdep' edit the makefile. Put the generated dependency
lists in a separate file. 4.3BSD-tahoe and later versions of make
read a file called `.depend', if it exists and no `-f' options are
given. Other makes require a subterfuge: instead of running the
regular `make' program directly, run a front-end that checks for
.depend. If the file exists (and no -f arguments are given), run
make -f Makefile -f .depend <original args>
or
make -f makefile -f .depend <original args>
(use the same rules your `make' uses to locate makefiles to decide
which is the `main' makefile).
In Bourne shell, the latter can be written as
if [ -f .depend ]; then
if [ -f makefile ]; then
f="-f makefile -f .depend"
else
f="-f Makefile -f .depend"
fi
for i do
case "$i" in -f*) f=;; esac
done
else
f=
fi
exec /bin/make $f ${1+"$@"} MACHINE=${MACHINE-`machine`}
(the MACHINE= is for trees that hide machine-specific sources in
machine-specific directories: a useful trick). This is what we
used to use on our non-BSD machines, though now we use pmake.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list