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