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