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