xref: /openbsd/sys/arch/i386/conf/Makefile.i386 (revision 8529ddd3)
1#	$OpenBSD: Makefile.i386,v 1.92 2015/01/13 01:12:49 deraadt Exp $
2
3# For instructions on building kernels consult the config(8) and options(4)
4# manual pages.
5#
6# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
7#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
8# DEBUG is set to -g by config if debugging is requested (config -g).
9# PROF is set to -pg by config if profiling is requested (config -p).
10
11.include <bsd.own.mk>
12
13SIZE?=	size
14STRIP?=	strip
15
16# source tree is located via $S relative to the compilation directory
17.ifndef S
18S!=	cd ../../../..; pwd
19.endif
20
21_machdir?=	$S/arch/${_mach}
22_archdir?=	$S/arch/${_arch}
23
24INCLUDES=	-nostdinc -I$S -I. -I$S/arch
25CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -MD -MP
26CWARNFLAGS=	-Werror -Wall -Wimplicit-function-declaration \
27		-Wno-main -Wno-uninitialized \
28		-Wframe-larger-than=2047
29
30CMACHFLAGS=
31CMACHFLAGS+=	-fno-builtin-printf -fno-builtin-snprintf \
32		-fno-builtin-vsnprintf -fno-builtin-log \
33		-fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
34.if ${IDENT:M-DNO_PROPOLICE}
35CMACHFLAGS+=	-fno-stack-protector
36.endif
37
38COPTS?=		-O2
39CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
40AFLAGS=		-D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
41LINKFLAGS=	-Ttext 0xD0200120 -e start -N --warn-common -nopie
42
43.if ${MACHINE} == "amd64"
44CFLAGS+=	-m32
45AFLAGS+=	-m32
46LINKFLAGS+= -melf_i386_obsd
47.endif
48
49.if ${IDENT:M-DDDB_STRUCT}
50DB_STRUCTINFO=	db_structinfo.h
51.else
52DB_STRUCTINFO=
53.endif
54
55HOSTCC?=	${CC}
56HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
57HOSTED_CFLAGS=	${CFLAGS}
58HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
59
60NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -c $<
61NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
62NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
63
64%OBJS
65
66%CFILES
67
68%SFILES
69
70# load lines for config "xxx" will be emitted as:
71# xxx: ${SYSTEM_DEP} swapxxx.o
72#	${SYSTEM_LD_HEAD}
73#	${SYSTEM_LD} swapxxx.o
74#	${SYSTEM_LD_TAIL}
75SYSTEM_HEAD=	locore.o param.o ioconf.o
76SYSTEM_OBJ=	${SYSTEM_HEAD} ${OBJS}
77SYSTEM_DEP=	Makefile ${SYSTEM_OBJ}
78SYSTEM_LD_HEAD=	@rm -f $@
79SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
80		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} vers.o ${OBJS}
81SYSTEM_LD_TAIL=	@${SIZE} $@; chmod 755 $@
82
83DEBUG?=
84.if ${DEBUG} == "-g"
85LINKFLAGS+=	-X
86STRIPFLAGS=	-g -x
87SYSTEM_LD_TAIL+=; \
88		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
89		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
90		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
91.else
92LINKFLAGS+=	-S -x
93.endif
94
95%LOAD
96
97# cc's -MD puts the source and output paths in the dependency file;
98# since those are temp files here we need to fix it up.  It also
99# puts the file in /tmp, so we use -MF to put it in the current
100# directory as assym.P and then generate assym.d from it with a
101# good target name
102assym.h: $S/kern/genassym.sh Makefile \
103	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
104	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
105	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp
106	sed '1s/.*/assym.h: \\/' assym.P > assym.d
107	sort -u assym.h.tmp > assym.h
108
109param.c: $S/conf/param.c
110	rm -f param.c
111	cp $S/conf/param.c .
112
113param.o: param.c Makefile
114	${NORMAL_C}
115
116mcount.o: $S/lib/libkern/mcount.c Makefile
117	${NORMAL_C_NOP}
118
119ioconf.o: ioconf.c
120	${NORMAL_C}
121
122vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
123	sh $S/conf/newvers.sh
124	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
125
126clean::
127	rm -f eddep *bsd *bsd.gdb tags *.[dio] [a-z]*.s \
128	    [Ee]rrs linterrs assym.h ${DB_STRUCTINFO}
129
130lint:
131	@lint -hbxncez -Dvolatile= ${CPPFLAGS} -UKGDB \
132	    ${CFILES} ioconf.c param.c | \
133	    grep -v 'static function .* unused'
134
135depend:
136	@touch $@
137
138tags:
139	@echo "see $S/kern/Makefile for tags"
140
141db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl
142	${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c
143	objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@
144	rm -f db_structinfo.o
145
146locore.o: ${_machdir}/${_mach}/locore.s assym.h
147in_cksum.o mptramp.o kvm86call.o acpi_wakecode.o: assym.h
148
149# The install target can be redefined by putting a
150# install-kernel-${MACHINE_NAME} target into /etc/mk.conf
151MACHINE_NAME!=  uname -n
152install: install-kernel-${MACHINE_NAME}
153.if !target(install-kernel-${MACHINE_NAME}})
154install-kernel-${MACHINE_NAME}:
155	cmp -s bsd /bsd || ln -f /bsd /obsd
156	cp bsd /nbsd
157	mv /nbsd /bsd
158.endif
159
160# pull in the dependency information
161.if !empty(DB_STRUCTINFO) && !exists(${DB_STRUCTINFO})
162 ${SYSTEM_OBJ}: ${DB_STRUCTINFO}
163.endif
164.ifnmake clean
165. for o in ${SYSTEM_OBJ} assym.h ${DB_STRUCTINFO}
166.  if exists(${o:R}.d)
167.   include "${o:R}.d"
168.  elif exists($o)
169    .PHONY: $o
170.  endif
171. endfor
172.endif
173
174%RULES
175