vkernel - Fix installkernel target
[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
0955fd91 76genassym.o: $S/platform/$P/$M/genassym.c ${FORWARD_HEADERS_COOKIE}
40ec0564 77 ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
982b0507 78 $S/platform/$P/$M/genassym.c
edbe133c
SS
79
80${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
81
82# The argument list can be very long, use make -V and xargs to
83# pass it to mkdep.
84kernel-depend: assym.s ${BEFORE_DEPEND} \
85 ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
86 ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/}
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
95kernel-cleandepend:
96 rm -f .depend
97
98links:
99 egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
100 sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
101 ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
102 sort -u | comm -23 - dontlink | \
103 sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
104 sh makelinks && rm -f dontlink
105
106kernel-tags:
107 @[ -f .depend ] || { echo "you must make depend first"; exit 1; }
108 sh $S/conf/systags.sh
109 rm -f tags1
110 sed -e 's, ../, ,' tags > tags1
111
9200f41c 112# Note: when moving the existing kernel to .old, it is by default stripped
edbe133c
SS
113# so we do not have two full debug environments sitting in / eating up space.
114#
116b7e3c
MD
115# Also note the .old might be a file and not a directory, so we have to
116# remove it first.
117#
de45fd49 118kernel-install: kernel-installable
116b7e3c
MD
119 @if [ ! -f ${SELECTEDKERNEL} ]; then \
120 echo "You must build a kernel first."; \
121 exit 1; \
122 fi
123 @if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
124 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
edbe133c 125 fi
5b8f9b1e
MS
126# Skip this step for vkernels
127.if ${MACHINE_PLATFORM} != vkernel && ${MACHINE_PLATFORM} != vkernel64
116b7e3c 128 mkdir -p ${DESTDIR}${DESTKERNDIR}.old
5b8f9b1e 129.endif
3b25fbd4 130. if exists(${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME})
f2728908 131.ifndef NOFSCHG
3b25fbd4 132 -chflags noschg ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
f2728908 133.endif
9200f41c 134. ifdef NO_KERNEL_OLD_STRIP
116b7e3c 135 cp -p ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
9200f41c 136. else
116b7e3c 137 ${OBJCOPY} --strip-debug ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
9200f41c
SS
138. endif
139. endif
116b7e3c
MD
140 @if [ -f ${DESTDIR}${DESTKERNDIR} ]; then \
141 chflags noschg ${DESTDIR}${DESTKERNDIR}; \
142 rm -f ${DESTDIR}${DESTKERNDIR}; \
143 fi
3b25fbd4 144 mkdir -p ${DESTDIR}${DESTKERNDIR}
f2728908 145.ifdef NOFSCHG
edbe133c 146 ${INSTALL} -m 555 -o root -g wheel \
3b25fbd4 147 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c 148.else
edbe133c 149 ${INSTALL} -m 555 -o root -g wheel -fschg \
3b25fbd4 150 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
151.endif
152
de45fd49 153kernel-reinstall: kernel-installable
3b25fbd4 154 mkdir -p ${DESTDIR}${DESTKERNDIR}
edbe133c
SS
155.ifdef NOFSCHG
156 ${INSTALL} -m 555 -o root -g wheel \
3b25fbd4 157 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
158.else
159 ${INSTALL} -m 555 -o root -g wheel -fschg \
3b25fbd4 160 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
edbe133c
SS
161.endif
162
de45fd49 163kernel-installable:
b15e54dc 164 @if [ -f ${DESTDIR}/${DESTKERNNAME} ]; then \
f4e821f3
MD
165 echo "You need to make buildworld, installworld, and upgrade"; \
166 echo "before you can install a new kernel, because the"; \
167 echo "kernel and modules have moved to /boot"; \
168 exit 1; \
169 fi
5b8f9b1e
MS
170# Skip this step for vkernels
171.if ${MACHINE_PLATFORM} != vkernel && ${MACHINE_PLATFORM} != vkernel64
116b7e3c
MD
172 @if [ ! -f ${DESTDIR}/boot/dloader.rc ]; then \
173 echo "You need to install a new ${DESTDIR}/boot before you"; \
174 echo "can install a new kernel, kernels are now installed"; \
73a01884
MD
175 echo "into a subdirectory along with their modules."; \
176 echo "You can do this with a buildworld / installworld"; \
177 echo "sequence."; \
116b7e3c
MD
178 exit 1; \
179 fi
5b8f9b1e 180.endif
de45fd49
MD
181 @exit 0
182
edbe133c
SS
183.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES)
184all: modules
185depend: modules-depend
186clean: modules-clean
187cleandepend: modules-cleandepend
188cleandir: modules-cleandir
189tags: modules-tags
190install: modules-install
191reinstall: modules-reinstall
192.endif
193
194modules:
195 @mkdir -p ${.OBJDIR}
196 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
197 env ${MKMODULESENV} ${MAKE} -f Makefile.modules all
198
199modules-depend:
200 @mkdir -p ${.OBJDIR}
201 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
202 env ${MKMODULESENV} ${MAKE} -f Makefile.modules depend
203
204modules-clean:
205 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules clean
206
207modules-cleandepend:
208 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandepend
209
210# XXX huh?
211#modules-clobber: modules-clean
212# rm -rf ${MKMODULESENV}
213
214modules-cleandir:
215 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandir
216
217modules-tags:
218 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags
219
9200f41c 220# Note: when moving the existing modules to .old, they are by default stripped
edbe133c
SS
221# so we do not have two full debug environments sitting in / eating up space.
222#
116b7e3c
MD
223# We may have to remove deprecated kernel.old files before we can create
224# the kernel.old directory.
225#
8b91125a 226modules-install: kernel-installable
edbe133c 227.if !defined(NO_MODULES_OLD)
9200f41c 228. ifdef NO_KERNEL_OLD_STRIP
8a0aecbc 229 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
230 if [ -f "$$1" ]; then \
231 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
232 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
233 fi; \
234 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
235 for file; do \
236 cp -p $$file ${DESTDIR}${DESTKERNDIR}.old; \
237 done; \
9200f41c
SS
238 fi
239. else
8a0aecbc 240 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
241 if [ -f "$$1" ]; then \
242 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
243 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
244 fi; \
245 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
246 for file; do \
247 ${OBJCOPY} --strip-debug $$file ${DESTDIR}${DESTKERNDIR}.old/$${file##*/}; \
248 done; \
edbe133c 249 fi
9200f41c 250. endif
edbe133c 251.endif
116b7e3c
MD
252.if exists(${DESTDIR}/${OLDMODULESDIR})
253 rm -rf ${DESTDIR}/${OLDMODULESDIR} # remove deprecated
254.endif
255 mkdir -p ${DESTDIR}${DESTKERNDIR} # Ensure that the modules directory exists!
edbe133c
SS
256 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
257
258modules-reinstall:
116b7e3c 259 mkdir -p ${DESTDIR}/${DESTKERNDIR} # Ensure that the modules directory exists!
edbe133c
SS
260 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
261
262config.o:
263 ${NORMAL_C}
264
265ioconf.o:
266 ${NORMAL_C}
267
268vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
7e7d17cb 269 sh $S/conf/newvers.sh $S/..
edbe133c
SS
270
271# XXX strictly, everything depends on Makefile because changes to ${PROF}
272# only appear there, but we don't handle that.
273vers.o:
274 ${NORMAL_C}
275
276#vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
277# awk -f $S/tools/vnode_if.awk -- -c $S/kern/vnode_if.src
278#
279#vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
280# awk -f $S/tools/vnode_if.awk -- -h $S/kern/vnode_if.src
281#
282#vnode_if.o:
283# ${NORMAL_C}
284
285.include "$S/conf/bsd.kern.mk"