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 # In case the config had a makeoptions DESTDIR...
12 .if defined(DESTDIR)
13 MKMODULESENV+= DESTDIR="${DESTDIR}"
14 .endif
15 MKMODULESENV+= KERNBUILDDIR="${.CURDIR}"
16
17 .MAIN: all
18
19 .for target in all clean cleandepend cleandir clobber depend install \
20 obj reinstall tags
21 ${target}: kernel-${target}
22 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
23 ${target}: modules-${target}
24 modules-${target}:
25 cd $S/modules; ${MKMODULESENV} ${MAKE} \
26 ${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
27 .endif
28 .endfor
29
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}
36 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/}
39 .endfor
40 .endfor
41 .endif
42
43 .ORDER: kernel-install modules-install
44
45 kernel-all: ${KERNEL_KO} ${KERNEL_EXTRA}
46
47 kernel-cleandir: kernel-clean kernel-cleandepend
48
49 kernel-clobber:
50 find . -maxdepth 1 ! -type d ! -name version -delete
51
52 kernel-obj:
53
54 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
55 modules: modules-all
56
57 .if !defined(NO_MODULES_OBJ)
58 modules-all modules-depend: modules-obj
59 .endif
60 .endif
61
62 .if !defined(DEBUG)
63 FULLKERNEL= ${KERNEL_KO}
64 .else
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}
73
74 # Install gdbinit files for kernel debugging.
75 gdbinit:
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
82 .endif
83 .endif
84
85 ${FULLKERNEL}: ${SYSTEM_DEP} vers.o
86 @rm -f ${.TARGET}
87 @echo linking ${.TARGET}
88 ${SYSTEM_LD}
89 .if !defined(DEBUG)
90 ${OBJCOPY} --strip-debug ${.TARGET}
91 .endif
92 ${SYSTEM_LD_TAIL}
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)
101 .endif
102
103 .if !exists(${.OBJDIR}/.depend)
104 ${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
105 .endif
106
107 LNFILES= ${CFILES:T:S/.c$/.ln/}
108
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
116 .endfor
117
118 kernel-clean:
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/} \
124 ${CLEAN}
125
126 lint: ${LNFILES}
127 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \
128 tee -a linterrs
129
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
134 hack.So: Makefile
135 :> hack.c
136 ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
137 rm -f hack.c
138
139 # This rule stops ./assym.s in .depend from causing problems.
140 ./assym.s: assym.s
141
142 assym.s: $S/kern/genassym.sh genassym.o
143 NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
144
145 genassym.o: $S/$M/$M/genassym.c
146 ${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
147
148 ${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
149
150 kernel-depend: .depend
151 # The argument list can be very long, so use make -V and xargs to
152 # pass it to mkdep.
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}
157 rm -f .newdep
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}
162 rm -f .depend
163 mv .newdep .depend
164
165 _ILINKS= machine
166 .if ${MACHINE} != ${MACHINE_ARCH}
167 _ILINKS+= ${MACHINE_ARCH}
168 .endif
169
170 # Ensure that the link exists without depending on it when it exists.
171 .for _link in ${_ILINKS}
172 .if !exists(${.OBJDIR}/${_link})
173 ${SRCS}: ${_link}
174 .endif
175 .endfor
176
177 ${_ILINKS}:
178 @case ${.TARGET} in \
179 machine) \
180 path=${S}/${MACHINE}/include ;; \
181 ${MACHINE_ARCH}) \
182 path=${S}/${MACHINE_ARCH}/include ;; \
183 esac ; \
184 ${ECHO} ${.TARGET} "->" $$path ; \
185 ln -s $$path ${.TARGET}
186
187 # .depend needs include links so we remove them only together.
188 kernel-cleandepend:
189 rm -f .depend ${_ILINKS}
190
191 links:
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
198
199 kernel-tags:
200 @[ -f .depend ] || { echo "you must make depend first"; exit 1; }
201 sh $S/conf/systags.sh
202
203 kernel-install:
204 @if [ ! -f ${KERNEL_KO} ] ; then \
205 echo "You must build a kernel first." ; \
206 exit 1 ; \
207 fi
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} ; \
213 else \
214 if [ -d ${DESTDIR}${KODIR}.old ] ; then \
215 chflags -R noschg ${DESTDIR}${KODIR}.old ; \
216 rm -rf ${DESTDIR}${KODIR}.old ; \
217 fi ; \
218 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
219 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
220 fi
221 .endif
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}
226 .endif
227 .if defined(KERNEL_EXTRA_INSTALL)
228 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_EXTRA_INSTALL} ${DESTDIR}${KODIR}
229 .endif
230
231
232
233 kernel-reinstall:
234 @-chflags -R noschg ${DESTDIR}${KODIR}
235 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR}
236 .if defined(DEBUG) && !defined(INSTALL_NODEBUG)
237 ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO}.symbols ${DESTDIR}${KODIR}
238 .endif
239
240 config.o env.o hints.o vers.o vnode_if.o:
241 ${NORMAL_C}
242
243 config.ln env.ln hints.ln vers.ln vnode_if.ln:
244 ${NORMAL_LINT}
245
246 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
247 MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT}
248
249 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
250 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
251
252 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \
253 $S/kern/vnode_if.src
254 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
255 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
256 vnode_if_newproto.h:
257 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p
258 vnode_if_typedef.h:
259 ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q
260
261 # XXX strictly, everything depends on Makefile because changes to ${PROF}
262 # only appear there, but we don't handle that.
263
264 .include "kern.mk"
Cache object: 0a205a1455faefbd9073629045b3e4a7
|