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} ${KERNEL_EXTRA} 46 47kernel-cleandir: kernel-clean kernel-cleandepend 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.if defined(MFS_IMAGE) 94 @sh ${S}/tools/embed_mfs.sh ${FULLKERNEL} ${MFS_IMAGE} 95.endif 96 97.if !exists(${.OBJDIR}/.depend) 98${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/} 99.endif 100 101LNFILES= ${CFILES:T:S/.c$/.ln/} 102 103.for mfile in ${MFILES} 104# XXX the low quality .m.o rules gnerated by config are normally used 105# instead of the .m.c rules here. 106${mfile:T:S/.m$/.c/}: ${mfile} 107 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c 108${mfile:T:S/.m$/.h/}: ${mfile} 109 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h 110.endfor 111 112kernel-clean: 113 rm -f *.o *.so *.So *.ko *.s eddep errs \ 114 ${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.symbols \ 115 linterrs makelinks tags vers.c \ 116 vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \ 117 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 118 ${CLEAN} 119 120lint: ${LNFILES} 121 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \ 122 tee -a linterrs 123 124# This is a hack. BFD "optimizes" away dynamic mode if there are no 125# dynamic references. We could probably do a '-Bforcedynamic' mode like 126# in the a.out ld. For now, this works. 127HACK_EXTRA_FLAGS?= -shared 128hack.So: Makefile 129 :> hack.c 130 ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So 131 rm -f hack.c 132 133# This rule stops ./assym.s in .depend from causing problems. 134./assym.s: assym.s 135 136assym.s: $S/kern/genassym.sh genassym.o 137 NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET} 138 139genassym.o: $S/$M/$M/genassym.c 140 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c 141 142${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 143 144kernel-depend: .depend 145# The argument list can be very long, so use make -V and xargs to 146# pass it to mkdep. 147SRCS= assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \ 148 ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 149 ${MFILES:T:S/.m$/.h/} 150.depend: .PRECIOUS ${SRCS} 151 rm -f .newdep 152 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | \ 153 MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS} 154 ${MAKE} -V SFILES | \ 155 MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS} 156 rm -f .depend 157 mv .newdep .depend 158 159_ILINKS= machine 160.if ${MACHINE} != ${MACHINE_ARCH} 161_ILINKS+= ${MACHINE_ARCH} 162.endif 163 164# Ensure that the link exists without depending on it when it exists. 165.for _link in ${_ILINKS} 166.if !exists(${.OBJDIR}/${_link}) 167${SRCS}: ${_link} 168.endif 169.endfor 170 171${_ILINKS}: 172 @case ${.TARGET} in \ 173 machine) \ 174 path=${S}/${MACHINE}/include ;; \ 175 ${MACHINE_ARCH}) \ 176 path=${S}/${MACHINE_ARCH}/include ;; \ 177 esac ; \ 178 ${ECHO} ${.TARGET} "->" $$path ; \ 179 ln -s $$path ${.TARGET} 180 181# .depend needs include links so we remove them only together. 182kernel-cleandepend: 183 rm -f .depend ${_ILINKS} 184 185links: 186 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 187 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 188 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 189 sort -u | comm -23 - dontlink | \ 190 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 191 sh makelinks; rm -f dontlink 192 193kernel-tags: 194 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 195 sh $S/conf/systags.sh 196 197kernel-install: 198 @if [ ! -f ${KERNEL_KO} ] ; then \ 199 echo "You must build a kernel first." ; \ 200 exit 1 ; \ 201 fi 202.if exists(${DESTDIR}${KODIR}) 203 -thiskernel=`sysctl -n kern.bootfile` ; \ 204 if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \ 205 chflags -R noschg ${DESTDIR}${KODIR} ; \ 206 rm -rf ${DESTDIR}${KODIR} ; \ 207 else \ 208 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 209 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 210 rm -rf ${DESTDIR}${KODIR}.old ; \ 211 fi ; \ 212 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 213 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \ 214 fi 215.endif 216 mkdir -p ${DESTDIR}${KODIR} 217 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 218.if defined(DEBUG) && !defined(INSTALL_NODEBUG) 219 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR} 220.endif 221.if defined(KERNEL_EXTRA_INSTALL) 222 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_EXTRA_INSTALL} ${DESTDIR}${KODIR} 223.endif 224 225 226 227kernel-reinstall: 228 @-chflags -R noschg ${DESTDIR}${KODIR} 229 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} 230.if defined(DEBUG) && !defined(INSTALL_NODEBUG) 231 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR} 232.endif 233 234config.o env.o hints.o vers.o vnode_if.o: 235 ${NORMAL_C} 236 237config.ln env.ln hints.ln vers.ln vnode_if.ln: 238 ${NORMAL_LINT} 239 240vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 241 MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT} 242 243vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src 244 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c 245 246vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \ 247 $S/kern/vnode_if.src 248vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 249 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h 250vnode_if_newproto.h: 251 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p 252vnode_if_typedef.h: 253 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q 254 255# XXX strictly, everything depends on Makefile because changes to ${PROF} 256# only appear there, but we don't handle that. 257 258.include "kern.mk" 259