kernel: Add simpler make depend variant for kernel.
[dragonfly.git] / sys / conf / kern.post.mk
CommitLineData
493c0012 1#
edbe133c
SS
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 \
24b5009f 48 linterrs setdef[01].c setdefs.h tags \
edbe133c
SS
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/}
0bcd6c77 78 ${CC} -c ${CFLAGS:N-fno-common:N-flto: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/}
319f97f7 88.if defined(FASTER_DEPEND)
89.if exists(hack.So)
90 @cat ${SYSTEM_OBJS:M*\.o$:S/.o$/.d/} genassym.d > .depend || \
91 echo "There were missing deps"
92.endif
93.else
edbe133c
SS
94 rm -f .newdep
95 ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \
96 mkdep -a -f .newdep ${CFLAGS}
97 ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \
98 env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS}
99 rm -f .depend
100 mv -f .newdep .depend
319f97f7 101.endif
edbe133c
SS
102
103kernel-cleandepend:
319f97f7 104.if defined(FASTER_DEPEND)
105 rm -f *.d
106.endif
edbe133c
SS
107 rm -f .depend
108
edbe133c 109kernel-tags:
b3badcb0 110 @[ -f .depend ] || { echo "you must make depend first"; /usr/bin/false; }
edbe133c
SS
111 sh $S/conf/systags.sh
112 rm -f tags1
113 sed -e 's, ../, ,' tags > tags1
114
9200f41c 115# Note: when moving the existing kernel to .old, it is by default stripped
edbe133c
SS
116# so we do not have two full debug environments sitting in / eating up space.
117#
116b7e3c
MD
118# Also note the .old might be a file and not a directory, so we have to
119# remove it first.
120#
de45fd49 121kernel-install: kernel-installable
116b7e3c
MD
122 @if [ ! -f ${SELECTEDKERNEL} ]; then \
123 echo "You must build a kernel first."; \
b3badcb0 124 /usr/bin/false; \
116b7e3c
MD
125 fi
126 @if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
127 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
edbe133c 128 fi
116b7e3c 129 mkdir -p ${DESTDIR}${DESTKERNDIR}.old
1b48f394 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 138. endif
1b48f394 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"; \
b3badcb0 168 /usr/bin/false; \
f4e821f3 169 fi
5b8f9b1e 170# Skip this step for vkernels
ee5e79e3 171.if ${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."; \
b3badcb0 178 /usr/bin/false; \
116b7e3c 179 fi
5b8f9b1e 180.endif
de45fd49 181
edbe133c
SS
182.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES)
183all: modules
184depend: modules-depend
185clean: modules-clean
186cleandepend: modules-cleandepend
187cleandir: modules-cleandir
188tags: modules-tags
189install: modules-install
190reinstall: modules-reinstall
191.endif
192
193modules:
194 @mkdir -p ${.OBJDIR}
195 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
196 env ${MKMODULESENV} ${MAKE} -f Makefile.modules all
197
198modules-depend:
199 @mkdir -p ${.OBJDIR}
200 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
201 env ${MKMODULESENV} ${MAKE} -f Makefile.modules depend
202
203modules-clean:
204 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules clean
205
206modules-cleandepend:
207 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandepend
208
209# XXX huh?
210#modules-clobber: modules-clean
211# rm -rf ${MKMODULESENV}
212
213modules-cleandir:
214 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandir
215
216modules-tags:
217 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags
218
9200f41c 219# Note: when moving the existing modules to .old, they are by default stripped
edbe133c
SS
220# so we do not have two full debug environments sitting in / eating up space.
221#
116b7e3c
MD
222# We may have to remove deprecated kernel.old files before we can create
223# the kernel.old directory.
224#
8b91125a 225modules-install: kernel-installable
edbe133c 226.if !defined(NO_MODULES_OLD)
9200f41c 227. ifdef NO_KERNEL_OLD_STRIP
8a0aecbc 228 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
229 if [ -f "$$1" ]; then \
230 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
231 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
232 fi; \
233 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
234 for file; do \
235 cp -p $$file ${DESTDIR}${DESTKERNDIR}.old; \
236 done; \
9200f41c
SS
237 fi
238. else
8a0aecbc 239 set -- ${DESTDIR}${DESTKERNDIR}/*.ko; \
116b7e3c
MD
240 if [ -f "$$1" ]; then \
241 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then \
242 rm -f ${DESTDIR}${DESTKERNDIR}.old; \
243 fi; \
244 mkdir -p ${DESTDIR}${DESTKERNDIR}.old; \
245 for file; do \
246 ${OBJCOPY} --strip-debug $$file ${DESTDIR}${DESTKERNDIR}.old/$${file##*/}; \
247 done; \
edbe133c 248 fi
9200f41c 249. endif
0be6dc31
SW
250 if [ -f ${DESTDIR}${DESTKERNDIR}/initrd.img ]; then \
251 cp -p ${DESTDIR}${DESTKERNDIR}/initrd.img ${DESTDIR}${DESTKERNDIR}.old; \
252 fi
f3266596
FT
253 if [ -f ${DESTDIR}${DESTKERNDIR}/initrd.img.gz ]; then \
254 cp -p ${DESTDIR}${DESTKERNDIR}/initrd.img.gz ${DESTDIR}${DESTKERNDIR}.old; \
255 fi
edbe133c 256.endif
116b7e3c
MD
257.if exists(${DESTDIR}/${OLDMODULESDIR})
258 rm -rf ${DESTDIR}/${OLDMODULESDIR} # remove deprecated
259.endif
260 mkdir -p ${DESTDIR}${DESTKERNDIR} # Ensure that the modules directory exists!
edbe133c
SS
261 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
262
263modules-reinstall:
116b7e3c 264 mkdir -p ${DESTDIR}/${DESTKERNDIR} # Ensure that the modules directory exists!
edbe133c
SS
265 cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
266
267config.o:
58ea7d2c 268 ${NORMAL_C} ${WERROR}
edbe133c
SS
269
270ioconf.o:
58ea7d2c 271 ${NORMAL_C} ${WERROR}
edbe133c
SS
272
273vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
7e7d17cb 274 sh $S/conf/newvers.sh $S/..
edbe133c
SS
275
276# XXX strictly, everything depends on Makefile because changes to ${PROF}
277# only appear there, but we don't handle that.
278vers.o:
58ea7d2c 279 ${NORMAL_C} ${WERROR}
edbe133c 280
edbe133c 281.include "$S/conf/bsd.kern.mk"