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