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