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