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