1# kern.post.mk 2# 3# Unified Makefile for building kenrels. This includes all the definitions 4# that need to be included after all the % directives, except %RULES and 5# things that act like they are part of %RULES 6# 7# $FreeBSD$ 8# 9 10.PHONY: all modules 11 12depend: kernel-depend 13clean: kernel-clean 14cleandepend: kernel-cleandepend 15clobber: kernel-clobber 16tags: kernel-tags 17install: kernel-install 18install.debug: kernel-install.debug 19reinstall: kernel-reinstall 20reinstall.debug: kernel-reinstall.debug 21 22.if !defined(DEBUG) 23FULLKERNEL= ${KERNEL_KO} 24.else 25FULLKERNEL= ${KERNEL_KO}.debug 26${KERNEL_KO}: ${FULLKERNEL} 27 ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO} 28.endif 29 30${FULLKERNEL}: ${SYSTEM_DEP} vers.o 31 @rm -f ${.TARGET} 32 @echo linking ${.TARGET} 33 ${SYSTEM_LD} 34 ${SYSTEM_LD_TAIL} 35 36.if !exists(.depend) 37${SYSTEM_OBJS}: vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/} 38.endif 39 40.for mfile in ${MFILES} 41${mfile:T:S/.m$/.h/}: ${mfile} 42 perl5 $S/kern/makeobjops.pl -h ${mfile} 43.endfor 44 45kernel-clean: 46 rm -f *.o *.so *.So *.ko *.s eddep errs \ 47 ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks \ 48 setdef[01].c setdefs.h tags \ 49 vers.c vnode_if.c vnode_if.h \ 50 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 51 ${CLEAN} 52 53kernel-clobber: 54 find . -type f ! -name version -delete 55 56locore.o: $S/$M/$M/locore.s assym.s 57 ${NORMAL_S} 58 59# This is a hack. BFD "optimizes" away dynamic mode if there are no 60# dynamic references. We could probably do a '-Bforcedynamic' mode like 61# in the a.out ld. For now, this works. 62HACK_EXTRA_FLAGS?= -shared 63hack.So: Makefile 64 touch hack.c 65 ${CC} ${FMT} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So 66 rm -f hack.c 67 68# this rule stops ./assym.s in .depend from causing problems 69./assym.s: assym.s 70 71assym.s: $S/kern/genassym.sh genassym.o 72 NM=${NM} OBJFORMAT=elf sh $S/kern/genassym.sh genassym.o > ${.TARGET} 73 74genassym.o: $S/$M/$M/genassym.c 75 ${CC} -c ${CFLAGS} $S/$M/$M/genassym.c 76 77${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 78 79kernel-depend: 80.if defined(EXTRA_KERNELDEP) 81 ${EXTRA_KERNELDEP} 82.endif 83 rm -f .olddep 84 if [ -f .depend ]; then mv .depend .olddep; fi 85 ${MAKE} _kernel-depend 86 87_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \ 88 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 89 ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/} 90 if [ -f .olddep ]; then mv .olddep .depend; fi 91 rm -f .newdep 92 env MKDEP_CPP="${CC} -E" CC="${CC}" \ 93 mkdep -a -f .newdep ${CFLAGS} ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} 94 env MKDEP_CPP="${CC} -E" \ 95 mkdep -a -f .newdep ${ASM_CFLAGS} ${SFILES} ${SYSTEM_SFILES} 96 rm -f .depend 97 mv .newdep .depend 98 99kernel-cleandepend: 100 rm -f .depend 101 102links: 103 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ 104 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink 105 echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ 106 sort -u | comm -23 - dontlink | \ 107 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks 108 sh makelinks; rm -f dontlink 109 110kernel-tags: 111 @[ -f .depend ] || { echo "you must make depend first"; exit 1; } 112 sh $S/conf/systags.sh 113 rm -f tags1 114 sed -e 's, ../, ,' tags > tags1 115 116kernel-install kernel-install.debug: 117.if exists(${DESTDIR}/boot) 118 @if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \ 119 echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \ 120 exit 1 ; \ 121 fi 122 @if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \ 123 echo "You must activate /boot/device.hints in loader.conf." ; \ 124 exit 1 ; \ 125 fi 126.endif 127 @if [ ! -f ${KERNEL_KO}${.TARGET:S/kernel-install//} ] ; then \ 128 echo "You must build a kernel first." ; \ 129 exit 1 ; \ 130 fi 131.if exists(${DESTDIR}${KODIR}) 132 -thiskernel=`sysctl -n kern.bootfile` ; \ 133 if [ "$$thiskernel" = ${DESTDIR}${KODIR}.old/${KERNEL_KO} ] ; then \ 134 chflags -R noschg ${DESTDIR}${KODIR} ; \ 135 rm -rf ${DESTDIR}${KODIR} ; \ 136 else \ 137 if [ -d ${DESTDIR}${KODIR}.old ] ; then \ 138 chflags -R noschg ${DESTDIR}${KODIR}.old ; \ 139 rm -rf ${DESTDIR}${KODIR}.old ; \ 140 fi ; \ 141 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \ 142 if [ "$$thiskernel" = ${DESTDIR}${KODIR}/${KERNEL_KO} ] ; then \ 143 sysctl -w kern.bootfile=${DESTDIR}${KODIR}.old/${KERNEL_KO} ; \ 144 fi; \ 145 fi 146.endif 147 mkdir -p ${DESTDIR}${KODIR} 148 install -c -m 555 -o root -g wheel \ 149 ${KERNEL_KO}${.TARGET:S/kernel-install//} ${DESTDIR}${KODIR} 150 151kernel-reinstall kernel-reinstall.debug: 152 @-chflags -R noschg ${DESTDIR}${KODIR} 153 install -c -m 555 -o root -g wheel \ 154 ${KERNEL_KO}${.TARGET:S/kernel-reinstall//} ${DESTDIR}${KODIR} 155 156.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules) 157all: modules 158depend: modules-depend 159clean: modules-clean 160cleandepend: modules-cleandepend 161cleandir: modules-cleandir 162clobber: modules-clobber 163tags: modules-tags 164install: modules-install 165install.debug: modules-install.debug 166reinstall: modules-reinstall 167reinstall.debug: modules-reinstall.debug 168.endif 169 170MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR} 171.if defined(MODULES_OVERRIDE) 172MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}" 173.endif 174.if defined(DEBUG) 175MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}" 176.endif 177 178modules: 179 @mkdir -p ${.OBJDIR}/modules 180 cd $S/modules ; env ${MKMODULESENV} ${MAKE} obj ; \ 181 env ${MKMODULESENV} ${MAKE} all 182 183modules-depend: 184 @mkdir -p ${.OBJDIR}/modules 185 cd $S/modules ; env ${MKMODULESENV} ${MAKE} obj ; \ 186 env ${MKMODULESENV} ${MAKE} depend 187 188modules-clean: 189 cd $S/modules ; env ${MKMODULESENV} ${MAKE} clean 190 191modules-cleandepend: 192 cd $S/modules ; env ${MKMODULESENV} ${MAKE} cleandepend 193 194modules-clobber: modules-clean 195 rm -rf ${MKMODULESENV} 196 197modules-cleandir: 198 cd $S/modules ; env ${MKMODULESENV} ${MAKE} cleandir 199 200modules-tags: 201 cd $S/modules ; env ${MKMODULESENV} ${MAKE} tags 202 203modules-install modules-reinstall: 204 cd $S/modules ; env ${MKMODULESENV} ${MAKE} install 205 206modules-install.debug modules-reinstall.debug: 207 cd $S/modules ; env ${MKMODULESENV} ${MAKE} install.debug 208 209config.o: 210 ${NORMAL_C} 211 212vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 213 sh $S/conf/newvers.sh ${KERN_IDENT} ${IDENT} 214 215# XXX strictly, everything depends on Makefile because changes to ${PROF} 216# only appear there, but we don't handle that. 217vers.o: 218 ${NORMAL_C} 219 220hints.o: hints.c 221 ${NORMAL_C} 222 223env.o: env.c 224 ${NORMAL_C} 225 226vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src 227 perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src 228 229vnode_if.h: $S/kern/vnode_if.pl $S/kern/vnode_if.src 230 perl5 $S/kern/vnode_if.pl -h $S/kern/vnode_if.src 231 232vnode_if.o: 233 ${NORMAL_C} 234 235# Commented out for now pending a better solution. 236# How do we pick up compiler version specific flags?? 237#.if exists($S/../share/mk) 238#.include "$S/../share/mk/bsd.kern.mk" 239#.else 240.include <bsd.kern.mk> 241#.endif 242