Subject: that "make" lossage with lib{kern,sa,z,compat}
To: None <tech-toolchain@netbsd.org, current-users@netbsd.org>
From: Matthias Drochner <drochner@zel459.zel.kfa-juelich.de>
List: current-users
Date: 04/20/1999 23:03:50
OK, I've tried various ways to work around that -ahem- cleverness of
"make". It was even a bit harder than thought because "make" has a number
of strategies to look up files it believes to need, and these strategies
can't be controlled easily if at all.

The primary problem was that "make" looks up files in ".depend" files
first relative to .CURDIR, the .PATH and obviously to the location of the
file something depends on if that was found by .PATH, before it does the
lookup from .OBJDIR (which is the only right thing in this case because
"mkdep" was ran in .OBJDIR). It's described in PR 7374, and some related
lossage in PR 4021.

I don't dare to change the way "make" works, so the workaround is to
make .OBJDIR == .CURDIR and to to make sure .PATH does not apply.
The appended patch does this - it switches more or less the roles
os the source directory and the target directory to avoid the .OBJDIR!=.CURDIR
situation, and it uses .PATH.suff rules to avoid the lookup of .h files.
It's not completely clean because "make" still looks up "Makefile.inc"
relative to the point where it found "Makefile" (according to "ktrace")
and I didn't find a way to keep it from doing so.

The patch does also cause that only relative paths appear in .depend.
It's only to sys/lib/libkern which is the hardest case because
of the arch dependant subdirs; the changes to the other library builds
follow the same pattern.

This works well for me so far. It would be nice if someone who really
understands the "make" stuff had a look at it, and if the people
which reported problems could try this version.

best regards
Matthias


Index: lib/libkern/Makefile
===================================================================
RCS file: /cvsroot/src/sys/lib/libkern/Makefile,v
retrieving revision 1.51
diff -c -2 -r1.51 Makefile
*** Makefile	1999/04/11 22:08:06	1.51
--- Makefile	1999/04/20 19:58:14
***************
*** 5,14 ****
  
  ARCHSUBDIR= ${MACHINE_ARCH:C/mipse[bl]/mips/}
! M= ${.CURDIR}/arch/${ARCHSUBDIR}
  
  CPPFLAGS=	-I$M ${KERNCPPFLAGS} ${KERNMISCCPPFLAGS}
  
  .if exists ($M/Makefile.inc)
! .PATH:	$M
  .include "$M/Makefile.inc"
  .endif
--- 5,16 ----
  
  ARCHSUBDIR= ${MACHINE_ARCH:C/mipse[bl]/mips/}
! M= ${KERNDIR}/arch/${ARCHSUBDIR}
  
  CPPFLAGS=	-I$M ${KERNCPPFLAGS} ${KERNMISCCPPFLAGS}
  
+ .PATH.c: ${KERNDIR}
  .if exists ($M/Makefile.inc)
! .PATH.c: $M
! .PATH.S: $M
  .include "$M/Makefile.inc"
  .endif
Index: lib/libkern/Makefile.inc
===================================================================
RCS file: /cvsroot/src/sys/lib/libkern/Makefile.inc,v
retrieving revision 1.30
diff -c -2 -r1.30 Makefile.inc
*** Makefile.inc	1998/10/15 18:46:37	1.30
--- Makefile.inc	1999/04/20 19:58:14
***************
*** 20,25 ****
  KERNDST?=	${.OBJDIR}/lib/kern
  KERN_AS?=	library
  
! KERNDIR=	$S/lib/libkern
  .if (${KERN_AS} == "obj")
  KERNLIB=	${KERNDST}/libkern.o
--- 20,26 ----
  KERNDST?=	${.OBJDIR}/lib/kern
  KERN_AS?=	library
+ KERNDOTDIR?= ../../.
  
! KERNDIR=	${S:S@^.@${KERNDOTDIR}@:Q}/lib/libkern
  .if (${KERN_AS} == "obj")
  KERNLIB=	${KERNDST}/libkern.o
***************
*** 31,35 ****
  
  KERNMAKE= \
! 	cd ${KERNDIR} && MAKEOBJDIR=${KERNDST} ${MAKE} \
  	    CC=${CC:Q} CFLAGS=${CFLAGS:Q} \
  	    AS=${AS:Q} AFLAGS=${AFLAGS:Q} \
--- 32,37 ----
  
  KERNMAKE= \
! 	cd ${KERNDST} && ${MAKE} -f ${KERNDIR:Q}/Makefile \
! 	    KERNDIR=${KERNDIR:Q} \
  	    CC=${CC:Q} CFLAGS=${CFLAGS:Q} \
  	    AS=${AS:Q} AFLAGS=${AFLAGS:Q} \
***************
*** 40,44 ****
  	    RANLIB=${RANLIB:Q} SIZE=${SIZE:Q} \
  	    MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH:Q} \
! 	    KERNCPPFLAGS=${CPPFLAGS:S@^-I.@-I../../.@g:Q} \
  	    KERNMISCCPPFLAGS=${KERNMISCCPPFLAGS:Q} \
  	    ${KERNMISCMAKEFLAGS}
--- 42,46 ----
  	    RANLIB=${RANLIB:Q} SIZE=${SIZE:Q} \
  	    MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH:Q} \
! 	    KERNCPPFLAGS=${CPPFLAGS:S@^-I.@-I${KERNDOTDIR}@g:Q} \
  	    KERNMISCCPPFLAGS=${KERNMISCCPPFLAGS:Q} \
  	    ${KERNMISCMAKEFLAGS}
***************
*** 77,78 ****
--- 79,83 ----
  __always_make_kernlib:	.NOTMAIN
  	@(mkdir -p ${KERNDST})
+ 
+ .PHONY: __always_make_kernlib
+ .PHONY: cleankernlib cleandirkernlib dependkernlib