Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!lhc!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: C + Make Message-ID: <26549@mimsy.umd.edu> Date: 14 Sep 90 14:54:08 GMT References: <1990Sep11.165709.24875@sj.ate.slb.com> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 69 [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@sj.ate.slb.com> mullen@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 or make -f makefile -f .depend (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@cs.umd.edu Path: uunet!mimsy!chris