FreeBSD/Linux Kernel Cross Reference
sys/conf/kern.post.mk
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 .if defined(DTS) || defined(DTSO) || defined(FDT_DTS_FILE)
12 .include "dtb.build.mk"
13
14 KERNEL_EXTRA+= ${DTB} ${DTBO}
15 CLEAN+= ${DTB} ${DTBO}
16
17 kernel-install: _dtbinstall
18 .ORDER: beforeinstall _dtbinstall
19 .endif
20
21 # In case the config had a makeoptions DESTDIR...
22 .if defined(DESTDIR)
23 MKMODULESENV+= DESTDIR="${DESTDIR}"
24 .endif
25 SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;:tA}
26 MKMODULESENV+= KERNBUILDDIR="${.CURDIR}" SYSDIR="${SYSDIR}"
27 MKMODULESENV+= MODULE_TIED=yes
28
29 .if defined(CONF_CFLAGS)
30 MKMODULESENV+= CONF_CFLAGS="${CONF_CFLAGS}"
31 .endif
32
33 .if defined(WITH_CTF)
34 MKMODULESENV+= WITH_CTF="${WITH_CTF}"
35 .endif
36
37 .if defined(WITH_EXTRA_TCP_STACKS)
38 MKMODULESENV+= WITH_EXTRA_TCP_STACKS="${WITH_EXTRA_TCP_STACKS}"
39 .endif
40
41 # Allow overriding the kernel debug directory, so kernel and user debug may be
42 # installed in different directories. Setting it to "" restores the historical
43 # behavior of installing debug files in the kernel directory.
44 KERN_DEBUGDIR?= ${DEBUGDIR}
45
46 .MAIN: all
47
48 .for target in all clean cleandepend cleandir clobber depend install \
49 ${_obj} reinstall tags
50 ${target}: kernel-${target}
51 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
52 ${target}: modules-${target}
53 modules-${target}:
54 cd $S/modules; ${MKMODULESENV} ${MAKE} \
55 ${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
56 .endif
57 .endfor
58
59 # Handle ports (as defined by the user) that build kernel modules
60 .if !defined(NO_MODULES) && defined(PORTS_MODULES)
61 #
62 # The ports tree needs some environment variables defined to match the new kernel
63 #
64 # Ports search for some dependencies in PATH, so add the location of the installed files
65 LOCALBASE?= /usr/local
66 # SRC_BASE is how the ports tree refers to the location of the base source files
67 .if !defined(SRC_BASE)
68 SRC_BASE= ${SYSDIR:H:tA}
69 .endif
70 # OSVERSION is used by some ports to determine build options
71 .if !defined(OSRELDATE)
72 # Definition copied from src/Makefile.inc1
73 OSRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
74 ${MAKEOBJDIRPREFIX}${SRC_BASE}/include/osreldate.h
75 .endif
76 # Keep the related ports builds in the obj directory so that they are only rebuilt once per kernel build
77 WRKDIRPREFIX?= ${.OBJDIR}
78 PORTSMODULESENV=\
79 env \
80 -u CC \
81 -u CXX \
82 -u CPP \
83 -u MAKESYSPATH \
84 -u MK_AUTO_OBJ \
85 -u MAKEOBJDIR \
86 MAKEFLAGS="${MAKEFLAGS:M*:tW:S/^-m /-m_/g:S/ -m / -m_/g:tw:N-m_*:NMK_AUTO_OBJ=*}" \
87 SYSDIR=${SYSDIR} \
88 PATH=${PATH}:${LOCALBASE}/bin:${LOCALBASE}/sbin \
89 SRC_BASE=${SRC_BASE} \
90 OSVERSION=${OSRELDATE} \
91 WRKDIRPREFIX=${WRKDIRPREFIX}
92
93 # The WRKDIR needs to be cleaned before building, and trying to change the target
94 # with a :C pattern below results in install -> instclean
95 all:
96 .for __i in ${PORTS_MODULES}
97 @${ECHO} "===> Ports module ${__i} (all)"
98 cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B clean build
99 .endfor
100
101 .for __target in install reinstall clean
102 ${__target}: ports-${__target}
103 ports-${__target}:
104 .for __i in ${PORTS_MODULES}
105 @${ECHO} "===> Ports module ${__i} (${__target})"
106 cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B ${__target:C/(re)?install/deinstall reinstall/}
107 .endfor
108 .endfor
109 .endif
110
111 .ORDER: kernel-install modules-install
112
113 beforebuild: .PHONY
114 kernel-all: beforebuild .WAIT ${KERNEL_KO} ${KERNEL_EXTRA}
115
116 kernel-cleandir: kernel-clean kernel-cleandepend
117
118 kernel-clobber:
119 find . -maxdepth 1 ! -type d ! -name version -delete
120
121 kernel-obj:
122
123 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
124 modules: modules-all
125 modules-depend: beforebuild
126 modules-all: beforebuild
127
128 .if !defined(NO_MODULES_OBJ)
129 modules-all modules-depend: modules-obj
130 .endif
131 .endif
132
133 .if !defined(DEBUG)
134 FULLKERNEL= ${KERNEL_KO}
135 .else
136 FULLKERNEL= ${KERNEL_KO}.full
137 ${KERNEL_KO}: ${FULLKERNEL} ${KERNEL_KO}.debug
138 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${KERNEL_KO}.debug \
139 ${FULLKERNEL} ${.TARGET}
140 ${KERNEL_KO}.debug: ${FULLKERNEL}
141 ${OBJCOPY} --only-keep-debug ${FULLKERNEL} ${.TARGET}
142 install.debug reinstall.debug: gdbinit
143 cd ${.CURDIR}; ${MAKE} ${.TARGET:R}
144
145 # Install gdbinit files for kernel debugging.
146 gdbinit:
147 grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \
148 sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit
149 cp ${S}/../tools/debugscripts/gdbinit.kernel ${.CURDIR}
150 .if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH})
151 cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH} \
152 ${.CURDIR}/gdbinit.machine
153 .endif
154 .endif
155
156 ${FULLKERNEL}: ${SYSTEM_DEP} vers.o
157 @rm -f ${.TARGET}
158 @echo linking ${.TARGET}
159 ${SYSTEM_LD}
160 .if !empty(MD_ROOT_SIZE_CONFIGURED) && defined(MFS_IMAGE)
161 @sh ${S}/tools/embed_mfs.sh ${.TARGET} ${MFS_IMAGE}
162 .endif
163 .if ${MK_CTF} != "no"
164 @echo ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ...
165 @${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
166 .endif
167 .if !defined(DEBUG)
168 ${OBJCOPY} --strip-debug ${.TARGET}
169 .endif
170 ${SYSTEM_LD_TAIL}
171
172 OBJS_DEPEND_GUESS+= offset.inc assym.inc vnode_if.h ${BEFORE_DEPEND:M*.h} \
173 ${MFILES:T:S/.m$/.h/}
174
175 .for mfile in ${MFILES}
176 # XXX the low quality .m.o rules gnerated by config are normally used
177 # instead of the .m.c rules here.
178 ${mfile:T:S/.m$/.c/}: ${mfile}
179 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c
180 ${mfile:T:S/.m$/.h/}: ${mfile}
181 ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h
182 .endfor
183
184 kernel-clean:
185 rm -f *.o *.so *.pico *.ko *.s eddep errs \
186 ${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.debug \
187 tags vers.c \
188 vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \
189 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
190 ${CLEAN}
191
192 # This is a hack. BFD "optimizes" away dynamic mode if there are no
193 # dynamic references. We could probably do a '-Bforcedynamic' mode like
194 # in the a.out ld. For now, this works.
195 hack.pico: Makefile
196 :> hack.c
197 ${CC} -shared ${CFLAGS} -nostdlib hack.c -o hack.pico
198 rm -f hack.c
199
200 offset.inc: $S/kern/genoffset.sh genoffset.o
201 NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genoffset.sh genoffset.o > ${.TARGET}
202
203 genoffset.o: $S/kern/genoffset.c
204 ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon $S/kern/genoffset.c
205
206 # genoffset_test.o is not actually used for anything - the point of compiling it
207 # is to exercise the CTASSERT that checks that the offsets in the offset.inc
208 # _lite struct(s) match those in the original(s).
209 genoffset_test.o: $S/kern/genoffset.c offset.inc
210 ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon -DOFFSET_TEST \
211 $S/kern/genoffset.c -o ${.TARGET}
212
213 assym.inc: $S/kern/genassym.sh genassym.o genoffset_test.o
214 NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
215
216 genassym.o: $S/$M/$M/genassym.c offset.inc
217 ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon $S/$M/$M/genassym.c
218
219 OBJS_DEPEND_GUESS+= opt_global.h
220 genoffset.o genassym.o vers.o: opt_global.h
221
222 .if !empty(.MAKE.MODE:Unormal:Mmeta) && empty(.MAKE.MODE:Unormal:Mnofilemon)
223 _meta_filemon= 1
224 .endif
225 # Skip reading .depend when not needed to speed up tree-walks and simple
226 # lookups. For install, only do this if no other targets are specified.
227 # Also skip generating or including .depend.* files if in meta+filemon mode
228 # since it will track dependencies itself. OBJS_DEPEND_GUESS is still used
229 # for _meta_filemon but not for _SKIP_DEPEND.
230 .if !defined(NO_SKIP_DEPEND) && \
231 ((!empty(.MAKEFLAGS:M-V) && empty(.MAKEFLAGS:M*DEP*)) || \
232 ${.TARGETS:M*obj} == ${.TARGETS} || \
233 ${.TARGETS:M*clean*} == ${.TARGETS} || \
234 ${.TARGETS:M*install*} == ${.TARGETS})
235 _SKIP_DEPEND= 1
236 .endif
237 .if defined(_SKIP_DEPEND) || defined(_meta_filemon)
238 .MAKE.DEPENDFILE= /dev/null
239 .endif
240
241 kernel-depend: .depend
242 SRCS= assym.inc offset.inc vnode_if.h ${BEFORE_DEPEND} ${CFILES} \
243 ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
244 ${MFILES:T:S/.m$/.h/}
245 DEPENDOBJS+= ${SYSTEM_OBJS} genassym.o genoffset.o genoffset_test.o
246 DEPENDOBJS+= ${CLEAN:M*.o}
247 DEPENDFILES= ${DEPENDOBJS:O:u:C/^/.depend./}
248 .if ${MAKE_VERSION} < 20160220
249 DEPEND_MP?= -MP
250 .endif
251 .if defined(_SKIP_DEPEND)
252 # Don't bother reading any .meta files
253 ${DEPENDOBJS}: .NOMETA
254 .depend: .NOMETA
255 # Unset these to avoid looping/statting on them later.
256 .undef DEPENDOBJS
257 .undef DEPENDFILES
258 .endif # defined(_SKIP_DEPEND)
259 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF.depend.${.TARGET}
260 DEPEND_CFLAGS+= -MT${.TARGET}
261 .if !defined(_meta_filemon)
262 .if !empty(DEPEND_CFLAGS)
263 # Only add in DEPEND_CFLAGS for CFLAGS on files we expect from DEPENDOBJS
264 # as those are the only ones we will include.
265 DEPEND_CFLAGS_CONDITION= "${DEPENDOBJS:M${.TARGET}}" != ""
266 CFLAGS+= ${${DEPEND_CFLAGS_CONDITION}:?${DEPEND_CFLAGS}:}
267 .endif
268 .for __depend_obj in ${DEPENDFILES}
269 .if ${MAKE_VERSION} < 20160220
270 .sinclude "${.OBJDIR}/${__depend_obj}"
271 .else
272 .dinclude "${.OBJDIR}/${__depend_obj}"
273 .endif
274 .endfor
275 .endif # !defined(_meta_filemon)
276
277 # Always run 'make depend' to generate dependencies early and to avoid the
278 # need for manually running it. For the kernel this is mostly a NOP since
279 # all dependencies are correctly added or accounted for. This is mostly to
280 # ensure downstream uses of kernel-depend are handled.
281 beforebuild: kernel-depend
282
283 # Guess some dependencies for when no ${DEPENDFILE}.OBJ is generated yet.
284 # For meta+filemon the .meta file is checked for since it is the dependency
285 # file used.
286 .for __obj in ${DEPENDOBJS:O:u}
287 .if defined(_meta_filemon)
288 _depfile= ${.OBJDIR}/${__obj}.meta
289 .else
290 _depfile= ${.OBJDIR}/.depend.${__obj}
291 .endif
292 .if !exists(${_depfile})
293 .if ${SYSTEM_OBJS:M${__obj}}
294 ${__obj}: ${OBJS_DEPEND_GUESS}
295 .endif
296 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
297 .elif defined(_meta_filemon)
298 # For meta mode we still need to know which file to depend on to avoid
299 # ambiguous suffix transformation rules from .PATH. Meta mode does not
300 # use .depend files. We really only need source files, not headers since
301 # they are typically in SRCS/beforebuild already. For target-specific
302 # guesses do include headers though since they may not be in SRCS.
303 .if ${SYSTEM_OBJS:M${__obj}}
304 ${__obj}: ${OBJS_DEPEND_GUESS:N*.h}
305 .endif
306 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
307 .endif # !exists(${_depfile})
308 .endfor
309
310 .NOPATH: .depend ${DEPENDFILES}
311
312 .depend: .PRECIOUS ${SRCS}
313
314 .if ${COMPILER_TYPE} == "clang" || \
315 (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60000)
316 _MAP_DEBUG_PREFIX= yes
317 .endif
318
319 _ILINKS= machine
320 .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
321 _ILINKS+= ${MACHINE_CPUARCH}
322 .endif
323 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
324 _ILINKS+= x86
325 .endif
326
327 # Ensure that the link exists without depending on it when it exists.
328 # Ensure that debug info references the path in the source tree.
329 .for _link in ${_ILINKS}
330 .if !exists(${.OBJDIR}/${_link})
331 ${SRCS} ${DEPENDOBJS}: ${_link}
332 .endif
333 .if defined(_MAP_DEBUG_PREFIX)
334 .if ${_link} == "machine"
335 CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include
336 .else
337 CFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include
338 .endif
339 .endif
340 .endfor
341
342 ${_ILINKS}:
343 @case ${.TARGET} in \
344 machine) \
345 path=${S}/${MACHINE}/include ;; \
346 *) \
347 path=${S}/${.TARGET}/include ;; \
348 esac ; \
349 ${ECHO} ${.TARGET} "->" $$path ; \
350 ln -fns $$path ${.TARGET}
351
352 # .depend needs include links so we remove them only together.
353 kernel-cleandepend: .PHONY
354 rm -f .depend .depend.* ${_ILINKS}
355
356 kernel-tags:
357 @ls .depend.* > /dev/null 2>&1 || \
358 { echo "you must make all first"; exit 1; }
359 sh $S/conf/systags.sh
360
361 kernel-install: .PHONY
362 @if [ ! -f ${KERNEL_KO} ] ; then \
363 echo "You must build a kernel first." ; \
364 exit 1 ; \
365 fi
366 .if exists(${DESTDIR}${KODIR})
367 -thiskernel=`sysctl -n kern.bootfile` ; \
368 if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \
369 chflags -R noschg ${DESTDIR}${KODIR} ; \
370 rm -rf ${DESTDIR}${KODIR} ; \
371 rm -rf ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ; \
372 else \
373 if [ -d ${DESTDIR}${KODIR}.old ] ; then \
374 chflags -R noschg ${DESTDIR}${KODIR}.old ; \
375 rm -rf ${DESTDIR}${KODIR}.old ; \
376 fi ; \
377 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
378 if [ -n "${KERN_DEBUGDIR}" -a \
379 -d ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ]; then \
380 rm -rf ${DESTDIR}${KERN_DEBUGDIR}${KODIR}.old ; \
381 mv ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ${DESTDIR}${KERN_DEBUGDIR}${KODIR}.old ; \
382 fi ; \
383 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
384 fi
385 .endif
386 mkdir -p ${DESTDIR}${KODIR}
387 ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}/
388 .if defined(DEBUG) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
389 mkdir -p ${DESTDIR}${KERN_DEBUGDIR}${KODIR}
390 ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.debug ${DESTDIR}${KERN_DEBUGDIR}${KODIR}/
391 .endif
392 .if defined(KERNEL_EXTRA_INSTALL)
393 ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_EXTRA_INSTALL} ${DESTDIR}${KODIR}/
394 .endif
395
396
397
398 kernel-reinstall:
399 @-chflags -R noschg ${DESTDIR}${KODIR}
400 ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}/
401 .if defined(DEBUG) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
402 ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.debug ${DESTDIR}${KERN_DEBUGDIR}${KODIR}/
403 .endif
404
405 config.o env.o hints.o vers.o vnode_if.o:
406 ${NORMAL_C}
407 ${NORMAL_CTFCONVERT}
408
409 .if ${MK_REPRODUCIBLE_BUILD} != "no"
410 REPRO_FLAG="-R"
411 .endif
412 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
413 MAKE="${MAKE}" sh $S/conf/newvers.sh ${REPRO_FLAG} ${KERN_IDENT}
414
415 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
416 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
417
418 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \
419 $S/kern/vnode_if.src
420 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
421 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
422 vnode_if_newproto.h:
423 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p
424 vnode_if_typedef.h:
425 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q
426
427 .if ${MFS_IMAGE:Uno} != "no"
428 .if empty(MD_ROOT_SIZE_CONFIGURED)
429 embedfs_${MFS_IMAGE:T:R}.o: ${MFS_IMAGE} $S/dev/md/embedfs.S
430 ${CC} ${CFLAGS} ${ACFLAGS} -DMFS_IMAGE="${MFS_IMAGE}" -c \
431 $S/dev/md/embedfs.S -o ${.TARGET}
432 .endif
433 .endif
434
435 # XXX strictly, everything depends on Makefile because changes to ${PROF}
436 # only appear there, but we don't handle that.
437
438 .include "kern.mk"
Cache object: 19cf7bac53ce682097df37a71fc4d096
|