Subject: Re: Using xargs in kernel depend
To: None <tech-toolchain@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: tech-toolchain
Date: 05/14/2004 21:18:24
On Fri, May 14, 2004 at 12:04:08PM -0700, Jason Thorpe wrote:
> 
> On May 14, 2004, at 10:39 AM, David Laight wrote:
> 
> >>I'd like to see individual .d files generated for the kernel build,
> >>instead, the way we do for userland now.
> >
> >I've got scripts for that here....
> 
> Can we just integrate it into the normal kernel build Makefile the way 
> it's done in userland?

The patch below does it - but uses -MD (to autogenerate the .d files),
it might need other bits of my auto-depend stuff.

	David

Index: Makefile.kern.inc
===================================================================
RCS file: /cvsroot/src/sys/conf/Makefile.kern.inc,v
retrieving revision 1.51
diff -u -p -r1.51 Makefile.kern.inc
--- Makefile.kern.inc	4 Dec 2003 02:33:41 -0000	1.51
+++ Makefile.kern.inc	14 May 2004 19:42:52 -0000
@@ -167,6 +167,9 @@ ${_cfile:T:R}.o: ${_cfile}
 #	${SYSTEM_LD_TAIL}
 SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
 SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ} .gdbinit
+.if !target(.depend) && ${MKAUTODEP} != "no" && !make(depend)
+SYSTEM_DEP+=	.WAIT .depend
+.endif
 SYSTEM_LD_HEAD?=@rm -f $@
 SYSTEM_LD?=	@${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
 		${_MKSHECHO}\
@@ -208,10 +211,10 @@ SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
 assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
 	${_MKTARGET_CREATE}
 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
-	    ${HOST_SH} $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
+	    ${HOST_SH} $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS:N-MD} ${PROF} \
 	    > assym.h.tmp && \
 	mv -f assym.h.tmp assym.h
-${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
+# ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
 .endif
 
 .if !target(vers.o)
@@ -220,7 +223,7 @@ vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
 	${_MKMSG_CREATE} vers.c
 	${HOST_SH} $S/conf/newvers.sh
 	${_MKTARGET_COMPILE}
-	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
+	${CC} ${CFLAGS} ${CPPFLAGS:N-MD} ${PROF} -c vers.c
 .endif
 
 .if !target(config_time.h)
@@ -275,7 +278,7 @@ kernelnames:
 
 .if !target(__CLEANDEPEND)
 __CLEANDEPEND: .USE
-	rm -f .depend
+	rm -f -- .depend *.d
 .endif
 
 # do not !target these, the kern and compat Makefiles augment them
@@ -284,7 +287,33 @@ clean: __CLEANKERNEL
 depend: .depend
 dependall: depend all
 
-.if !target(.depend)
+.if !target(.depend)							# {
+.if ${MKAUTODEP} != "no"						# {
+DEP_FILES?=	${OBJS:N*/*:.o=.d} assym.d
+.if make(depend)							# {
+.for f in ${MD_CFILES} ${MI_CFILES} ${CFILES}
+${f:T:R}.d: ${f}
+	${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} ${CPPFLAGS} ${f}
+.endfor
+.for f in ${MD_SFILES} ${SFILES}
+${f:T:R}.d: ${f}
+	${MKDEP} -f ${.TARGET} -- ${MKDEP_AFLAGS} ${CPPFLAGS} ${f}
+.endfor
+.else									# } {
+CPPFLAGS+=	-MD
+.OPTIONAL: ${DEP_FILES}
+.endif									# }
+
+assym.dep: assym.h config_time.h
+	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
+	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep -- \
+	    ${CFLAGS} ${CPPFLAGS:N-MD}
+assym.d: assym.dep
+	sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
+
+.depend: ${DEP_FILES}
+	${MKDEP} -o -d -- ${.ALLSRC}
+.else	# {MKAUTODEP}							# } {
 SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
 MKDEP_AFLAGS?=	${AFLAGS}
 MKDEP_CFLAGS?=	${CFLAGS}
@@ -298,7 +327,8 @@ MKDEP_CFLAGS?=	${CFLAGS}
 	    ${CFLAGS} ${CPPFLAGS}
 	@sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
 	@rm -f assym.dep
-.endif
+.endif									# }
+.endif									# }
 
 .if !target(lint)
 ALLSFILES?=	${MD_SFILES} ${SFILES}
-- 
David Laight: david@l8s.co.uk