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