boot system and buildkernel - Remove the thrice damned forth interpreter
[dragonfly.git] / sys / conf / kern.post.mk
1
2 # This Makefile covers the bottom part of the MI build instructions
3 #
4
5 .PHONY: all modules
6
7 all: ${KERNEL}.stripped
8
9 _MACHINE_FWD=   ${.OBJDIR}
10 .include "$S/conf/kern.fwd.mk"
11 .include "$S/conf/kern.paths.mk"
12
13 depend kernel-depend modules-depend: ${FORWARD_HEADERS_COOKIE}
14
15 depend: kernel-depend
16 clean:  kernel-clean
17 cleandepend:  kernel-cleandepend
18 tags:  kernel-tags
19 install: kernel-install
20 reinstall: kernel-reinstall
21
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
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
45 kernel-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} \
55 #         $S/platform/$P/$M/Locore.c ${CFILES} ioconf.c | \
56 #           grep -v 'struct/union .* never defined' | \
57 #           grep -v 'possible pointer alignment problem'
58
59 locore.o: $S/platform/$P/$M/locore.s assym.s
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.
65 hack.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
73 assym.s: $S/kern/genassym.sh genassym.o
74         sh $S/kern/genassym.sh genassym.o > ${.TARGET}
75
76 genassym.o: $S/platform/$P/$M/genassym.c ${FORWARD_HEADERS_COOKIE}
77         ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
78         $S/platform/$P/$M/genassym.c
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.
84 kernel-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
95 kernel-cleandepend:
96         rm -f .depend
97
98 links:
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
106 kernel-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
112 # Note: when moving the existing kernel to .old, it is by default stripped
113 # so we do not have two full debug environments sitting in / eating up space.
114 #
115 # Also note the .old might be a file and not a directory, so we have to
116 # remove it first.
117 #
118 kernel-install: kernel-installable
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;             \
125         fi
126         mkdir -p ${DESTDIR}${DESTKERNDIR}.old
127 .  if exists(${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME})
128 .ifndef NOFSCHG
129         -chflags noschg ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
130 .endif
131 .    ifdef NO_KERNEL_OLD_STRIP
132         cp -p ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
133 .    else
134         ${OBJCOPY} --strip-debug ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME} ${DESTDIR}${DESTKERNDIR}.old/${DESTKERNNAME}
135 .    endif
136 .  endif
137         @if [ -f ${DESTDIR}${DESTKERNDIR} ]; then               \
138                 chflags noschg ${DESTDIR}${DESTKERNDIR};        \
139                 rm -f ${DESTDIR}${DESTKERNDIR};                 \
140         fi
141         mkdir -p ${DESTDIR}${DESTKERNDIR}
142 .ifdef NOFSCHG
143         ${INSTALL} -m 555 -o root -g wheel \
144                 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
145 .else
146         ${INSTALL} -m 555 -o root -g wheel -fschg \
147                 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
148 .endif
149
150 kernel-reinstall: kernel-installable
151         mkdir -p ${DESTDIR}${DESTKERNDIR}
152 .ifdef NOFSCHG
153         ${INSTALL} -m 555 -o root -g wheel \
154                 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
155 .else
156         ${INSTALL} -m 555 -o root -g wheel -fschg \
157                 ${SELECTEDKERNEL} ${DESTDIR}${DESTKERNDIR}/${DESTKERNNAME}
158 .endif
159
160 kernel-installable:
161         @if [ -f ${DESTDIR}/${DESTKERNNAME} ]; then \
162                 echo "You need to make buildworld, installworld, and upgrade"; \
163                 echo "before you can install a new kernel, because the"; \
164                 echo "kernel and modules have moved to /boot"; \
165                 exit 1; \
166         fi
167         @if [ ! -f ${DESTDIR}/boot/dloader.rc ]; then \
168                 echo "You need to install a new ${DESTDIR}/boot before you"; \
169                 echo "can install a new kernel, kernels are now installed"; \
170                 echo "into a subdirectory along with their modules"; \
171                 exit 1; \
172         fi
173         @exit 0
174
175 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES)
176 all:    modules
177 depend: modules-depend
178 clean:  modules-clean
179 cleandepend:  modules-cleandepend
180 cleandir:  modules-cleandir
181 tags:  modules-tags
182 install: modules-install
183 reinstall: modules-reinstall
184 .endif
185
186 modules:
187         @mkdir -p ${.OBJDIR}
188         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
189             env ${MKMODULESENV} ${MAKE} -f Makefile.modules all
190
191 modules-depend:
192         @mkdir -p ${.OBJDIR}
193         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules obj ; \
194             env ${MKMODULESENV} ${MAKE} -f Makefile.modules depend
195
196 modules-clean:
197         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules clean
198
199 modules-cleandepend:
200         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandepend
201
202 # XXX huh?
203 #modules-clobber:       modules-clean
204 #       rm -rf ${MKMODULESENV}
205
206 modules-cleandir:
207         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules cleandir
208
209 modules-tags:
210         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags
211
212 # Note: when moving the existing modules to .old, they are by default stripped
213 # so we do not have two full debug environments sitting in / eating up space.
214 #
215 # We may have to remove deprecated kernel.old files before we can create
216 # the kernel.old directory.
217 #
218 modules-install:
219 .if !defined(NO_MODULES_OLD)
220 .  ifdef NO_KERNEL_OLD_STRIP
221         set -- ${DESTDIR}${DESTKERNDIR}/*;                      \
222         if [ -f "$$1" ]; then                                   \
223                 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then    \
224                     rm -f ${DESTDIR}${DESTKERNDIR}.old;         \
225                 fi;                                             \
226                 mkdir -p ${DESTDIR}${DESTKERNDIR}.old;          \
227                 for file; do                                    \
228                 cp -p $$file ${DESTDIR}${DESTKERNDIR}.old;      \
229                 done;                                           \
230         fi
231 .  else
232         set -- ${DESTDIR}${DESTKERNDIR}/*;                      \
233         if [ -f "$$1" ]; then                                   \
234                 if [ -f ${DESTDIR}${DESTKERNDIR}.old ]; then    \
235                     rm -f ${DESTDIR}${DESTKERNDIR}.old;         \
236                 fi;                                             \
237                 mkdir -p ${DESTDIR}${DESTKERNDIR}.old;          \
238                 for file; do                                    \
239                 ${OBJCOPY} --strip-debug $$file ${DESTDIR}${DESTKERNDIR}.old/$${file##*/}; \
240                 done;                                           \
241         fi
242 .  endif
243 .endif
244 .if exists(${DESTDIR}/${OLDMODULESDIR})
245         rm -rf ${DESTDIR}/${OLDMODULESDIR} # remove deprecated
246 .endif
247         mkdir -p ${DESTDIR}${DESTKERNDIR} # Ensure that the modules directory exists!
248         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
249
250 modules-reinstall:
251         mkdir -p ${DESTDIR}/${DESTKERNDIR} # Ensure that the modules directory exists!
252         cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install
253
254 config.o:
255         ${NORMAL_C}
256
257 ioconf.o:
258         ${NORMAL_C}
259
260 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
261         sh $S/conf/newvers.sh $S/..
262
263 # XXX strictly, everything depends on Makefile because changes to ${PROF}
264 # only appear there, but we don't handle that.
265 vers.o:
266         ${NORMAL_C}
267
268 #vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
269 #       awk -f $S/tools/vnode_if.awk -- -c $S/kern/vnode_if.src
270 #
271 #vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
272 #       awk -f $S/tools/vnode_if.awk -- -h $S/kern/vnode_if.src
273 #
274 #vnode_if.o:
275 #       ${NORMAL_C}
276
277 .include "$S/conf/bsd.kern.mk"