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