1 2# Part of unified Makefile for building kenrels. This includes all 3# the definitions that need to be included after all the % directives, 4# except %RULES and things that act like they are part of %RULES 5# 6# Most make variables should not be defined in this file. Instead, they 7# should be defined in the kern.pre.mk so that port makefiles can 8# override or augment them. 9# 10# $FreeBSD$ 11# 12 13# XXX why are only some phony targets marked phony? 14.PHONY: all modules 15 16clean: kernel-clean 17cleandepend: kernel-cleandepend 18clobber: kernel-clobber 19depend: kernel-depend 20# XXX "make install.debug" seems to install kernels twice. 21install.debug: kernel-install.debug 22install: kernel-install 23reinstall.debug: kernel-reinstall.debug 24reinstall: kernel-reinstall 25tags: kernel-tags 26 27.if !defined(DEBUG) 28FULLKERNEL= ${KERNEL_KO} 29.else 30FULLKERNEL= ${KERNEL_KO}.debug 31${KERNEL_KO}: ${FULLKERNEL} 32 ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO} 33.endif 34 35${FULLKERNEL}: ${SYSTEM_DEP} vers.o 36 @rm -f ${.TARGET} 37 @echo linking ${.TARGET} 38 ${SYSTEM_LD} 39 ${SYSTEM_LD_TAIL} 40 41.if !exists(.depend) 42${SYSTEM_OBJS}: vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/} 43.endif 44 45.for mfile in ${MFILES} 46${mfile:T:S/.m$/.h/}: ${mfile} 47 perl5 $S/kern/makeobjops.pl -h ${mfile} 48.endfor 49 50kernel-clean: 51 rm -f *.o *.so *.So *.ko *.s eddep errs \ 52 ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks \ 53 setdef[01].c setdefs.h tags \ 54 vers.c vnode_if.c vnode_if.h \ 55 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 56 ${CLEAN} 57 58kernel-clobber: 59 find . -type f ! -name version -delete 60 61lint: ${CFILES} 62 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 63 64locore.o: $S/$M/$M/locore.s assym.s 65 ${NORMAL_S} 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# The argument list can be very long, use make -V and xargs to 98# pass it to mkdep. 99_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \ 100 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 101 ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/} 102 if [ -f .olddep ]; then mv .olddep .depend; fi 103 rm -f .newdep 104 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \ 105 env MKDEP_CPP="${CC} -E" CC="${CC}" mkdep -a -f .newdep ${CFLAGS} 106 ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \ 107 env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS} 108 rm -f .depend 109 mv .newdep .depend 110 111kernel-cleandepend: 112 rm -f .depend 113 114links: 115 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 116 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 117 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 118 sort -u | comm -23 - dontlink | \ 119 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 120 sh makelinks; rm -f dontlink 121 122kernel-tags: 123 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 124 sh $S/conf/systags.sh 125 rm -f tags1 126 sed -e 's, ../, ,' tags > tags1 127 128kernel-install kernel-install.debug: 129.if exists(${DESTDIR}/boot) 130 @if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \ 131 echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \ 132 exit 1 ; \ 133 fi 134 @if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \ 135 echo "You must activate /boot/device.hints in loader.conf." ; \ 136 exit 1 ; \ 137 fi 138.endif 139 @if [ ! -f ${KERNEL_KO}${.TARGET:S/kernel-install//} ] ; then \ 140 echo "You must build a kernel first." ; \ 141 exit 1 ; \ 142 fi 143.if exists(${DESTDIR}${KODIR}) 144 -thiskernel=`sysctl -n kern.bootfile` ; \ 145 if [ "$$thiskernel" = ${DESTDIR}${KODIR}.old/${KERNEL_KO} ] ; then \ 146 chflags -R noschg ${DESTDIR}${KODIR} ; \ 147 rm -rf ${DESTDIR}${KODIR} ; \ 148 else \ 149 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 150 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 151 rm -rf ${DESTDIR}${KODIR}.old ; \ 152 fi ; \ 153 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 154 if [ "$$thiskernel" = ${DESTDIR}${KODIR}/${KERNEL_KO} ] ; then \ 155 sysctl -w kern.bootfile=${DESTDIR}${KODIR}.old/${KERNEL_KO} ; \ 156 fi; \ 157 fi 158.endif 159 mkdir -p ${DESTDIR}${KODIR} 160 install -c -m 555 -o root -g wheel \ 161 ${KERNEL_KO}${.TARGET:S/kernel-install//} ${DESTDIR}${KODIR} 162 163kernel-reinstall kernel-reinstall.debug: 164 @-chflags -R noschg ${DESTDIR}${KODIR} 165 install -c -m 555 -o root -g wheel \ 166 ${KERNEL_KO}${.TARGET:S/kernel-reinstall//} ${DESTDIR}${KODIR} 167 168.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 169all: modules 170clean: modules-clean 171cleandepend: modules-cleandepend 172cleandir: modules-cleandir 173clobber: modules-clobber 174depend: modules-depend 175install.debug: modules-install.debug 176install: modules-install 177reinstall.debug: modules-reinstall.debug 178reinstall: modules-reinstall 179tags: modules-tags 180.endif 181 182modules: 183 @mkdir -p ${.OBJDIR}/modules 184 cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \ 185 ${MKMODULESENV} ${MAKE} all 186 187modules-clean: 188 cd $S/modules ; ${MKMODULESENV} ${MAKE} clean 189 190modules-cleandepend: 191 cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandepend 192 193modules-cleandir: 194 cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandir 195 196modules-clobber: modules-clean 197 rm -rf ${MKMODULESENV} 198 199modules-depend: 200 @mkdir -p ${.OBJDIR}/modules 201 cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \ 202 ${MKMODULESENV} ${MAKE} depend 203 204modules-tags: 205 cd $S/modules ; ${MKMODULESENV} ${MAKE} tags 206 207modules-install modules-reinstall: 208 cd $S/modules ; ${MKMODULESENV} ${MAKE} install 209 210modules-install.debug modules-reinstall.debug: 211 cd $S/modules ; ${MKMODULESENV} ${MAKE} install.debug 212 213modules-tags: 214 cd $S/modules ; env ${MKMODULESENV} ${MAKE} tags 215 216config.o: 217 ${NORMAL_C} 218 219env.o: env.c 220 ${NORMAL_C} 221 222hints.o: hints.c 223 ${NORMAL_C} 224 225vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 226 sh $S/conf/newvers.sh ${KERN_IDENT} ${IDENT} 227 228# XXX strictly, everything depends on Makefile because changes to ${PROF} 229# only appear there, but we don't handle that. 230vers.o: 231 ${NORMAL_C} 232 233vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src 234 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c 235 236vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src 237 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h 238 239vnode_if.o: 240 ${NORMAL_C} 241 242.include <bsd.kern.mk> 243