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# Handle out of tree ports 31.if !defined(NO_MODULES) && defined(PORTS_MODULES) 32SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;} 33PORTSMODULESENV=SYSDIR=${SYSDIR} 34.for __target in all install reinstall clean 35${__target}: ports-${__target} 36ports-${__target}: 37.for __i in ${PORTS_MODULES} 38 cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B ${__target:C/install/deinstall reinstall/:C/reinstall/deinstall reinstall/} 39.endfor 40.endfor 41.endif 42 43.ORDER: kernel-install modules-install 44 45kernel-all: ${KERNEL_KO} 46 47kernel-cleandir: kernel-clean 48 49kernel-clobber: 50 find . -maxdepth 1 ! -type d ! -name version -delete 51 52kernel-obj: 53 54.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 55modules: modules-all 56 57.if !defined(NO_MODULES_OBJ) 58modules-all modules-depend: modules-obj 59.endif 60.endif 61 62.if !defined(DEBUG) 63FULLKERNEL= ${KERNEL_KO} 64.else 65FULLKERNEL= ${KERNEL_KO}.debug 66${KERNEL_KO}: ${FULLKERNEL} ${KERNEL_KO}.symbols 67 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${KERNEL_KO}.symbols\ 68 ${FULLKERNEL} ${.TARGET} 69${KERNEL_KO}.symbols: ${FULLKERNEL} 70 ${OBJCOPY} --only-keep-debug ${FULLKERNEL} ${.TARGET} 71install.debug reinstall.debug: gdbinit 72 cd ${.CURDIR}; ${MAKE} ${.TARGET:R} 73 74# Install gdbinit files for kernel debugging. 75gdbinit: 76 grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \ 77 sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit 78 cp ${S}/../tools/debugscripts/gdbinit.kernel ${.CURDIR} 79.if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH}) 80 cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_ARCH} \ 81 ${.CURDIR}/gdbinit.machine 82.endif 83.endif 84 85${FULLKERNEL}: ${SYSTEM_DEP} vers.o 86 @rm -f ${.TARGET} 87 @echo linking ${.TARGET} 88 ${SYSTEM_LD} 89.if !defined(DEBUG) 90 ${OBJCOPY} --strip-debug ${.TARGET} 91.endif 92 ${SYSTEM_LD_TAIL} 93 94.if !exists(${.OBJDIR}/.depend) 95${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/} 96.endif 97 98LNFILES= ${CFILES:T:S/.c$/.ln/} 99 100.for mfile in ${MFILES} 101# XXX the low quality .m.o rules gnerated by config are normally used 102# instead of the .m.c rules here. 103${mfile:T:S/.m$/.c/}: ${mfile} 104 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c 105${mfile:T:S/.m$/.h/}: ${mfile} 106 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h 107.endfor 108 109kernel-clean: 110 rm -f *.o *.so *.So *.ko *.s eddep errs \ 111 ${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.symbols \ 112 linterrs makelinks tags vers.c \ 113 vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \ 114 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 115 ${CLEAN} ${_ILINKS} 116 117lint: ${LNFILES} 118 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \ 119 tee -a linterrs 120 121# This is a hack. BFD "optimizes" away dynamic mode if there are no 122# dynamic references. We could probably do a '-Bforcedynamic' mode like 123# in the a.out ld. For now, this works. 124HACK_EXTRA_FLAGS?= -shared 125hack.So: Makefile 126 touch hack.c 127 ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So 128 rm -f hack.c 129 130# This rule stops ./assym.s in .depend from causing problems. 131./assym.s: assym.s 132 133assym.s: $S/kern/genassym.sh genassym.o 134 NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET} 135 136genassym.o: $S/$M/$M/genassym.c 137 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c 138 139${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 140 141kernel-depend: .depend 142# The argument list can be very long, so use make -V and xargs to 143# pass it to mkdep. 144SRCS= assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \ 145 ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 146 ${MFILES:T:S/.m$/.h/} 147.depend: ${SRCS} 148 rm -f .newdep 149 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | \ 150 MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS} 151 ${MAKE} -V SFILES | \ 152 MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS} 153 rm -f .depend 154 mv .newdep .depend 155 156_ILINKS= machine 157.if ${MACHINE} != ${MACHINE_ARCH} 158_ILINKS+= ${MACHINE_ARCH} 159.endif 160 161# Ensure that the link exists without depending on it when it exists. 162.for _link in ${_ILINKS} 163.if !exists(${.OBJDIR}/${_link}) 164${SRCS}: ${_link} 165.endif 166.endfor 167 168${_ILINKS}: 169 @case ${.TARGET} in \ 170 machine) \ 171 path=${S}/${MACHINE}/include ;; \ 172 ${MACHINE_ARCH}) \ 173 path=${S}/${MACHINE_ARCH}/include ;; \ 174 esac ; \ 175 ${ECHO} ${.TARGET} "->" $$path ; \ 176 ln -s $$path ${.TARGET} 177 178kernel-cleandepend: 179 rm -f .depend 180 181links: 182 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 183 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 184 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 185 sort -u | comm -23 - dontlink | \ 186 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 187 sh makelinks; rm -f dontlink 188 189kernel-tags: 190 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 191 sh $S/conf/systags.sh 192 rm -f tags1 193 sed -e 's, ../, ,' tags > tags1 194 195.if ${MACHINE_ARCH} != "ia64" 196.if exists(${DESTDIR}/boot) 197kernel-install-check: 198 @if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \ 199 echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \ 200 exit 1 ; \ 201 fi 202 @if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \ 203 echo "You must activate /boot/device.hints in loader.conf." ; \ 204 exit 1 ; \ 205 fi 206 207kernel-install: kernel-install-check 208.endif 209.endif 210 211kernel-install: 212 @if [ ! -f ${KERNEL_KO} ] ; then \ 213 echo "You must build a kernel first." ; \ 214 exit 1 ; \ 215 fi 216.if exists(${DESTDIR}${KODIR}) 217 -thiskernel=`sysctl -n kern.bootfile` ; \ 218 if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \ 219 chflags -R noschg ${DESTDIR}${KODIR} ; \ 220 rm -rf ${DESTDIR}${KODIR} ; \ 221 else \ 222 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 223 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 224 rm -rf ${DESTDIR}${KODIR}.old ; \ 225 fi ; \ 226 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 227 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \ 228 fi 229.endif 230 mkdir -p ${DESTDIR}${KODIR} 231 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 232.if defined(DEBUG) && !defined(INSTALL_NODEBUG) 233 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR} 234.endif 235 236kernel-reinstall: 237 @-chflags -R noschg ${DESTDIR}${KODIR} 238 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 239.if defined(DEBUG) && !defined(INSTALL_NODEBUG) 240 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR} 241.endif 242 243config.o env.o hints.o vers.o vnode_if.o: 244 ${NORMAL_C} 245 246config.ln env.ln hints.ln vers.ln vnode_if.ln: 247 ${NORMAL_LINT} 248 249vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 250 MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT} 251 252vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src 253 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c 254 255vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src 256 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h 257 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p 258 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q 259 260# XXX strictly, everything depends on Makefile because changes to ${PROF} 261# only appear there, but we don't handle that. 262 263.include "kern.mk" 264