Makefile.landisk revision 1.30
1#	$OpenBSD: Makefile.landisk,v 1.30 2010/05/24 17:49:37 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
13MKDEP?=	mkdep
14SIZE?=	size
15STRIP?=	strip
16
17# source tree is located via $S relative to the compilation directory
18.ifndef S
19S!=	cd ../../../..; pwd
20.endif
21
22_mach?=		landisk
23_arch?=		sh
24_machdir?=	$S/arch/${_mach}
25_archdir?=	$S/arch/${_arch}
26
27INCLUDES=	-nostdinc -I. -I$S -I$S/arch
28CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__
29CWARNFLAGS=	-Werror -Wall -Wstrict-prototypes -Wmissing-prototypes \
30		-Wno-main -Wno-uninitialized -Wno-format \
31		-Wstack-larger-than-2047 -Wvariable-decl
32
33CMACHFLAGS=	-m4-nofpu
34CMACHFLAGS+=	-fno-builtin-printf -fno-builtin-snprintf \
35		-fno-builtin-vsnprintf -fno-builtin-log \
36		-fno-builtin-log2 -fno-builtin-malloc 
37.if ${IDENT:M-DNO_PROPOLICE}
38CMACHFLAGS+=	-fno-stack-protector
39.endif
40
41COPTS?=		-O2
42CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
43AFLAGS=		-D_LOCORE -x assembler-with-cpp -traditional-cpp ${CMACHFLAGS}
44LINKFLAGS=	-N -Ttext 0x8c002000 -e start --warn-common
45STRIPFLAGS=	-g -X -x
46
47.if ${IDENT:M-DDDB_STRUCT}
48DB_STRUCTINFO=	db_structinfo.h
49.else
50DB_STRUCTINFO=
51.endif
52
53HOSTCC?=	${CC}
54HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
55HOSTED_CFLAGS=	${CFLAGS}
56HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
57
58NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -c $<
59NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
60NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
61
62%OBJS
63
64%CFILES
65
66%SFILES
67
68# load lines for config "xxx" will be emitted as:
69# xxx: ${SYSTEM_DEP} swapxxx.o
70#	${SYSTEM_LD_HEAD}
71#	${SYSTEM_LD} swapxxx.o
72#	${SYSTEM_LD_TAIL}
73SYSTEM_OBJ=	locore.o param.o ioconf.o ${OBJS}
74SYSTEM_DEP=	Makefile ${SYSTEM_OBJ}
75SYSTEM_LD_HEAD=	@rm -f $@
76SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
77		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
78SYSTEM_LD_TAIL=	@${SIZE} $@; chmod 755 $@
79
80DEBUG?=
81.if ${DEBUG} == "-g"
82LINKFLAGS+=	-X
83SYSTEM_LD_TAIL+=; \
84		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
85		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
86		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
87.else
88LINKFLAGS+=	-S -x
89.endif
90
91%LOAD
92
93assym.h: $S/kern/genassym.sh Makefile \
94	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
95	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
96	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PARAM} | \
97	    sort -u > assym.h.tmp && \
98	    mv -f assym.h.tmp assym.h
99
100param.c: $S/conf/param.c
101	rm -f param.c
102	cp $S/conf/param.c .
103
104param.o: param.c Makefile
105	${NORMAL_C}
106
107mcount.o: $S/lib/libkern/mcount.c Makefile
108	${NORMAL_C_NOP}
109
110ioconf.o: ioconf.c
111	${NORMAL_C}
112
113vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
114	sh $S/conf/newvers.sh
115	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
116
117clean::
118	rm -f eddep *bsd *bsd.gdb tags *.[io] [a-z]*.s \
119	    [Ee]rrs linterrs makelinks assym.h ${DB_STRUCTINFO}
120
121lint:
122	@lint -hbxncez -Dvolatile= ${CPPFLAGS} -UKGDB \
123	    ${CFILES} ioconf.c param.c | \
124	    grep -v 'static function .* unused'
125
126tags:
127	@echo "see $S/kern/Makefile for tags"
128
129links:
130	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
131	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
132	echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
133	  sort -u | comm -23 - dontlink | \
134	  sed 's,../.*/\(.*.o\),rm -f \1; ln -s ../GENERIC/\1 \1,' > makelinks
135	sh makelinks && rm -f dontlink makelinks
136
137SRCS=	${_machdir}/${_mach}/locore.S \
138	param.c ioconf.c ${CFILES} ${SFILES}
139depend:: .depend
140.depend: ${SRCS} assym.h param.c ${DB_STRUCTINFO}
141	${MKDEP} ${AFLAGS} ${CPPFLAGS} ${_machdir}/${_mach}/locore.S
142	${MKDEP} -a ${CFLAGS} ${CPPFLAGS} param.c ioconf.c ${CFILES}
143.if !empty(SFILES)
144	${MKDEP} -a ${AFLAGS} ${CPPFLAGS} ${SFILES}
145.endif
146	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
147	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
148	@sed -e 's/.*\.o: /assym.h: /' -e 's/\/tmp\/genassym_c.[^ ]*//' \
149	    < assym.dep >> .depend
150	@rm -f assym.dep
151
152db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk
153	${CC} ${CFLAGS} ${CPPFLAGS} -gstabs -c $S/ddb/db_structinfo.c
154	objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@
155	rm -f db_structinfo.o
156
157locore.o: ${_machdir}/${_mach}/locore.S assym.h
158	${NORMAL_S}
159
160# The install target can be redefined by putting a
161# install-kernel-${MACHINE_NAME} target into /etc/mk.conf
162MACHINE_NAME!=  uname -n
163install: install-kernel-${MACHINE_NAME}
164.if !target(install-kernel-${MACHINE_NAME}})
165install-kernel-${MACHINE_NAME}:
166	rm -f /obsd
167	ln /bsd /obsd
168	cp bsd /nbsd
169	mv /nbsd /bsd
170.endif
171
172%RULES
173