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