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.
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.
11 # In case the config had a makeoptions DESTDIR...
13 MKMODULESENV+= DESTDIR="${DESTDIR}"
15 MKMODULESENV+= KERNBUILDDIR="${.CURDIR}"
19 .for target in all clean cleandepend cleandir clobber depend install \
21 ${target}: kernel-${target}
22 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
23 ${target}: modules-${target}
25 cd $S/modules; ${MKMODULESENV} ${MAKE} \
26 ${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
30 # Handle out of tree ports
31 .if !defined(NO_MODULES) && defined(PORTS_MODULES)
32 SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;}
33 PORTSMODULESENV=SYSDIR=${SYSDIR}
34 .for __target in all install reinstall clean
35 ${__target}: ports-${__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/}
43 .ORDER: kernel-install modules-install
45 kernel-all: ${KERNEL_KO}
47 kernel-cleandir: kernel-clean kernel-cleandepend
50 find . -maxdepth 1 ! -type d ! -name version -delete
54 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
57 .if !defined(NO_MODULES_OBJ)
58 modules-all modules-depend: modules-obj
63 FULLKERNEL= ${KERNEL_KO}
65 FULLKERNEL= ${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}
71 install.debug reinstall.debug: gdbinit
72 cd ${.CURDIR}; ${MAKE} ${.TARGET:R}
74 # Install gdbinit files for kernel debugging.
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
85 ${FULLKERNEL}: ${SYSTEM_DEP} vers.o
87 @echo linking ${.TARGET}
90 ${OBJCOPY} --strip-debug ${.TARGET}
93 .if defined(MFS_IMAGE)
94 @dd if="${MFS_IMAGE}" ibs=8192 of="${FULLKERNEL}" \
95 obs=`strings -at d "${FULLKERNEL}" | \
96 grep "MFS Filesystem goes here" | awk '{print $$1}'` \
97 oseek=1 conv=notrunc 2>/dev/null && \
98 strings ${FULLKERNEL} | \
99 grep 'MFS Filesystem had better STOP here' > /dev/null || \
100 (rm ${FULLKERNEL} && echo 'MFS image too large' && false)
103 .if !exists(${.OBJDIR}/.depend)
104 ${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
107 LNFILES= ${CFILES:T:S/.c$/.ln/}
109 .for mfile in ${MFILES}
110 # XXX the low quality .m.o rules gnerated by config are normally used
111 # instead of the .m.c rules here.
112 ${mfile:T:S/.m$/.c/}: ${mfile}
113 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c
114 ${mfile:T:S/.m$/.h/}: ${mfile}
115 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h
119 rm -f *.o *.so *.So *.ko *.s eddep errs \
120 ${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.symbols \
121 linterrs makelinks tags vers.c \
122 vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \
123 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
127 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \
130 # This is a hack. BFD "optimizes" away dynamic mode if there are no
131 # dynamic references. We could probably do a '-Bforcedynamic' mode like
132 # in the a.out ld. For now, this works.
133 HACK_EXTRA_FLAGS?= -shared
136 ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
139 # This rule stops ./assym.s in .depend from causing problems.
142 assym.s: $S/kern/genassym.sh genassym.o
143 NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
145 genassym.o: $S/$M/$M/genassym.c
146 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
148 ${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
150 kernel-depend: .depend
151 # The argument list can be very long, so use make -V and xargs to
153 SRCS= assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \
154 ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
155 ${MFILES:T:S/.m$/.h/}
156 .depend: .PRECIOUS ${SRCS}
158 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | \
159 MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS}
160 ${MAKE} -V SFILES | \
161 MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS}
166 .if ${MACHINE} != ${MACHINE_ARCH}
167 _ILINKS+= ${MACHINE_ARCH}
170 # Ensure that the link exists without depending on it when it exists.
171 .for _link in ${_ILINKS}
172 .if !exists(${.OBJDIR}/${_link})
178 @case ${.TARGET} in \
180 path=${S}/${MACHINE}/include ;; \
182 path=${S}/${MACHINE_ARCH}/include ;; \
184 ${ECHO} ${.TARGET} "->" $$path ; \
185 ln -s $$path ${.TARGET}
187 # .depend needs include links so we remove them only together.
189 rm -f .depend ${_ILINKS}
192 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
193 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
194 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
195 sort -u | comm -23 - dontlink | \
196 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
197 sh makelinks; rm -f dontlink
200 @[ -f .depend ] || { echo "you must make depend first"; exit 1; }
201 sh $S/conf/systags.sh
204 @if [ ! -f ${KERNEL_KO} ] ; then \
205 echo "You must build a kernel first." ; \
208 .if exists(${DESTDIR}${KODIR})
209 -thiskernel=`sysctl -n kern.bootfile` ; \
210 if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \
211 chflags -R noschg ${DESTDIR}${KODIR} ; \
212 rm -rf ${DESTDIR}${KODIR} ; \
214 if [ -d ${DESTDIR}${KODIR}.old ] ; then \
215 chflags -R noschg ${DESTDIR}${KODIR}.old ; \
216 rm -rf ${DESTDIR}${KODIR}.old ; \
218 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
219 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
222 mkdir -p ${DESTDIR}${KODIR}
223 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
224 .if defined(DEBUG) && !defined(INSTALL_NODEBUG)
225 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR}
229 @-chflags -R noschg ${DESTDIR}${KODIR}
230 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
231 .if defined(DEBUG) && !defined(INSTALL_NODEBUG)
232 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR}
235 config.o env.o hints.o vers.o vnode_if.o:
238 config.ln env.ln hints.ln vers.ln vnode_if.ln:
241 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
242 MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT}
244 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
245 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
247 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \
249 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
250 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
252 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p
254 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q
256 # XXX strictly, everything depends on Makefile because changes to ${PROF}
257 # only appear there, but we don't handle that.