1# $FreeBSD$ 2 3# Part of a unified Makefile for building kernels. This part includes all 4# the definitions that need to be after all the % directives except %RULES 5# and ones that act like they are part of %RULES. 6# 7# Most make variables should not be defined in this file. Instead, they 8# should be defined in the kern.pre.mk so that port makefiles can 9# override or augment them. 10 11# In case the config had a makeoptions DESTDIR... 12.if defined(DESTDIR) 13MKMODULESENV+= DESTDIR="${DESTDIR}" 14.endif 15MKMODULESENV+= KERNBUILDDIR="${.CURDIR}" 16 17.MAIN: all 18 19.for target in all clean cleandepend cleandir clobber depend install \ 20 obj reinstall tags 21${target}: kernel-${target} 22.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 23${target}: modules-${target} 24modules-${target}: 25 cd $S/modules; ${MKMODULESENV} ${MAKE} \ 26 ${target:S/^reinstall$/install/:S/^clobber$/cleandir/} 27.endif 28.endfor 29 30# Handle out of tree ports 31.if defined(PORTS_MODULES) 32.if defined(SYSDIR) 33PORTSMODULESENV=SYSDIR=${SYSDIR} 34.endif 35.for target in all install clean 36${target}: ports-${target} 37ports-${target}: 38.for __i in ${PORTS_MODULES} 39 cd $${PORTSDIR:-/usr/ports/}${__i}; ${PORTSMODULESENV} ${MAKE} -B ${target} 40.endfor 41.endfor 42.endif 43 44.ORDER: kernel-install modules-install 45 46kernel-all: ${KERNEL_KO} 47 48kernel-cleandir: kernel-clean 49 50kernel-clobber: 51 find . -maxdepth 1 ! -type d ! -name version -delete 52 53kernel-obj: 54 55.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 56modules: modules-all 57 58.if !defined(NO_MODULES_OBJ) 59modules-all modules-depend: modules-obj 60.endif 61.endif 62 63.if !defined(DEBUG) 64FULLKERNEL= ${KERNEL_KO} 65.else 66FULLKERNEL= ${KERNEL_KO}.debug 67${KERNEL_KO}: ${FULLKERNEL} 68 ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO} 69install.debug reinstall.debug: gdbinit 70 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG ${.TARGET:R} 71 72# Install gdbinit files for kernel debugging. 73gdbinit: 74 grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \ 75 sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit 76 cp ${S}/../tools/debugscripts/gdbinit.kernel ${.CURDIR} 77.if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH}) 78 cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH} \ 79 ${.CURDIR}/gdbinit.machine 80.endif 81.endif 82 83${FULLKERNEL}: ${SYSTEM_DEP} vers.o 84 @rm -f ${.TARGET} 85 @echo linking ${.TARGET} 86 ${SYSTEM_LD} 87.if !defined(DEBUG) 88 ${OBJCOPY} --strip-debug ${.TARGET} 89.endif 90 ${SYSTEM_LD_TAIL} 91 92.if !exists(${.OBJDIR}/.depend) 93${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/} 94.endif 95 96LNFILES= ${CFILES:T:S/.c$/.ln/} 97 98.for mfile in ${MFILES} 99# XXX the low quality .m.o rules gnerated by config are normally used 100# instead of the .m.c rules here. 101${mfile:T:S/.m$/.c/}: ${mfile} 102 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c 103${mfile:T:S/.m$/.h/}: ${mfile} 104 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h 105.endfor 106 107kernel-clean: 108 rm -f *.o *.so *.So *.ko *.s eddep errs \ 109 ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks tags \ 110 vers.c vnode_if.c vnode_if.h majors.c \ 111 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 112 ${CLEAN} 113 114lint: ${LNFILES} 115 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \ 116 tee -a linterrs 117 118# This is a hack. BFD "optimizes" away dynamic mode if there are no 119# dynamic references. We could probably do a '-Bforcedynamic' mode like 120# in the a.out ld. For now, this works. 121HACK_EXTRA_FLAGS?= -shared 122hack.So: Makefile 123 touch hack.c 124 ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So 125 rm -f hack.c 126 127# This rule stops ./assym.s in .depend from causing problems. 128./assym.s: assym.s 129 130assym.s: $S/kern/genassym.sh genassym.o 131 NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET} 132 133genassym.o: $S/$M/$M/genassym.c 134 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c 135 136${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 137 138kernel-depend: 139.if defined(EXTRA_KERNELDEP) 140 ${EXTRA_KERNELDEP} 141.endif 142 rm -f .olddep 143 if [ -f .depend ]; then mv .depend .olddep; fi 144 ${MAKE} _kernel-depend 145 146# The argument list can be very long, so use make -V and xargs to 147# pass it to mkdep. 148_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \ 149 ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 150 ${MFILES:T:S/.m$/.h/} 151 if [ -f .olddep ]; then mv .olddep .depend; fi 152 rm -f .newdep 153 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | \ 154 MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS} 155 ${MAKE} -V SFILES | \ 156 MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS} 157 rm -f .depend 158 mv .newdep .depend 159 160kernel-cleandepend: 161 rm -f .depend 162 163links: 164 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 165 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 166 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 167 sort -u | comm -23 - dontlink | \ 168 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 169 sh makelinks; rm -f dontlink 170 171kernel-tags: 172 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 173 sh $S/conf/systags.sh 174 rm -f tags1 175 sed -e 's, ../, ,' tags > tags1 176 177.if ${MACHINE_ARCH} != "ia64" 178.if exists(${DESTDIR}/boot) 179kernel-install-check: 180 @if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \ 181 echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \ 182 exit 1 ; \ 183 fi 184 @if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \ 185 echo "You must activate /boot/device.hints in loader.conf." ; \ 186 exit 1 ; \ 187 fi 188 189kernel-install: kernel-install-check 190.endif 191.endif 192 193kernel-install: 194 @if [ ! -f ${FULLKERNEL} ] ; then \ 195 echo "You must build a kernel first." ; \ 196 exit 1 ; \ 197 fi 198.if exists(${DESTDIR}${KODIR}) 199 -thiskernel=`sysctl -n kern.bootfile` ; \ 200 if [ "`dirname "$$thiskernel"`" != ${DESTDIR}${KODIR} ] ; then \ 201 chflags -R noschg ${DESTDIR}${KODIR} ; \ 202 rm -rf ${DESTDIR}${KODIR} ; \ 203 else \ 204 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 205 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 206 rm -rf ${DESTDIR}${KODIR}.old ; \ 207 fi ; \ 208 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 209 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \ 210 fi 211.endif 212 mkdir -p ${DESTDIR}${KODIR} 213.if defined(DEBUG) && defined(INSTALL_DEBUG) 214 ${INSTALL} -p -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR} 215.else 216 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 217.endif 218 219kernel-reinstall: 220 @-chflags -R noschg ${DESTDIR}${KODIR} 221.if defined(DEBUG) && defined(INSTALL_DEBUG) 222 ${INSTALL} -p -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR} 223.else 224 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 225.endif 226 227config.o env.o hints.o majors.o vers.o vnode_if.o: 228 ${NORMAL_C} 229 230config.ln env.ln hints.ln majors.ln vers.ln vnode_if.ln: 231 ${NORMAL_LINT} 232 233majors.c: $S/conf/majors $S/conf/majors.awk 234 ${AWK} -f $S/conf/majors.awk $S/conf/majors > ${.TARGET} 235 236vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 237 MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT} 238 239vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src 240 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c 241 242vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src 243 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h 244 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p 245 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q 246 247# XXX strictly, everything depends on Makefile because changes to ${PROF} 248# only appear there, but we don't handle that. 249 250.include "kern.mk" 251