Makefile.rump revision 1.118
1#	$NetBSD: Makefile.rump,v 1.118 2015/08/24 22:52:15 pooka Exp $
2#
3
4.if !defined(_RUMP_MK)
5_RUMP_MK= #defined
6
7WARNS?=		3	# XXX: src/sys won't compile with -Wsign-compare yet
8NOLINT=		# kernel code
9
10.include <bsd.own.mk>
11
12# Use NetBSD kernel ABI by default on x86 archs.  Performance-related
13# compile-time options may override this at a later date.
14.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64")
15_RUMP_NATIVEABI= yes
16.else
17_RUMP_NATIVEABI= no
18CPPFLAGS:=	-I${RUMPTOP}/include ${CPPFLAGS}
19CPPFLAGS+=	-D_RUMPKERNEL -I${RUMPTOP}/librump/rumpkern
20.endif
21
22# Define baseline cpu for mips ports, required for
23# rumpcomp_sync_icache() hypercall.
24.if !empty(MACHINE_ARCH:Mmips*)
25.if !empty(MACHINE_ARCH:Mmips64*)
26CPPFLAGS+=	-DMIPS64=1
27.else
28CPPFLAGS+=	-DMIPS1=1
29.endif
30.endif
31
32# which NetBSD compat to build
33RUMP_NBCOMPAT?=default
34.if ${RUMP_NBCOMPAT} == "all" || ${RUMP_NBCOMPAT} == "default"
35RUMP_NBCOMPAT=	50 60 70
36.endif
37.if ${RUMP_NBCOMPAT} == "none"
38RUMP_NBCOMPAT=
39.endif
40RUMP_NBCOMPAT:=	${RUMP_NBCOMPAT:S/,/ /g}
41CPPFLAGS+=	${RUMP_NBCOMPAT:C/[1-9]0/-DCOMPAT_&/g}
42
43CPPFLAGS+=	-nostdinc
44CFLAGS+=	-ffreestanding -fno-strict-aliasing
45
46CWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
47
48CPPFLAGS+=	-imacros ${RUMPTOP}/include/opt/opt_rumpkernel.h
49.ifdef BUILDRUMP_IMACROS
50CPPFLAGS+=	-imacros ${BUILDRUMP_IMACROS}
51.endif
52
53CPPFLAGS+=	-I${.CURDIR} -I.
54CPPFLAGS+=	-I${RUMPTOP}/../../common/include
55CPPFLAGS+=	-I${RUMPTOP}/include
56CPPFLAGS+=	-I${RUMPTOP}/include/opt
57
58SHLIB_MAJOR?=	0
59SHLIB_MINOR?=	0
60
61.ifdef NEED_ISYSTEM
62CPPFLAGS+=	-isystem ${RUMPTOP}/../arch
63CPPFLAGS+=	-isystem ${RUMPTOP}/..
64.else
65CPPFLAGS+=	-I${RUMPTOP}/../arch
66CPPFLAGS+=	-I${RUMPTOP}/..
67.endif
68
69RUMP_LDSCRIPT?=	GNU
70.if ${RUMP_LDSCRIPT} != "no"
71# my ld or yours?
72.if ${RUMP_LDSCRIPT} == "sun"
73LDFLAGS+=	-Wl,-M ${RUMPTOP}/ldscript_sun.rump
74SRCS+=		linksyms_sun.c
75.PATH:		${RUMPTOP}
76.elif ${RUMP_LDSCRIPT} == "GNU"
77LDFLAGS+=	-Wl,-T,${RUMPTOP}/ldscript.rump
78.elif ${RUMP_LDSCRIPT} == "ctor"
79CPPFLAGS+=	-DRUMP_USE_CTOR
80.else
81.error Unknown ldscript ${RUMP_LDSCRIPT}
82.endif
83.endif
84
85.if defined(RUMP_CURLWP)
86.if   ${RUMP_CURLWP} == "hypercall"
87CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_HYPERCALL
88.elif ${RUMP_CURLWP} == "__thread"
89CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP___THREAD
90.elif ${RUMP_CURLWP} == "register"
91CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_REGISTER
92.else
93.error Unsupported curlwp scheme: ${RUMP_CURLWP}
94.endif
95.endif
96
97RUMP_DIAGNOSTIC?=yes
98.if ${RUMP_DIAGNOSTIC} == "yes"
99CPPFLAGS+=	-DDIAGNOSTIC
100.endif
101
102.ifdef RUMP_DEBUG
103CPPFLAGS+=	-DDEBUG
104.endif
105
106.ifdef RUMP_LOCKDEBUG
107CPPFLAGS+=	-DLOCKDEBUG
108.endif
109
110RUMP_KTRACE?=yes
111.if ${RUMP_KTRACE} == "yes"
112CPPFLAGS+=	-DKTRACE
113.endif
114
115# kernel libs should not get linked against libc
116# XXX: actually, we would like to enable this but cannot, since it
117# also leaves out libgcc, it causes problems on some platforms.
118# revisit some day.
119#LDFLAGS+=	-nodefaultlibs
120
121# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
122# also, give those builds a way to undef the local compiler's macros
123CPPFLAGS+=	${RUMPKERN_UNDEF}
124
125RUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
126
127# workaround: evbppc is not a well-defined arch
128.if (${MACHINE} == "evbppc")
129CPPFLAGS+=	-DPPC_OEA
130.endif
131
132# If any of these files change, we need a full rebuild
133DPSRCS+=	${RUMPTOP}/Makefile.rump
134
135#
136# Support for component-specific hypercalls
137#
138
139# no easy way to get WARNS out of bsd.sys.mk
140RUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
141RUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
142
143.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
144.if empty(DESTDIR)
145DESTDIR=/
146.endif
147BUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
148RUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
149.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
150${rcusrc}.d: ${rcusrc}.c
151	${_MKTARGET_CREATE}
152	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
153
154${rcusrc}.o: ${rcusrc}.c
155	${_MKTARGET_COMPILE}
156	${CC} -o ${.TARGET} ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
157
158${rcusrc}.pico: ${rcusrc}.c
159	${_MKTARGET_COMPILE}
160	${CC} -o ${.TARGET} -fPIC -DPIC ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
161
162${rcusrc}.po: ${rcusrc}.c
163	${_MKTARGET_COMPILE}
164	${CC} -o ${.TARGET} ${PROFFLAGS} -pg ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
165
166RUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
167SRCS+=${rcusrc}.c
168.endfor
169.endif
170
171#
172# Rename library symbols before use.  If a symbol does not already belong
173# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
174# avoids accidentally linking any kernel symbol against host platform
175# libraries.  The only non-renamed symbols are linkset delimiters and
176# the GOT, which are more a property of the compiler than the kernel.
177#
178# Some toolchains generate unresolved symbols which are supposed to be
179# satisfied by the toolchain itself when the program is linked.
180# Unfortunately, we do not know which of the symbols are generated by
181# the toolchain.  Worse, they vary from platform to platform and
182# toolchain to toolchain.  The good news, however, is that this will
183# be detected by a compile-time failure, so we can fairly easily manage
184# a quirktable here.
185#
186# We also allow calling ourselves externally with e.g.:
187# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
188#
189.if ${MACHINE_CPU} == "mips"
190_SYMQUIRK='|_gp_disp'
191.elif ${MACHINE_CPU} == "hppa"
192_SYMQUIRK='|\$$\$$'
193.elif ${MACHINE_ARCH} == "powerpc64"
194_SYMQUIRK="|PF_funcs"
195.endif
196
197#
198# Prefix quirks.  At least one toolchain generates global
199# symbols with prefixes which really need to remain as prefixes
200# (i.e. the '.' on the front of some ppc64 globals).  The
201# way to know if you have the problem is if you get later
202# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
203# the 'X' part was added by the toolchain and will need to
204# be mentioned here.
205# 
206.if ${MACHINE_ARCH} == "powerpc64"
207_PQ="\.?"
208.else
209_PQ=
210.endif
211
212rump_symren: __archivebuild
213.if !defined(RUMP_SYMREN)
214	@echo "Must supply RUMP_SYMREN for target rump_symren"
215	@false
216.endif
217
218# if we are called from lib build (RUMP_SYMREN is not specified),
219# build the arrrrchive.  otherwise just rename symbols.
220__archivebuild: .USE
221.if defined(RUMP_SYMREN) && defined(RUMPTOP)
222	@echo "ERROR: RUMP_SYMREN can only be used standalone"
223	@false
224.endif
225.if defined(RUMP_SYMREN)
226	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
227.else
228	${_MKTARGET_BUILD}
229	rm -f ${.TARGET}
230.endif
231	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
232		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
233		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
234		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
235		    | sort | uniq  > renametab.$${renameobj}; \
236		${OBJCOPY} --preserve-dates --redefine-syms \
237		    renametab.$${renameobj} $${renameobj}; \
238		rm -f renametab.$${renameobj}; \
239	done
240.if !defined(RUMP_SYMREN)
241	${AR} ${_ARFL} ${.TARGET} \
242	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
243.endif
244
245_BSD_IOCONF_MK_USER_=1
246.include <bsd.ioconf.mk>
247
248.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
249.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
250
251.endif # _RUMP_MK
252