Makefile.landisk revision 1.78
1#	$OpenBSD: Makefile.landisk,v 1.78 2019/04/14 14:07:06 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?=	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
25CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP
26CWARNFLAGS=	-Werror -Wall -Wimplicit-function-declaration \
27		-Wno-main -Wno-uninitialized -Wno-pointer-sign \
28		-Wframe-larger-than=2047
29
30CMACHFLAGS=	-m4-nofpu
31CMACHFLAGS+=	-fno-builtin-printf -fno-builtin-snprintf \
32		-fno-builtin-vsnprintf -fno-builtin-log \
33		-fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
34SORTR=		sort -R
35.if ${IDENT:M-DNO_PROPOLICE}
36CMACHFLAGS+=	-fno-stack-protector
37.endif
38.if ${IDENT:M-DSMALL_KERNEL}
39SORTR=		cat
40COPTS?=		-Oz
41.endif
42
43DEBUG?=		-g
44COPTS?=		-O2
45CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
46AFLAGS=		-D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
47LINKFLAGS=	-N -Ttext 0x8c002000 -e start --warn-common -nopie
48
49HOSTCC?=	${CC}
50HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
51HOSTED_CFLAGS=	${CFLAGS}
52HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
53
54NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -c $<
55NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
56NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
57
58%OBJS
59
60%CFILES
61
62%SFILES
63
64# load lines for config "xxx" will be emitted as:
65# xxx: ${SYSTEM_DEP} swapxxx.o
66#	${SYSTEM_LD_HEAD}
67#	${SYSTEM_LD} swapxxx.o
68#	${SYSTEM_LD_TAIL}
69SYSTEM_HEAD=	locore0.o gap.o
70SYSTEM_OBJ=	${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
71SYSTEM_DEP=	Makefile ${SYSTEM_OBJ} ld.script
72SYSTEM_LD_HEAD=	@rm -f $@
73SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
74		umask 007; \
75		echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
76		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
77SYSTEM_LD_TAIL=	@${SIZE} $@
78
79.if ${DEBUG} == "-g"
80STRIPFLAGS=	-S
81SYSTEM_LD_TAIL+=; umask 007; \
82		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
83		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
84		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
85.else
86LINKFLAGS+=	-S
87.endif
88
89%LOAD
90
91# cc's -MD puts the source and output paths in the dependency file;
92# since those are temp files here we need to fix it up.  It also
93# puts the file in /tmp, so we use -MF to put it in the current
94# directory as assym.P and then generate assym.d from it with a
95# good target name
96assym.h: $S/kern/genassym.sh Makefile \
97	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
98	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
99	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp
100	sed '1s/.*/assym.h: \\/' assym.P > assym.d
101	sort -u assym.h.tmp > assym.h
102
103param.c: $S/conf/param.c
104	rm -f param.c
105	cp $S/conf/param.c .
106
107param.o: param.c Makefile
108	${NORMAL_C}
109
110mcount.o: $S/lib/libkern/mcount.c Makefile
111	${NORMAL_C_NOP}
112
113ioconf.o: ioconf.c
114	${NORMAL_C}
115
116ld.script: ${_machdir}/conf/ld.script
117	cp ${_machdir}/conf/ld.script $@
118
119makegap.sh:
120	cp $S/conf/makegap.sh $@
121
122MAKE_GAP = LD="${LD}" sh makegap.sh 0xc3c3c3c3
123
124gap.o:	Makefile makegap.sh vers.o
125	${MAKE_GAP}
126
127vers.o: ${SYSTEM_DEP:Ngap.o}
128	sh $S/conf/newvers.sh
129	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
130
131clean:
132	rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \
133	    gap.link ld.script lorder makegap.sh param.c
134
135cleandir: clean
136	rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
137
138depend obj:
139
140locore.o: ${_machdir}/${_mach}/locore.S assym.h
141locore0.o: ${_machdir}/${_mach}/locore0.S assym.h
142locore_subr.o vectors.o in_cksum.o: assym.h
143
144hardlink-obsd:
145	[[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd
146
147newinstall:
148	umask 077 && cp bsd /nbsd && mv /nbsd /bsd && \
149	    sha256 -h /var/db/kernel.SHA256 /bsd
150
151install: update-link hardlink-obsd newinstall
152
153# pull in the dependency information
154.ifnmake clean
155. for o in ${SYSTEM_OBJ:Ngap.o} assym.h
156.  if exists(${o:R}.d)
157.   include "${o:R}.d"
158.  elif exists($o)
159    .PHONY: $o
160.  endif
161. endfor
162.endif
163
164%RULES
165