1# 2# This Makefile covers the bottom part of the MI build instructions 3# 4 5.PHONY: all modules 6 7all: ${KERNEL}.stripped 8 9_MACHINE_FWD= ${.OBJDIR} 10.include "$S/conf/kern.fwd.mk" 11.include "$S/conf/kern.paths.mk" 12 13depend kernel-depend modules-depend: ${FORWARD_HEADERS_COOKIE} 14 15depend: kernel-depend 16clean: kernel-clean 17cleandepend: kernel-cleandepend 18tags: kernel-tags 19install: kernel-install 20reinstall: kernel-reinstall 21 22# Often developers just want the kernel, don't let 23# -j builds leak into the modules until the kernel is done. 24# 25.ORDER: ${KERNEL}.stripped modules 26 27${KERNEL}.stripped: ${FULLKERNEL} 28 ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL}.stripped 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}: ${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 awk -f $S/tools/makeobjops.awk -- -h ${mfile} 43.endfor 44 45kernel-clean: 46 rm -f *.o *.so *.So *.ko *.s errs \ 47 ${KERNEL} ${KERNEL}.debug ${KERNEL}.nodebug ${KERNEL}.stripped \ 48 tags vers.c \ 49 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ 50 ${CLEAN} 51 52locore.o: $S/platform/$P/$M/locore.s assym.s 53 ${NORMAL_S} 54 55# This is a hack. BFD "optimizes" away dynamic mode if there are no 56# dynamic references. We could probably do a '-Bforcedynamic' mode like 57# in the a.out ld. For now, this works. 58hack.So: Makefile 59 touch hack.c 60 ${CC} -shared -nostdlib hack.c -o hack.So 61 rm -f hack.c 62 63# this rule stops ./assym.s in .depend from causing problems 64./assym.s: assym.s 65 66assym.s: $S/kern/genassym.sh genassym.o 67 sh $S/kern/genassym.sh genassym.o > ${.TARGET} 68 69genassym.o: $S/platform/$P/$M/genassym.c ${FORWARD_HEADERS_COOKIE} \ 70 ${MFILES:T:S/.m$/.h/} 71 ${CC} -c ${CFLAGS:N-fno-common:N-flto:N-mcmodel=small} -fcommon \ 72 ${WERROR} $S/platform/$P/$M/genassym.c 73 74${SYSTEM_OBJS} genassym.o vers.o: opt_global.h 75 76# The argument list can be very long, use make -V and xargs to 77# pass it to mkdep. 78kernel-depend: assym.s ${BEFORE_DEPEND} \ 79 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ 80 ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/} 81.if defined(FASTER_DEPEND) 82.if exists(hack.So) 83 @cat ${SYSTEM_OBJS:M*\.o$:S/.o$/.d/} genassym.d > .depend || \ 84 echo "There were missing deps" 85.endif 86.else 87 rm -f .newdep 88 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \ 89 mkdep -a -f .newdep ${CFLAGS} 90 ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \ 91 env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS} 92 rm -f .depend 93 mv -f .newdep .depend 94.endif 95 96kernel-cleandepend: 97.if defined(FASTER_DEPEND) 98 rm -f *.d 99.endif 100 rm -f .depend 101 102kernel-tags: 103 @[ -f .depend ] || { echo "you must make depend first"; /usr/bin/false; } 104 sh $S/conf/systags.sh 105 rm -f tags1 106 sed -e 's, ../, ,' tags > tags1 107 108# Note: when moving the existing kernel to .old, it is by default stripped 109# so we do not have two full debug environments sitting in / eating up space. 110# 111# Also note the .old might be a file and not a directory, so we have to 112# remove it first. 113# 114kernel-install: kernel-installable 115 @if [ ! -f ${SELECTEDKERNEL} ]; then \ 116 echo "You must build a kernel first."; \ 117 /usr/bin/false; \ 118 fi 119 @if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \ 120 rm -f ${DESTDIR}${DESTKERNDIR}.old; \ 121 fi 122 mkdir -p ${DESTDIR}${DESTKERNDIR}.old 123.if exists(${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}) 124.ifndef NOFSCHG 125 -chflags noschg ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} 126.endif 127. ifdef NO_KERNEL_OLD_STRIP 128 cp -p ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME} 129. else 130 ${OBJCOPY} --strip-debug ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME} 131. endif 132.endif 133 @if [ -f ${DESTDIR}${DESTKERNDIR} ]; then \ 134 chflags noschg ${DESTDIR}${DESTKERNDIR}; \ 135 rm -f ${DESTDIR}${DESTKERNDIR}; \ 136 fi 137 mkdir -p ${DESTDIR}${DESTKERNDIR} 138.ifdef NOFSCHG 139 ${INSTALL} -m 555 -o root -g wheel \ 140 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} 141.else 142 ${INSTALL} -m 555 -o root -g wheel -fschg \ 143 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} 144.endif 145 146kernel-reinstall: kernel-installable 147 mkdir -p ${DESTDIR}${DESTKERNDIR} 148.ifdef NOFSCHG 149 ${INSTALL} -m 555 -o root -g wheel \ 150 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} 151.else 152 ${INSTALL} -m 555 -o root -g wheel -fschg \ 153 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} 154.endif 155 156kernel-installable: 157 @if [ -f ${DESTDIR}/${DESTKERNNAME} ]; then \ 158 echo "You need to make buildworld, installworld, and upgrade"; \ 159 echo "before you can install a new kernel, because the"; \ 160 echo "kernel and modules have moved to /boot"; \ 161 /usr/bin/false; \ 162 fi 163# Skip this step for vkernels 164.if ${MACHINE_PLATFORM} != vkernel64 165 @if [ ! -f ${DESTDIR}/boot/dloader.rc ]; then \ 166 echo "You need to install a new ${DESTDIR}/boot before you"; \ 167 echo "can install a new kernel, kernels are now installed"; \ 168 echo "into a subdirectory along with their modules."; \ 169 echo "You can do this with a buildworld / installworld"; \ 170 echo "sequence."; \ 171 /usr/bin/false; \ 172 fi 173.endif 174 175.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) 176all: modules 177depend: modules-depend 178clean: modules-clean 179cleandepend: modules-cleandepend 180cleandir: modules-cleandir 181tags: modules-tags 182install: modules-install 183reinstall: modules-reinstall 184.endif 185 186modules: 187 @mkdir -p ${.OBJDIR} 188 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \ 189 env ${MKMODULESENV} ${MAKE} -f Makefile.modules all 190 191modules-depend: 192 @mkdir -p ${.OBJDIR} 193 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \ 194 env ${MKMODULESENV} ${MAKE} -f Makefile.modules depend 195 196modules-clean: 197 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules clean 198 199modules-cleandepend: 200 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandepend 201 202# XXX huh? 203#modules-clobber: modules-clean 204# rm -rf ${MKMODULESENV} 205 206modules-cleandir: 207 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandir 208 209modules-tags: 210 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags 211 212# Note: when moving the existing modules to .old, they are by default stripped 213# so we do not have two full debug environments sitting in / eating up space. 214# 215# We may have to remove deprecated kernel.old files before we can create 216# the kernel.old directory. 217# 218modules-install: kernel-installable 219.if !defined(NO_MODULES_OLD) 220. ifdef NO_KERNEL_OLD_STRIP 221 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \ 222 if [ -f "$$1" ]; then \ 223 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \ 224 rm -f ${DESTDIR}${DESTKERNDIR}.old; \ 225 fi; \ 226 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \ 227 for file; do \ 228 cp -p $$file ${DESTDIR}${DESTKERNDIR}.old; \ 229 done; \ 230 fi 231. else 232 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \ 233 if [ -f "$$1" ]; then \ 234 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \ 235 rm -f ${DESTDIR}${DESTKERNDIR}.old; \ 236 fi; \ 237 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \ 238 for file; do \ 239 ${OBJCOPY} --strip-debug $$file ${DESTDIR}${DESTKERNDIR}.old/$${file##*/}; \ 240 done; \ 241 fi 242. endif 243 if [ -f ${DESTDIR}${DESTKERNDIR}/initrd.img ]; then \ 244 cp -p ${DESTDIR}${DESTKERNDIR}/initrd.img ${DESTDIR}${DESTKERNDIR}.old; \ 245 fi 246 if [ -f ${DESTDIR}${DESTKERNDIR}/initrd.img.gz ]; then \ 247 cp -p ${DESTDIR}${DESTKERNDIR}/initrd.img.gz ${DESTDIR}${DESTKERNDIR}.old; \ 248 fi 249.endif 250.if exists(${DESTDIR}/${OLDMODULESDIR}) 251 rm -rf ${DESTDIR}/${OLDMODULESDIR} # remove deprecated 252.endif 253 mkdir -p ${DESTDIR}${DESTKERNDIR} # Ensure that the modules directory exists! 254 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install 255 256modules-reinstall: 257 mkdir -p ${DESTDIR}/${DESTKERNDIR} # Ensure that the modules directory exists! 258 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install 259 260config.o: 261 ${NORMAL_C} ${WERROR} 262 263ioconf.o: 264 ${NORMAL_C} ${WERROR} 265 266vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP} 267 sh $S/conf/newvers.sh $S/.. 268 269vers.o: 270 ${NORMAL_C} ${WERROR} 271 272.include "$S/conf/bsd.kern.mk" 273