xref: /openbsd/sys/arch/i386/conf/Makefile.i386 (revision 09467b48)
1#	$OpenBSD: Makefile.i386,v 1.138 2020/06/08 04:47:58 jsg 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?=	ctfstrip
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${.OBJDIR} -I$S/arch \
25		-I$S/dev/pci/drm/include \
26		-I$S/dev/pci/drm/include/uapi \
27		-I$S/dev/pci/drm/i915
28CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -MD -MP
29CWARNFLAGS=	-Werror -Wall -Wimplicit-function-declaration \
30		-Wno-uninitialized -Wno-pointer-sign \
31		-Wframe-larger-than=2047
32
33CMACHFLAGS=
34CMACHFLAGS+=	-ffreestanding ${NOPIE_FLAGS}
35SORTR=		sort -R
36.if ${IDENT:M-DNO_PROPOLICE}
37CMACHFLAGS+=	-fno-stack-protector
38.endif
39.if ${IDENT:M-DSMALL_KERNEL}
40SORTR=		cat
41COPTS?=		-Oz -mtune=i486 -mno-retpoline
42.elif ${COMPILER_VERSION:Mclang}
43CMACHFLAGS+=	-mretpoline
44.endif
45.if ${COMPILER_VERSION:Mclang}
46NO_INTEGR_AS=	-no-integrated-as
47CWARNFLAGS+=	-Wno-address-of-packed-member -Wno-constant-conversion
48.endif
49
50DEBUG?=		-g
51COPTS?=		-O2
52CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
53AFLAGS=		-D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
54LINKFLAGS=	-T ld.script -X --warn-common -nopie
55
56.if ${MACHINE} == "amd64"
57CFLAGS+=	-m32
58AFLAGS+=	-m32
59LDFLAGS=	-melf_i386
60LINKFLAGS+=	${LDFLAGS}
61.endif
62
63HOSTCC?=	${CC}
64HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
65HOSTED_CFLAGS=	${CFLAGS}
66HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
67
68NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -c $<
69NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
70NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c $<
71
72%OBJS
73
74%CFILES
75
76%SFILES
77
78# load lines for config "xxx" will be emitted as:
79# xxx: ${SYSTEM_DEP} swapxxx.o
80#	${SYSTEM_LD_HEAD}
81#	${SYSTEM_LD} swapxxx.o
82#	${SYSTEM_LD_TAIL}
83SYSTEM_HEAD=	locore0.o gap.o
84SYSTEM_OBJ=	${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
85SYSTEM_DEP=	Makefile ${SYSTEM_OBJ} ld.script
86SYSTEM_LD_HEAD=	@rm -f $@
87SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
88		umask 007; \
89		echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
90		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
91SYSTEM_LD_TAIL=	@${SIZE} $@
92
93.if ${DEBUG} == "-g"
94STRIPFLAGS=	-S
95SYSTEM_LD_TAIL+=; umask 007; \
96		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
97		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
98		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
99.else
100LINKFLAGS+=	-S
101.endif
102
103.if ${SYSTEM_OBJ:Mkcov.o} && ${COMPILER_VERSION:Mclang}
104PROF=		-fsanitize-coverage=trace-pc,trace-cmp
105.endif
106
107%LOAD
108
109# cc's -MD puts the source and output paths in the dependency file;
110# since those are temp files here we need to fix it up.  It also
111# puts the file in /tmp, so we use -MF to put it in the current
112# directory as assym.P and then generate assym.d from it with a
113# good target name
114assym.h: $S/kern/genassym.sh Makefile \
115	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
116	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
117	    sh $S/kern/genassym.sh ${CC} ${NO_INTEGR_AS} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp
118	sed '1s/.*/assym.h: \\/' assym.P > assym.d
119	sort -u assym.h.tmp > assym.h
120
121param.c: $S/conf/param.c
122	rm -f param.c
123	cp $S/conf/param.c .
124
125param.o: param.c Makefile
126	${NORMAL_C}
127
128mcount.o: $S/lib/libkern/mcount.c Makefile
129	${NORMAL_C_NOP}
130
131ioconf.o: ioconf.c
132	${NORMAL_C}
133
134ld.script: ${_machdir}/conf/ld.script
135	cp ${_machdir}/conf/ld.script $@
136
137gapdummy.o:
138	echo '__asm(".section .rodata,\"a\"");' > gapdummy.c
139	${CC} -c ${CFLAGS} ${CPPFLAGS} gapdummy.c -o $@
140
141makegap.sh:
142	cp $S/conf/makegap.sh $@
143
144MAKE_GAP = LD="${LD}" LDFLAGS="${LDFLAGS}" sh makegap.sh 0xcccccccc gapdummy.o
145
146gap.o:	Makefile makegap.sh gapdummy.o vers.o
147	${MAKE_GAP}
148
149vers.o: ${SYSTEM_DEP:Ngap.o}
150	sh $S/conf/newvers.sh
151	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
152
153.if ${SYSTEM_OBJ:Mkcov.o} && ${COMPILER_VERSION:Mclang}
154kcov.o: $S/dev/kcov.c
155	${NORMAL_C} -fno-sanitize-coverage=trace-pc,trace-cmp
156.endif
157
158clean:
159	rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \
160	    gap.link gapdummy.c ld.script lorder makegap.sh param.c
161
162cleandir: clean
163	rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
164
165depend obj:
166
167locore0.o: ${_machdir}/${_mach}/locore0.S assym.h
168locore.o mutex.o in_cksum.o mptramp.o: assym.h
169acpi_wakecode.o: assym.h
170
171hardlink-obsd:
172	[[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd
173
174newinstall:
175	install -F -m 700 bsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd
176
177install: update-link hardlink-obsd newinstall
178
179# pull in the dependency information
180.ifnmake clean
181. for o in ${SYSTEM_OBJ:Ngap.o} assym.h
182.  if exists(${o:R}.d)
183.   include "${o:R}.d"
184.  elif exists($o)
185    .PHONY: $o
186.  endif
187. endfor
188.endif
189
190%RULES
191