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