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