kern.post.mk revision 95356
192821Simp
292821Simp# Part of unified Makefile for building kenrels.  This includes all
392821Simp# the definitions that need to be included after all the % directives,
492821Simp# except %RULES and things that act like they are part of %RULES
585909Simp#
688893Simp# Most make variables should not be defined in this file.  Instead, they
788893Simp# should be defined in the kern.pre.mk so that port makefiles can
888969Simp# override or augment them.
988893Simp#
1085909Simp# $FreeBSD: head/sys/conf/kern.post.mk 95356 2002-04-24 11:26:19Z ru $
1185909Simp#
1285909Simp
1392821Simp# XXX why are only some phony targets marked phony?
1485909Simp.PHONY:	all modules
1585909Simp
1685909Simpclean:  kernel-clean
1785909Simpcleandepend:  kernel-cleandepend
1885909Simpclobber: kernel-clobber
1992821Simpdepend: kernel-depend
2085909Simpinstall: kernel-install
2185909Simpreinstall: kernel-reinstall
2292821Simptags:  kernel-tags
2385909Simp
2485909Simp.if !defined(DEBUG)
2585909SimpFULLKERNEL=	${KERNEL_KO}
2685909Simp.else
2785909SimpFULLKERNEL=	${KERNEL_KO}.debug
2885909Simp${KERNEL_KO}: ${FULLKERNEL}
2985909Simp	${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO}
3095356Sruinstall.debug reinstall.debug:
3195356Sru	cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG ${.TARGET:R}
3285909Simp.endif
3385909Simp
3485909Simp${FULLKERNEL}: ${SYSTEM_DEP} vers.o
3585909Simp	@rm -f ${.TARGET}
3685909Simp	@echo linking ${.TARGET}
3785909Simp	${SYSTEM_LD}
3885909Simp	${SYSTEM_LD_TAIL}
3985909Simp
4085909Simp.if !exists(.depend)
4185909Simp${SYSTEM_OBJS}: vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
4285909Simp.endif
4385909Simp
4485909Simp.for mfile in ${MFILES}
4585909Simp${mfile:T:S/.m$/.h/}: ${mfile}
4685909Simp	perl5 $S/kern/makeobjops.pl -h ${mfile}
4785909Simp.endfor
4885909Simp
4985909Simpkernel-clean:
5085909Simp	rm -f *.o *.so *.So *.ko *.s eddep errs \
5185909Simp	      ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks \
5285909Simp	      setdef[01].c setdefs.h tags \
5385909Simp	      vers.c vnode_if.c vnode_if.h \
5485909Simp	      ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
5585909Simp	      ${CLEAN}
5685909Simp
5785909Simpkernel-clobber:
5885909Simp	find . -type f ! -name version -delete
5985909Simp
6092491Smarkmlint: ${CFILES}
6192553Sru	${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC}
6292491Smarkm
6385909Simplocore.o: $S/$M/$M/locore.s assym.s
6485909Simp	${NORMAL_S}
6585909Simp
6685909Simp# This is a hack.  BFD "optimizes" away dynamic mode if there are no
6785909Simp# dynamic references.  We could probably do a '-Bforcedynamic' mode like
6885909Simp# in the a.out ld.  For now, this works.
6985909SimpHACK_EXTRA_FLAGS?= -shared
7085909Simphack.So: Makefile
7185909Simp	touch hack.c
7285909Simp	${CC} ${FMT} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
7385909Simp	rm -f hack.c
7485909Simp
7585909Simp# this rule stops ./assym.s in .depend from causing problems
7685909Simp./assym.s: assym.s
7785909Simp
7885909Simpassym.s: $S/kern/genassym.sh genassym.o
7985909Simp	NM=${NM} OBJFORMAT=elf sh $S/kern/genassym.sh genassym.o > ${.TARGET}
8085909Simp
8192821Simp# XXX used to force -elf after CFLAGS to work around breakage of cc -aout
8292821Simp# (genassym.sh makes some assumptions and cc stopped satisfying them).
8385909Simpgenassym.o: $S/$M/$M/genassym.c
8489180Smsmith	${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
8585909Simp
8685909Simp${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
8785909Simp
8885909Simpkernel-depend:
8986048Simp.if defined(EXTRA_KERNELDEP)
9086048Simp	${EXTRA_KERNELDEP}
9186048Simp.endif
9285909Simp	rm -f .olddep
9385909Simp	if [ -f .depend ]; then mv .depend .olddep; fi
9485909Simp	${MAKE} _kernel-depend
9585909Simp
9691104Sjake# The argument list can be very long, use make -V and xargs to
9791104Sjake# pass it to mkdep.
9885909Simp_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \
9985909Simp	    ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
10085909Simp	    ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/}
10185909Simp	if [ -f .olddep ]; then mv .olddep .depend; fi
10285909Simp	rm -f .newdep
10392652Sbde	${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \
10492652Sbde	    env MKDEP_CPP="${CC} -E" CC="${CC}" mkdep -a -f .newdep ${CFLAGS}
10592652Sbde	${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \
10692652Sbde	    env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS}
10785909Simp	rm -f .depend
10885909Simp	mv .newdep .depend
10985909Simp
11085909Simpkernel-cleandepend:
11185909Simp	rm -f .depend
11285909Simp
11385909Simplinks:
11485909Simp	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
11585909Simp	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
11691046Sluigi	${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
11785909Simp	  sort -u | comm -23 - dontlink | \
11885909Simp	  sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
11985909Simp	sh makelinks; rm -f dontlink
12085909Simp
12185909Simpkernel-tags:
12285909Simp	@[ -f .depend ] || { echo "you must make depend first"; exit 1; }
12385909Simp	sh $S/conf/systags.sh
12485909Simp	rm -f tags1
12585909Simp	sed -e 's,      ../,    ,' tags > tags1
12685909Simp
12795356Srukernel-install:
12885909Simp.if exists(${DESTDIR}/boot)
12985909Simp	@if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \
13085909Simp		echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \
13185909Simp		exit 1 ; \
13285909Simp	fi
13385909Simp	@if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \
13485909Simp		echo "You must activate /boot/device.hints in loader.conf." ; \
13585909Simp		exit 1 ; \
13685909Simp	fi
13785909Simp.endif
13895356Sru	@if [ ! -f ${FULLKERNEL} ] ; then \
13985909Simp		echo "You must build a kernel first." ; \
14085909Simp		exit 1 ; \
14185909Simp	fi
14285909Simp.if exists(${DESTDIR}${KODIR})
14385909Simp	-thiskernel=`sysctl -n kern.bootfile` ; \
14485909Simp	if [ "$$thiskernel" = ${DESTDIR}${KODIR}.old/${KERNEL_KO} ] ; then \
14585909Simp		chflags -R noschg ${DESTDIR}${KODIR} ; \
14685909Simp		rm -rf ${DESTDIR}${KODIR} ; \
14785909Simp	else \
14885909Simp		if [ -d ${DESTDIR}${KODIR}.old ] ; then \
14985909Simp			chflags -R noschg ${DESTDIR}${KODIR}.old ; \
15085909Simp			rm -rf ${DESTDIR}${KODIR}.old ; \
15185909Simp		fi ; \
15285909Simp		mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
15385909Simp		if [ "$$thiskernel" = ${DESTDIR}${KODIR}/${KERNEL_KO} ] ; then \
15485909Simp			sysctl -w kern.bootfile=${DESTDIR}${KODIR}.old/${KERNEL_KO} ; \
15585909Simp		fi; \
15685909Simp	fi
15785909Simp.endif
15885909Simp	mkdir -p ${DESTDIR}${KODIR}
15995356Sru.if defined(DEBUG) && defined(INSTALL_DEBUG)
16095356Sru	install -c -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR}
16195356Sru.else
16295356Sru	install -c -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
16395356Sru.endif
16485909Simp
16595356Srukernel-reinstall:
16685909Simp	@-chflags -R noschg ${DESTDIR}${KODIR}
16795356Sru.if defined(DEBUG) && defined(INSTALL_DEBUG)
16895356Sru	install -c -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR}
16995356Sru.else
17095356Sru	install -c -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
17195356Sru.endif
17285909Simp
17385909Simp.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
17485909Simpall:	modules
17585909Simpclean:  modules-clean
17685909Simpcleandepend:  modules-cleandepend
17785909Simpcleandir:  modules-cleandir
17885909Simpclobber:  modules-clobber
17992821Simpdepend: modules-depend
18085909Simpinstall: modules-install
18185909Simpreinstall: modules-reinstall
18292821Simptags:  modules-tags
18385909Simp.endif
18485909Simp
18585909Simpmodules:
18685909Simp	@mkdir -p ${.OBJDIR}/modules
18792650Sbde	cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \
18892650Sbde	    ${MKMODULESENV} ${MAKE} all
18985909Simp
19085909Simpmodules-clean:
19192650Sbde	cd $S/modules ; ${MKMODULESENV} ${MAKE} clean
19285909Simp
19385909Simpmodules-cleandepend:
19492650Sbde	cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandepend
19585909Simp
19692821Simpmodules-cleandir:
19792821Simp	cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandir
19892821Simp
19985909Simpmodules-clobber:	modules-clean
20085909Simp	rm -rf ${MKMODULESENV}
20185909Simp
20292821Simpmodules-depend:
20392821Simp	@mkdir -p ${.OBJDIR}/modules
20492821Simp	cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \
20592821Simp	    ${MKMODULESENV} ${MAKE} depend
20685909Simp
20785909Simpmodules-tags:
20892650Sbde	cd $S/modules ; ${MKMODULESENV} ${MAKE} tags
20985909Simp
21085909Simpmodules-install modules-reinstall:
21192650Sbde	cd $S/modules ; ${MKMODULESENV} ${MAKE} install
21285909Simp
21392821Simpmodules-tags:
21492821Simp	cd $S/modules ; env ${MKMODULESENV} ${MAKE} tags
21592821Simp
21685909Simpconfig.o:
21785909Simp	${NORMAL_C}
21885909Simp
21992821Simpenv.o:	env.c
22092821Simp	${NORMAL_C}
22192821Simp
22292821Simphints.o:	hints.c
22392821Simp	${NORMAL_C}
22492821Simp
22585909Simpvers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
22685909Simp	sh $S/conf/newvers.sh ${KERN_IDENT} ${IDENT}
22785909Simp
22885909Simp# XXX strictly, everything depends on Makefile because changes to ${PROF}
22985909Simp# only appear there, but we don't handle that.
23085909Simpvers.o:
23185909Simp	${NORMAL_C}
23285909Simp
23391512Sobrienvnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
23491512Sobrien	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
23585909Simp
23691512Sobrienvnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
23791512Sobrien	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
23885909Simp
23985909Simpvnode_if.o:
24085909Simp	${NORMAL_C}
24185909Simp
24285909Simp.include <bsd.kern.mk>
243