Subject: Re: automatically rebuilding headers using make
To: None <netbsd-help@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 12/12/2001 16:48:29
In article <200112121640.JAA28593@biology.nmsu.edu>,
Brook Milligan <brook@biology.nmsu.edu> wrote:
>I am have trouble getting a Makefile based on the definitions in
>bsd.lib.mk to work.  I am trying to use it to make a small library.
>One of the header files (units-defs.h) needs to be rebuilt from a
>template (units-defs.h.in) prior to compiling the library.  My attempt
>to include an explicit rule in the Makefile is illustrated below.
>
>     # Makefile
>
>     SRCDIR=		..
>
>     LIB=		units
>
>     SRCS+=		${SRCDIR}/lib/units.c
>
>     CPPFLAGS+=	-O0 -g -I/usr/pkg/include/pgsql
>     CPICFLAGS=	-fpic -DPIC
>     CPPPICFLAGS=	-DPIC
>
>     MKLINT=		no
>     NOPROFILE=	no profile library
>
>     install:	# needed only for build
>
>     units-defs.h: units-defs.h.in ../bin/units-defs
>	     ../bin/units-defs < ${.TARGET}.in > ${.TARGET}
>     units.o: units-defs.h
>
>     .include <bsd.lib.mk>
>
>Unfortunately, this doesn't work.  Even though units-defs.h is out of
>date with respect to units-defs.h.in, the appropriate rule is never
>used.
>
>An examination of the debugging output from make seems to indicate
>that it considers units-defs.h to be a source file, and therefore is
>never out of date.
>
>What are the proper incantations to make this happen?  Are there any
>examples in the NetBSD source code of rebuilding a header file prior
>to compilation?

Just guessing here, but since units.c has a path it will build

    ${SRCDIR}/lib/units.o

so your dependency to units.o is not taken into account. I would
use:

.PATH.c: ${SRCDIR}/lib

SRCS+=	units.c

christos