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