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 53kernel-clean: 54 rm -f *.o *.so *.So *.ko *.s eddep errs \ 55 ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks \ 56 setdef[01].c setdefs.h tags \ 57 vers.c vnode_if.c vnode_if.h \ 58 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 59 ${CLEAN} 60 61kernel-clobber: 62 find . -type f ! -name version -delete 63 64lint: ${CFILES} 65 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 66 67# This is a hack. BFD "optimizes" away dynamic mode if there are no 68# dynamic references. We could probably do a '-Bforcedynamic' mode like 69# in the a.out ld. For now, this works. 70HACK_EXTRA_FLAGS?= -shared 71hack.So: Makefile 72 touch hack.c 73 ${CC} ${FMT} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So 74 rm -f hack.c 75 76# this rule stops ./assym.s in .depend from causing problems 77./assym.s: assym.s 78 79assym.s: $S/kern/genassym.sh genassym.o 80 NM=${NM} OBJFORMAT=elf sh $S/kern/genassym.sh genassym.o > ${.TARGET} 81 82# XXX used to force -elf after CFLAGS to work around breakage of cc -aout 83# (genassym.sh makes some assumptions and cc stopped satisfying them). 84genassym.o: $S/$M/$M/genassym.c 85 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c 86 87${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 88 89kernel-depend: 90.if defined(EXTRA_KERNELDEP) 91 ${EXTRA_KERNELDEP} 92.endif 93 rm -f .olddep 94 if [ -f .depend ]; then mv .depend .olddep; fi 95 ${MAKE} _kernel-depend 96 97# XXX this belongs elsewhere (inside GEN_CFILES if possible). 98GEN_M_CFILES= ${MFILES:T:S/.m$/.c/} 99 100# The argument list can be very long, so use make -V and xargs to 101# pass it to mkdep. 102_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \ 103 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${GEN_M_CFILES} \ 104 ${SFILES} ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/} 105 if [ -f .olddep ]; then mv .olddep .depend; fi 106 rm -f .newdep 107 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES -V GEN_M_CFILES | \ 108 MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS} 109 ${MAKE} -V SFILES -V SYSTEM_SFILES | \ 110 MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS} 111 rm -f .depend 112 mv .newdep .depend 113 114kernel-cleandepend: 115 rm -f .depend 116 117links: 118 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 119 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 120 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 121 sort -u | comm -23 - dontlink | \ 122 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 123 sh makelinks; rm -f dontlink 124 125kernel-tags: 126 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 127 sh $S/conf/systags.sh 128 rm -f tags1 129 sed -e 's, ../, ,' tags > tags1 130 131kernel-install: 132.if exists(${DESTDIR}/boot) 133 @if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \ 134 echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \ 135 exit 1 ; \ 136 fi 137 @if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \ 138 echo "You must activate /boot/device.hints in loader.conf." ; \ 139 exit 1 ; \ 140 fi 141.endif 142 @if [ ! -f ${FULLKERNEL} ] ; then \ 143 echo "You must build a kernel first." ; \ 144 exit 1 ; \ 145 fi 146.if exists(${DESTDIR}${KODIR}) 147 -thiskernel=`sysctl -n kern.bootfile` ; \ 148 if [ "$$thiskernel" = ${DESTDIR}${KODIR}.old/${KERNEL_KO} ] ; then \ 149 chflags -R noschg ${DESTDIR}${KODIR} ; \ 150 rm -rf ${DESTDIR}${KODIR} ; \ 151 else \ 152 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 153 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 154 rm -rf ${DESTDIR}${KODIR}.old ; \ 155 fi ; \ 156 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 157 if [ "$$thiskernel" = ${DESTDIR}${KODIR}/${KERNEL_KO} ] ; then \ 158 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/${KERNEL_KO} ; \ 159 fi; \ 160 fi 161.endif 162 mkdir -p ${DESTDIR}${KODIR} 163.if defined(DEBUG) && defined(INSTALL_DEBUG) 164 ${INSTALL} -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR} 165.else 166 ${INSTALL} -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 167.endif 168 169kernel-reinstall: 170 @-chflags -R noschg ${DESTDIR}${KODIR} 171.if defined(DEBUG) && defined(INSTALL_DEBUG) 172 ${INSTALL} -m 555 -o root -g wheel ${FULLKERNEL} ${DESTDIR}${KODIR} 173.else 174 ${INSTALL} -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 175.endif 176 177.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 178all: modules 179clean: modules-clean 180cleandepend: modules-cleandepend 181cleandir: modules-cleandir 182clobber: modules-clobber 183depend: modules-depend 184install: modules-install 185.ORDER: kernel-install modules-install 186reinstall: modules-reinstall 187tags: modules-tags 188.endif 189 190modules: 191 @mkdir -p ${.OBJDIR}/modules 192 cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \ 193 ${MKMODULESENV} ${MAKE} all 194 195modules-clean: 196 cd $S/modules ; ${MKMODULESENV} ${MAKE} clean 197 198modules-cleandepend: 199 cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandepend 200 201modules-cleandir: 202 cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandir 203 204modules-clobber: modules-clean 205 rm -rf ${MKMODULESENV} 206 207modules-depend: 208 @mkdir -p ${.OBJDIR}/modules 209 cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \ 210 ${MKMODULESENV} ${MAKE} depend 211 212modules-tags: 213 cd $S/modules ; ${MKMODULESENV} ${MAKE} tags 214 215modules-install modules-reinstall: 216 cd $S/modules ; ${MKMODULESENV} ${MAKE} install 217 218config.o: 219 ${NORMAL_C} 220 221env.o: env.c 222 ${NORMAL_C} 223 224hints.o: hints.c 225 ${NORMAL_C} 226 227vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 228 sh $S/conf/newvers.sh ${KERN_IDENT} 229 230# XXX strictly, everything depends on Makefile because changes to ${PROF} 231# only appear there, but we don't handle that. 232vers.o: 233 ${NORMAL_C} 234 235vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src 236 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c 237 238vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src 239 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h 240 241vnode_if.o: 242 ${NORMAL_C} 243 244.include <bsd.kern.mk> 245