Fix buildkernel without -j.
[dragonfly.git] / sys / conf / kern.post.mk
CommitLineData
edbe133c
SS
1#
2# This Makefile covers the bottom part of the MI build instructions
3#
4
5.PHONY: all modules
6
7all: ${KERNEL}.stripped
8
a7f2f51f 9_MACHINE_FWD= ${.OBJDIR}
49da4741 10.include "$S/conf/kern.fwd.mk"
3b25fbd4 11.include "$S/conf/kern.paths.mk"
49da4741 12
703521da 13depend kernel-depend modules-depend: ${FORWARD_HEADERS_COOKIE}
a7f2f51f 14
edbe133c
SS
15depend: kernel-depend
16clean: kernel-clean
17cleandepend: kernel-cleandepend
18tags: kernel-tags
19install: kernel-install
20reinstall: kernel-reinstall
21
76f43533
MD
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
edbe133c
SS
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 eddep errs \
47 ${KERNEL} ${KERNEL}.debug ${KERNEL}.nodebug ${KERNEL}.stripped \
48 linterrs makelinks setdef[01].c setdefs.h tags \
49 vers.c vnode_if.c vnode_if.h \
50 ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
51 ${CLEAN}
52
53#lint: /tmp
54# @lint -hbxn -DGENERIC -Dvolatile= ${COPTS} \
0955fd91 55# $S/platform/$P/$M/Locore.c ${CFILES} ioconf.c | \
edbe133c
SS
56# grep -v 'struct/union .* never defined' | \
57# grep -v 'possible pointer alignment problem'
58
0955fd91 59locore.o: $S/platform/$P/$M/locore.s assym.s
edbe133c
SS
60 ${NORMAL_S}
61
62# This is a hack. BFD "optimizes" away dynamic mode if there are no
63# dynamic references. We could probably do a '-Bforcedynamic' mode like
64# in the a.out ld. For now, this works.
65hack.So: Makefile
66 touch hack.c
67 ${CC} -shared -nostdlib hack.c -o hack.So
68 rm -f hack.c
69
70# this rule stops ./assym.s in .depend from causing problems
71./assym.s: assym.s
72
73assym.s: $S/kern/genassym.sh genassym.o
74 sh $S/kern/genassym.sh genassym.o > ${.TARGET}
75
82011fa5
SW
76genassym.o: $S/platform/$P/$M/genassym.c ${FORWARD_HEADERS_COOKIE} \
77 ${MFILES:T:S/.m$/.h/}
40ec0564 78 ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
982b0507 79 $S/platform/$P/$M/genassym.c
edbe133c
SS
80
81${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
82
83# The argument list can be very long, use make -V and xargs to
84# pass it to mkdep.
85kernel-depend: assym.s ${BEFORE_DEPEND} \
86 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
87 ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/}
88 rm -f .newdep
89 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \
90 mkdep -a -f .newdep ${CFLAGS}
91 ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \
92 env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS}
93 rm -f .depend
94 mv -f .newdep .depend
95
96kernel-cleandepend:
97 rm -f .depend
98
99links:
100 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
101 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
102 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
103 sort -u | comm -23 - dontlink | \
104 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
105 sh makelinks && rm -f dontlink
106
107kernel-tags:
108 @[ -f .depend ] || { echo "you must make depend first"; exit 1; }
109 sh $S/conf/systags.sh
110 rm -f tags1
111 sed -e 's, ../, ,' tags > tags1
112
9200f41c 113# Note: when moving the existing kernel to .old, it is by default stripped
edbe133c
SS
114# so we do not have two full debug environments sitting in / eating up space.
115#
116b7e3c
MD
116# Also note the .old might be a file and not a directory, so we have to
117# remove it first.
118#
de45fd49 119kernel-install: kernel-installable
116b7e3c
MD
120 @if [ ! -f ${SELECTEDKERNEL} ]; then \
121 echo "You must build a kernel first."; \
122 exit 1; \
123 fi
124 @if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
125 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
edbe133c 126 fi
116b7e3c 127 mkdir -p ${DESTDIR}${DESTKERNDIR}.old
1b48f394 128.if exists(${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME})
f2728908 129.ifndef NOFSCHG
3b25fbd4 130 -chflags noschg ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
f2728908 131.endif
9200f41c 132. ifdef NO_KERNEL_OLD_STRIP
116b7e3c 133 cp -p ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
9200f41c 134. else
116b7e3c 135 ${OBJCOPY} --strip-debug ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
9200f41c 136. endif
1b48f394 137.endif
116b7e3c
MD
138 @if [ -f ${DESTDIR}${DESTKERNDIR} ]; then \
139 chflags noschg ${DESTDIR}${DESTKERNDIR}; \
140 rm -f ${DESTDIR}${DESTKERNDIR}; \
141 fi
3b25fbd4 142 mkdir -p ${DESTDIR}${DESTKERNDIR}
f2728908 143.ifdef NOFSCHG
edbe133c 144 ${INSTALL} -m 555 -o root -g wheel \
3b25fbd4 145 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c 146.else
edbe133c 147 ${INSTALL} -m 555 -o root -g wheel -fschg \
3b25fbd4 148 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
149.endif
150
de45fd49 151kernel-reinstall: kernel-installable
3b25fbd4 152 mkdir -p ${DESTDIR}${DESTKERNDIR}
edbe133c
SS
153.ifdef NOFSCHG
154 ${INSTALL} -m 555 -o root -g wheel \
3b25fbd4 155 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
156.else
157 ${INSTALL} -m 555 -o root -g wheel -fschg \
3b25fbd4 158 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
159.endif
160
de45fd49 161kernel-installable:
b15e54dc 162 @if [ -f ${DESTDIR}/${DESTKERNNAME} ]; then \
f4e821f3
MD
163 echo "You need to make buildworld, installworld, and upgrade"; \
164 echo "before you can install a new kernel, because the"; \
165 echo "kernel and modules have moved to /boot"; \
166 exit 1; \
167 fi
5b8f9b1e
MS
168# Skip this step for vkernels
169.if ${MACHINE_PLATFORM} != vkernel && ${MACHINE_PLATFORM} != vkernel64
116b7e3c
MD
170 @if [ ! -f ${DESTDIR}/boot/dloader.rc ]; then \
171 echo "You need to install a new ${DESTDIR}/boot before you"; \
172 echo "can install a new kernel, kernels are now installed"; \
73a01884
MD
173 echo "into a subdirectory along with their modules."; \
174 echo "You can do this with a buildworld / installworld"; \
175 echo "sequence."; \
116b7e3c
MD
176 exit 1; \
177 fi
5b8f9b1e 178.endif
de45fd49
MD
179 @exit 0
180
edbe133c
SS
181.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES)
182all: modules
183depend: modules-depend
184clean: modules-clean
185cleandepend: modules-cleandepend
186cleandir: modules-cleandir
187tags: modules-tags
188install: modules-install
189reinstall: modules-reinstall
190.endif
191
192modules:
193 @mkdir -p ${.OBJDIR}
194 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
195 env ${MKMODULESENV} ${MAKE} -f Makefile.modules all
196
197modules-depend:
198 @mkdir -p ${.OBJDIR}
199 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
200 env ${MKMODULESENV} ${MAKE} -f Makefile.modules depend
201
202modules-clean:
203 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules clean
204
205modules-cleandepend:
206 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandepend
207
208# XXX huh?
209#modules-clobber: modules-clean
210# rm -rf ${MKMODULESENV}
211
212modules-cleandir:
213 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandir
214
215modules-tags:
216 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags
217
9200f41c 218# Note: when moving the existing modules to .old, they are by default stripped
edbe133c
SS
219# so we do not have two full debug environments sitting in / eating up space.
220#
116b7e3c
MD
221# We may have to remove deprecated kernel.old files before we can create
222# the kernel.old directory.
223#
8b91125a 224modules-install: kernel-installable
edbe133c 225.if !defined(NO_MODULES_OLD)
9200f41c 226. ifdef NO_KERNEL_OLD_STRIP
8a0aecbc 227 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
228 if [ -f "$$1" ]; then \
229 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
230 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
231 fi; \
232 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
233 for file; do \
234 cp -p $$file ${DESTDIR}${DESTKERNDIR}.old; \
235 done; \
9200f41c
SS
236 fi
237. else
8a0aecbc 238 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
239 if [ -f "$$1" ]; then \
240 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
241 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
242 fi; \
243 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
244 for file; do \
245 ${OBJCOPY} --strip-debug $$file ${DESTDIR}${DESTKERNDIR}.old/$${file##*/}; \
246 done; \
edbe133c 247 fi
9200f41c 248. endif
edbe133c 249.endif
116b7e3c
MD
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!
edbe133c
SS
254 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
255
256modules-reinstall:
116b7e3c 257 mkdir -p ${DESTDIR}/${DESTKERNDIR} # Ensure that the modules directory exists!
edbe133c
SS
258 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
259
260config.o:
261 ${NORMAL_C}
262
263ioconf.o:
264 ${NORMAL_C}
265
266vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
7e7d17cb 267 sh $S/conf/newvers.sh $S/..
edbe133c
SS
268
269# XXX strictly, everything depends on Makefile because changes to ${PROF}
270# only appear there, but we don't handle that.
271vers.o:
272 ${NORMAL_C}
273
274#vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
275# awk -f $S/tools/vnode_if.awk -- -c $S/kern/vnode_if.src
276#
277#vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
278# awk -f $S/tools/vnode_if.awk -- -h $S/kern/vnode_if.src
279#
280#vnode_if.o:
281# ${NORMAL_C}
282
283.include "$S/conf/bsd.kern.mk"