kern.post.mk revision 129752
11022Sache# $FreeBSD: head/sys/conf/kern.post.mk 129752 2004-05-26 16:31:41Z imp $
21533Sjoerg
31022Sache# Part of a unified Makefile for building kernels.  This part includes all
41022Sache# the definitions that need to be after all the % directives except %RULES
51022Sache# and ones that act like they are part of %RULES.
61022Sache#
71022Sache# Most make variables should not be defined in this file.  Instead, they
81022Sache# should be defined in the kern.pre.mk so that port makefiles can
91022Sache# override or augment them.
101022Sache
111022Sache# In case the config had a makeoptions DESTDIR...
121022Sache.if defined(DESTDIR)
131022SacheMKMODULESENV+=	DESTDIR="${DESTDIR}"
141533Sjoerg.endif
151533SjoergMKMODULESENV+=	KERNBUILDDIR="${.CURDIR}"
161533Sjoerg
171533Sjoerg.MAIN: all
181533Sjoerg
191533Sjoerg.for target in all clean cleandepend cleandir clobber depend install \
201533Sjoerg    obj reinstall tags
211533Sjoerg${target}: kernel-${target}
221533Sjoerg.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
231533Sjoerg${target}: modules-${target}
241533Sjoergmodules-${target}:
251022Sache	cd $S/modules; ${MKMODULESENV} ${MAKE} \
261022Sache	    ${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
271022Sache.endif
281022Sache.endfor
291022Sache
301022Sache.ORDER: kernel-install modules-install
311022Sache
321022Sachekernel-all: ${KERNEL_KO}
331022Sache
341022Sachekernel-cleandir: kernel-clean
351022Sache
361022Sachekernel-clobber:
371022Sache	find . -maxdepth 1 ! -type d ! -name version -delete
381022Sache
391022Sachekernel-obj:
401022Sache
411022Sache.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
421022Sachemodules: modules-all
431022Sache
441022Sache.if !defined(NO_MODULES_OBJ)
451022Sachemodules-all modules-depend: modules-obj
461022Sache.endif
471022Sache.endif
481022Sache
491022Sache.if !defined(DEBUG)
501022SacheFULLKERNEL=	${KERNEL_KO}
511022Sache.else
521022SacheFULLKERNEL=	${KERNEL_KO}.debug
531022Sache${KERNEL_KO}: ${FULLKERNEL}
541137Sache	${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO}
551022Sacheinstall.debug reinstall.debug: gdbinit
561022Sache	cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG ${.TARGET:R}
571137Sache
581138Sache# Install gdbinit files for kernel debugging.
591022Sachegdbinit:
601137Sache	grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \
611137Sache	    sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit
621137Sache	cp ${S}/../tools/debugscripts/gdbinit.kernel \
631137Sache	    ${S}/../tools/debugscripts/gdbinit.vinum ${.CURDIR}
641137Sache.if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH})
651137Sache	cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH} \
661137Sache	    ${.CURDIR}/gdbinit.machine
671022Sache.endif
681022Sache.endif
691022Sache
701022Sache${FULLKERNEL}: ${SYSTEM_DEP} vers.o
711022Sache	@rm -f ${.TARGET}
721022Sache	@echo linking ${.TARGET}
731022Sache	${SYSTEM_LD}
741022Sache.if !defined(DEBUG)
751022Sache	${OBJCOPY} --strip-debug ${.TARGET}
761022Sache.endif
771022Sache	${SYSTEM_LD_TAIL}
781022Sache
791137Sache.if !exists(${.OBJDIR}/.depend)
801022Sache${SYSTEM_OBJS}: assym.s pccarddevs.h usbdevs.h miidevs.h vnode_if.h \
811022Sache    ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
821022Sache.endif
831022Sache
841022SacheLNFILES=	${CFILES:T:S/.c$/.ln/}
851022Sache
861022Sache.for mfile in ${MFILES}
871022Sache# XXX the low quality .m.o rules gnerated by config are normally used
881022Sache# instead of the .m.c rules here.
891022Sache${mfile:T:S/.m$/.c/}: ${mfile}
901022Sache	${AWK} -f $S/tools/makeobjops.awk ${mfile} -c
911022Sache${mfile:T:S/.m$/.h/}: ${mfile}
921022Sache	${AWK} -f $S/tools/makeobjops.awk ${mfile} -h
931533Sjoerg.endfor
941022Sache
951533Sjoergkernel-clean:
961533Sjoerg	rm -f *.o *.so *.So *.ko *.s eddep errs \
971533Sjoerg	    ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks tags \
981533Sjoerg	    vers.c vnode_if.c vnode_if.h majors.c \
991533Sjoerg	    ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
1001533Sjoerg	    ${CLEAN}
1011533Sjoerg
1021533Sjoerglint: ${LNFILES}
1031022Sache	${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \
1041022Sache	    tee -a linterrs
1051022Sache
1061022Sache# This is a hack.  BFD "optimizes" away dynamic mode if there are no
1071022Sache# dynamic references.  We could probably do a '-Bforcedynamic' mode like
1081022Sache# in the a.out ld.  For now, this works.
1091022SacheHACK_EXTRA_FLAGS?= -shared
1101022Sachehack.So: Makefile
1111022Sache	touch hack.c
1121022Sache	${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
1131022Sache	rm -f hack.c
1141022Sache
1151022Sache# This rule stops ./assym.s in .depend from causing problems.
1161533Sjoerg./assym.s: assym.s
1171533Sjoerg
1181533Sjoergassym.s: $S/kern/genassym.sh genassym.o
1191533Sjoerg	NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
1201533Sjoerg
1211533Sjoerggenassym.o: $S/$M/$M/genassym.c
1221533Sjoerg	${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
1231533Sjoerg
1241022Sache${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
1251022Sache
1261022Sachekernel-depend:
1271022Sache.if defined(EXTRA_KERNELDEP)
1281022Sache	${EXTRA_KERNELDEP}
1291022Sache.endif
1301022Sache	rm -f .olddep
1311022Sache	if [ -f .depend ]; then mv .depend .olddep; fi
1321022Sache	${MAKE} _kernel-depend
1331022Sache
1341022Sache# XXX this belongs elsewhere (inside GEN_CFILES if possible).
1351022SacheGEN_M_CFILES=	${MFILES:T:S/.m$/.c/}
1361022Sache
1371022Sache# The argument list can be very long, so use make -V and xargs to
1381022Sache# pass it to mkdep.
1391022Sache_kernel-depend: assym.s miidevs.h pccarddevs.h usbdevs.h vnode_if.h \
1401022Sache	    ${BEFORE_DEPEND} ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} \
1411022Sache	    ${GEN_M_CFILES} ${SFILES} ${MFILES:T:S/.m$/.h/}
1421022Sache	if [ -f .olddep ]; then mv .olddep .depend; fi
1431533Sjoerg	rm -f .newdep
1441022Sache	${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES -V GEN_M_CFILES | \
1451022Sache	    MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS}
1461022Sache	${MAKE} -V SFILES | \
1471022Sache	    MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS}
1481022Sache	rm -f .depend
1491022Sache	mv .newdep .depend
1501022Sache
1511022Sachekernel-cleandepend:
1521022Sache	rm -f .depend
1531022Sache
1541022Sachelinks:
1551022Sache	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
1561022Sache	    sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
1571022Sache	${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
1581022Sache	    sort -u | comm -23 - dontlink | \
1591022Sache	    sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
1601022Sache	sh makelinks; rm -f dontlink
1611022Sache
1621022Sachekernel-tags:
1631022Sache	@[ -f .depend ] || { echo "you must make depend first"; exit 1; }
1641022Sache	sh $S/conf/systags.sh
1651022Sache	rm -f tags1
1661022Sache	sed -e 's,      ../,    ,' tags > tags1
1671022Sache
1681533Sjoerg.if ${MACHINE_ARCH} != "ia64"
1691022Sache.if exists(${DESTDIR}/boot)
1701022Sachekernel-install-check:
1711022Sache	@if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \
1721022Sache		echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \
1731022Sache		exit 1 ; \
1741022Sache	fi
1751022Sache	@if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \
1761022Sache		echo "You must activate /boot/device.hints in loader.conf." ; \
1771022Sache		exit 1 ; \
1781022Sache	fi
1791022Sache
1801022Sachekernel-install: kernel-install-check
1811022Sache.endif
1821022Sache.endif
1831022Sache
1841022Sachekernel-install:
1851022Sache	@if [ ! -f ${FULLKERNEL} ] ; then \
1861022Sache		echo "You must build a kernel first." ; \
1871022Sache		exit 1 ; \
1881022Sache	fi
1891022Sache.if exists(${DESTDIR}${KODIR})
1901022Sache	-thiskernel=`sysctl -n kern.bootfile` ; \
1911022Sache	if [ "`dirname "$$thiskernel"`" != ${DESTDIR}${KODIR} ] ; then \
1921022Sache		chflags -R noschg ${DESTDIR}${KODIR} ; \
1931022Sache		rm -rf ${DESTDIR}${KODIR} ; \
1941022Sache	else \
1951022Sache		if [ -d ${DESTDIR}${KODIR}.old ] ; then \
1961022Sache			chflags -R noschg ${DESTDIR}${KODIR}.old ; \
1971022Sache			rm -rf ${DESTDIR}${KODIR}.old ; \
1981022Sache		fi ; \
1991022Sache		mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
2001022Sache		sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
2011022Sache	fi
2021022Sache.endif
2031022Sache	mkdir -p ${DESTDIR}${KODIR}
2041022Sache.if defined(DEBUG) && defined(INSTALL_DEBUG)
2051022Sache	${INSTALL} -p -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR}
2061022Sache.else
2071022Sache	${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
2081022Sache.endif
2091022Sache
2101022Sachekernel-reinstall:
2111022Sache	@-chflags -R noschg ${DESTDIR}${KODIR}
2121022Sache.if defined(DEBUG) && defined(INSTALL_DEBUG)
2131022Sache	${INSTALL} -p -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR}
2141022Sache.else
2151022Sache	${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
2161022Sache.endif
2171022Sache
2181022Sacheconfig.o env.o hints.o majors.o vers.o vnode_if.o:
2191022Sache	${NORMAL_C}
2201022Sache
2211022Sacheconfig.ln env.ln hints.ln majors.ln vers.ln vnode_if.ln:
2221022Sache	${NORMAL_LINT}
2231022Sache
2241022Sachemajors.c: $S/conf/majors $S/conf/majors.awk
2251022Sache	${AWK} -f $S/conf/majors.awk $S/conf/majors > ${.TARGET}
2261022Sache
2271022Sachevers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
2281022Sache	sh $S/conf/newvers.sh ${KERN_IDENT}
2291022Sache
2301022Sachevnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
2311022Sache	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
2321022Sache
2331022Sachevnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
2341022Sache	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
2351022Sache
2361022Sache# XXX strictly, everything depends on Makefile because changes to ${PROF}
2371022Sache# only appear there, but we don't handle that.
2381022Sache
2391022Sache.include "kern.mk"
2401022Sache