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