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