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