Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / conf / Makefile.i386
1 # Makefile.i386 -- with config changes.
2 # Copyright 1990 W. Jolitz
3 #       from: @(#)Makefile.i386 7.1 5/10/91
4 # $FreeBSD: src/sys/conf/Makefile.i386,v 1.179.2.16 2002/11/18 11:26:49 ru Exp $
5 #
6 # Makefile for FreeBSD
7 #
8 # This makefile is constructed from a machine description:
9 #       config machineid
10 # Most changes should be made in the machine description
11 #       /sys/i386/conf/``machineid''
12 # after which you should do
13 #        config machineid
14 # Generic makefile changes should be made in
15 #       /sys/conf/Makefile.i386
16 # after which config should be rerun for all machines.
17 #
18
19 # Which version of config(8) is required.
20 %VERSREQ=       400019
21
22 # Can be overridden by makeoptions or /etc/make.conf
23 KERNEL?=        kernel
24 STD8X16FONT?=   iso
25
26 .if !defined(S)
27 .if exists(./@/.)
28 S=      ./@
29 .else
30 S=      ../..
31 .endif
32 .endif
33 M=      ${MACHINE_ARCH}
34
35 SIZE?=          size
36 OBJCOPY?=       objcopy
37
38 COPTFLAGS?=-O -pipe
39 .if !defined(NO_CPU_COPTFLAGS)
40 COPTFLAGS+= ${_CPUCFLAGS}
41 .endif
42 INCLUDES= -nostdinc -I- -I. -I$S
43 # This hack is to allow kernel compiles to succeed on machines w/out srcdist
44 .if exists($S/../include)
45 INCLUDES+= -I$S/../include
46 .else
47 INCLUDES+= -I/usr/include
48 .endif
49
50 # This hack lets us use the ipfilter code without spamming a new
51 # include path into 100+ source files.
52 INCLUDES+= -I$S/contrib/ipfilter
53
54 COPTS=  ${INCLUDES} ${IDENT} -D_KERNEL -include opt_global.h
55 CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
56
57 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
58 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
59
60 DEFINED_PROF=   ${PROF}
61 .if defined(PROF)
62 CFLAGS+=        -malign-functions=4
63 .if ${PROFLEVEL} >= 2
64 IDENT+= -DGPROF4 -DGUPROF
65 PROF+=  -mprofiler-epilogue
66 .endif
67 .endif
68
69 # Put configuration-specific C flags last (except for ${PROF}) so that they
70 # can override the others.
71 CFLAGS+=        ${CONF_CFLAGS}
72
73 NORMAL_C= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
74 NORMAL_C_C= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
75 NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${.IMPSRC}
76 PROFILE_C= ${CC} -c ${CFLAGS} ${.IMPSRC}
77
78 GEN_CFILES= $S/$M/$M/genassym.c
79 # setdef0.c and setdef1.c are intentionally
80 # omitted from SYSTEM_CFILES.  They include setdefs.h, a header which
81 # is generated from all of ${OBJS}.  We don't want to have to compile
82 # everything just to do a make depend.
83 SYSTEM_CFILES= ioconf.c vnode_if.c config.c
84 SYSTEM_SFILES= $S/$M/$M/locore.s
85 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
86 SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o config.o \
87         setdef1.o hack.So
88 SYSTEM_LD= @${LD} -Bdynamic -T $S/conf/ldscript.$M \
89         -export-dynamic -dynamic-linker /red/herring \
90         -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
91 SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
92         ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
93 SYSTEM_DEP+= $S/conf/ldscript.$M
94
95 %BEFORE_DEPEND
96
97 %OBJS
98
99 %CFILES
100
101 %SFILES
102
103 %MFILES
104
105 %CLEAN
106
107 .PHONY: all modules
108
109 all: ${KERNEL}
110
111 depend: kernel-depend
112 clean:  kernel-clean
113 cleandepend:  kernel-cleandepend
114 tags:  kernel-tags
115 install install.debug: kernel-install
116 reinstall reinstall.debug: kernel-reinstall
117
118 .if !defined(DEBUG)
119 FULLKERNEL=     ${KERNEL}
120 .else
121 FULLKERNEL=     ${KERNEL}.debug
122 ${KERNEL}: ${FULLKERNEL}
123         ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL}
124 .endif
125
126 ${FULLKERNEL}: ${SYSTEM_DEP} vers.o
127         @rm -f ${.TARGET}
128         @echo linking ${.TARGET}
129         ${SYSTEM_LD}
130         ${SYSTEM_LD_TAIL}
131
132 .if !exists(.depend)
133 ${SYSTEM_OBJS}: vnode_if.h ${BEFORE_DEPEND:M*.h}
134 .endif
135
136 kernel-clean:
137         rm -f *.o *.so *.So *.ko *.s eddep errs \
138               ${FULLKERNEL} ${KERNEL} linterrs makelinks \
139               setdef[01].c setdefs.h tags \
140               vers.c vnode_if.c vnode_if.h ${CLEAN}
141
142 #lint: /tmp
143 #       @lint -hbxn -DGENERIC -Dvolatile= ${COPTS} \
144 #         $S/$M/$M/Locore.c ${CFILES} ioconf.c | \
145 #           grep -v 'struct/union .* never defined' | \
146 #           grep -v 'possible pointer alignment problem'
147
148 locore.o: $S/$M/$M/locore.s assym.s
149         ${NORMAL_S}
150
151 # This is a hack.  BFD "optimizes" away dynamic mode if there are no
152 # dynamic references.  We could probably do a '-Bforcedynamic' mode like
153 # in the a.out ld.  For now, this works.
154 hack.So: Makefile
155         touch hack.c
156         ${CC} -shared -nostdlib hack.c -o hack.So
157         rm -f hack.c
158
159 .ORDER: setdefs.h setdef0.c setdef1.c
160
161 setdef0.o: setdef0.c setdefs.h
162         ${NORMAL_C}
163
164 setdef1.o: setdef1.c setdefs.h
165         ${NORMAL_C}
166
167 setdef0.c setdef1.c setdefs.h: ${OBJS}
168         @gensetdefs ${OBJS}
169
170 # this rule stops ./assym.s in .depend from causing problems
171 ./assym.s: assym.s
172
173 assym.s: $S/kern/genassym.sh genassym.o
174         sh $S/kern/genassym.sh genassym.o > ${.TARGET}
175
176 genassym.o: $S/$M/$M/genassym.c
177         ${CC} -c ${CFLAGS} $S/$M/$M/genassym.c
178
179 ${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
180
181 # The argument list can be very long, use make -V and xargs to
182 # pass it to mkdep.
183 kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \
184             ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} ${SYSTEM_SFILES}
185         rm -f .newdep
186         ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \
187                 mkdep -a -f .newdep ${CFLAGS}
188         ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \
189             env MKDEP_CPP="${CC} -E" mkdep -a -f .newdep ${ASM_CFLAGS}
190         rm -f .depend
191         mv -f .newdep .depend
192
193 kernel-cleandepend:
194         rm -f .depend
195
196 links:
197         egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
198           sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
199         ${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
200           sort -u | comm -23 - dontlink | \
201           sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
202         sh makelinks && rm -f dontlink
203
204 kernel-tags:
205         @[ -f .depend ] || { echo "you must make depend first"; exit 1; }
206         sh $S/conf/systags.sh
207         rm -f tags1
208         sed -e 's,      ../,    ,' tags > tags1
209
210 kernel-install kernel-install.debug:
211         @if [ ! -f ${KERNEL}${.TARGET:S/kernel-install//} ] ; then \
212                 echo "You must build a kernel first." ; \
213                 exit 1 ; \
214         fi
215 .if exists(${DESTDIR}/${KERNEL})
216         -chflags noschg ${DESTDIR}/${KERNEL}
217         mv ${DESTDIR}/${KERNEL} ${DESTDIR}/${KERNEL}.old
218 .endif
219         ${INSTALL} -m 555 -o root -g wheel -fschg \
220                 ${KERNEL}${.TARGET:S/kernel-install//} ${DESTDIR}/${KERNEL}
221
222 kernel-reinstall kernel-reinstall.debug:
223         ${INSTALL} -m 555 -o root -g wheel -fschg \
224                 ${KERNEL}${.TARGET:S/kernel-reinstall//} ${DESTDIR}/${KERNEL}
225
226 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
227 all:    modules
228 depend: modules-depend
229 clean:  modules-clean
230 cleandepend:  modules-cleandepend
231 cleandir:  modules-cleandir
232 tags:  modules-tags
233 install install.debug: modules-install
234 reinstall reinstall.debug: modules-reinstall
235 .endif
236
237 MKMODULESENV=   MAKEOBJDIRPREFIX=${.OBJDIR}/modules
238 .if defined(MODULES_OVERRIDE)
239 MKMODULESENV+=  MODULES_OVERRIDE="${MODULES_OVERRIDE}"
240 .endif
241 .if defined(DEBUG)
242 MKMODULESENV+=  DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}"
243 .endif
244 MKMODULESENV+= MACHINE=i386
245
246 modules:
247         @mkdir -p ${.OBJDIR}/modules
248         cd $S/modules ; env ${MKMODULESENV} ${MAKE} obj ; \
249             env ${MKMODULESENV} ${MAKE} all
250
251 modules-depend:
252         @mkdir -p ${.OBJDIR}/modules
253         cd $S/modules ; env ${MKMODULESENV} ${MAKE} obj ; \
254             env ${MKMODULESENV} ${MAKE} depend
255
256 modules-clean:
257         cd $S/modules ; env ${MKMODULESENV} ${MAKE} clean
258
259 modules-cleandepend:
260         cd $S/modules ; env ${MKMODULESENV} ${MAKE} cleandepend
261
262 modules-clobber:        modules-clean
263         rm -rf ${MKMODULESENV}
264
265 modules-cleandir:
266         cd $S/modules ; env ${MKMODULESENV} ${MAKE} cleandir
267
268 modules-tags:
269         cd $S/modules ; env ${MKMODULESENV} ${MAKE} tags
270
271 modules-install modules-install.debug:
272 .if !defined(NO_MODULES_OLD)
273         if [ -d ${DESTDIR}/modules -a -n "`ls ${DESTDIR}/modules`" ]; then \
274                 mkdir -p ${DESTDIR}/modules.old; \
275                 cp -p ${DESTDIR}/modules/* ${DESTDIR}/modules.old; \
276         fi;
277 .endif
278         cd $S/modules ; env ${MKMODULESENV} ${MAKE} install
279
280 modules-reinstall modules-reinstall.debug:
281         cd $S/modules ; env ${MKMODULESENV} ${MAKE} install
282
283 config.o:
284         ${NORMAL_C}
285
286 ioconf.o:
287         ${NORMAL_C}
288
289 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
290         sh $S/conf/newvers.sh ${KERN_IDENT} ${IDENT}
291
292 # XXX strictly, everything depends on Makefile because changes to ${PROF}
293 # only appear there, but we don't handle that.
294 vers.o:
295         ${NORMAL_C}
296
297 vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src
298         perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src
299
300 vnode_if.h: $S/kern/vnode_if.pl $S/kern/vnode_if.src
301         perl5 $S/kern/vnode_if.pl -h $S/kern/vnode_if.src
302
303 vnode_if.o:
304         ${NORMAL_C}
305
306 # Commented out for now pending a better solution.
307 # How do we pick up compiler version specific flags??
308 #.if exists($S/../share/mk)
309 #.include "$S/../share/mk/bsd.kern.mk"
310 #.else
311 .include <bsd.kern.mk>
312 #.endif
313
314 %RULES
315
316 # DO NOT DELETE THIS LINE -- make depend uses it