rt.mk 9.4 KB
Newer Older
1
# This is a procedure to define the targets for building
2
# the runtime.
3 4 5 6 7
#
# Argument 1 is the target triple.
#
# This is not really the right place to explain this, but
# for those of you who are not Makefile gurus, let me briefly
8
# cover the $ expansion system in use here, because it
9 10 11
# confused me for a while!  The variable DEF_RUNTIME_TARGETS
# will be defined once and then expanded with different
# values substituted for $(1) each time it is called.
12
# That resulting text is then eval'd.
13 14 15 16 17
#
# For most variables, you could use a single $ sign.  The result
# is that the substitution would occur when the CALL occurs,
# I believe.  The problem is that the automatic variables $< and $@
# need to be expanded-per-rule.  Therefore, for those variables at
18
# least, you need $$< and $$@ in the variable text.  This way, after
19 20 21 22
# the CALL substitution occurs, you will have $< and $@.  This text
# will then be evaluated, and all will work as you like.
#
# Reader beware, this explanantion could be wrong, but it seems to
23 24
# fit the experimental data (i.e., I was able to get the system
# working under these assumptions).
25

N
Niko Matsakis 已提交
26
# Hack for passing flags into LIBUV, see below.
27 28
LIBUV_FLAGS_i386 = -m32 -fPIC
LIBUV_FLAGS_x86_64 = -m64 -fPIC
J
Jyun-Yan You 已提交
29
ifeq ($(OSTYPE_$(1)), linux-androideabi)
Y
Young-il Choi 已提交
30
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
J
Jyun-Yan You 已提交
31 32 33
else
LIBUV_FLAGS_arm = -fPIC -std=gnu99
endif
J
Jyun-Yan You 已提交
34
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
N
Niko Matsakis 已提交
35

36 37 38 39 40 41 42 43
# when we're doing a snapshot build, we intentionally degrade as many
# features in libuv and the runtime as possible, to ease portability.

SNAP_DEFINES:=
ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
	SNAP_DEFINES=-DRUST_SNAPSHOT
endif

44 45
define DEF_RUNTIME_TARGETS

G
Graydon Hoare 已提交
46 47 48 49
######################################################################
# Runtime (C++) library variables
######################################################################

50 51 52 53 54 55
# $(1) is the target triple
# $(2) is the stage number

RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)

56 57 58 59 60 61 62 63 64
# XXX: Like with --cfg stage0, pass the defines for stage1 to the stage0
# build of non-build-triple host compilers
ifeq ($(2),0)
ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(1)))
RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE1
RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
endif
endif

65
RUNTIME_CXXS_$(1)_$(2) := \
G
Graydon Hoare 已提交
66
              rt/sync/lock_and_signal.cpp \
67
              rt/sync/rust_thread.cpp \
G
Graydon Hoare 已提交
68 69
              rt/rust_builtin.cpp \
              rt/rust_run_program.cpp \
70
              rt/rust_rng.cpp \
G
Graydon Hoare 已提交
71
              rt/rust_upcall.cpp \
72
              rt/rust_uv.cpp \
73
              rt/rust_crate_map.cpp \
74
              rt/rust_util.cpp \
75
              rt/rust_log.cpp \
G
Graydon Hoare 已提交
76
              rt/isaac/randport.cpp \
77
              rt/miniz.cpp \
78
              rt/rust_abi.cpp \
G
Graydon Hoare 已提交
79
              rt/memory_region.cpp \
80
              rt/boxed_region.cpp \
81
              rt/arch/$$(HOST_$(1))/context.cpp \
Y
Young-il Choi 已提交
82
              rt/arch/$$(HOST_$(1))/gpr.cpp \
83 84
              rt/rust_android_dummy.cpp \
              rt/rust_test_helpers.cpp
85

86
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
87

88 89 90
RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
			rt/arch/$$(HOST_$(1))/ccall.S \
			rt/arch/$$(HOST_$(1))/record_sp.S
91

92
ifeq ($$(CFG_WINDOWSY_$(1)), 1)
93 94
  LIBUV_OSTYPE_$(1)_$(2) := win
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
C
Corey Richardson 已提交
95
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/jemalloc.lib
96
else ifeq ($(OSTYPE_$(1)), apple-darwin)
97 98
  LIBUV_OSTYPE_$(1)_$(2) := mac
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
99
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
100
else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
101 102
  LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
103
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
104
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
105 106
  LIBUV_OSTYPE_$(1)_$(2) := unix/android
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
107
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
108
else
109 110
  LIBUV_OSTYPE_$(1)_$(2) := unix/linux
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
111
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
112
endif
G
Graydon Hoare 已提交
113

114 115
RUNTIME_DEF_$(1)_$(2) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
116 117 118
                     -I $$(S)src/rt/arch/$$(HOST_$(1)) \
                     -I $$(S)src/rt/linenoise \
                     -I $$(S)src/libuv/include
119 120 121 122
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=rt/$(1)/stage$(2)/%.o) \
                     $$(RUNTIME_CS_$(1)_$(2):rt/%.c=rt/$(1)/stage$(2)/%.o) \
                     $$(RUNTIME_S_$(1)_$(2):rt/%.S=rt/$(1)/stage$(2)/%.o)
ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
123

124 125
MORESTACK_OBJ_$(1)_$(2) := rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/morestack.o
ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
126

127
rt/$(1)/stage$(2)/%.o: rt/%.cpp $$(MKFILE_DEPS)
128
	@$$(call E, compile: $$@)
129 130
	$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
                 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
131

132
rt/$(1)/stage$(2)/%.o: rt/%.c $$(MKFILE_DEPS)
133
	@$$(call E, compile: $$@)
134 135
	$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
                 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
136

137
rt/$(1)/stage$(2)/%.o: rt/%.S  $$(MKFILE_DEPS) \
138
                     $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
139
	@$$(call E, compile: $$@)
140
	$$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
141

142
rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
143
	@$$(call E, link: $$@)
144
	$$(Q)$(AR_$(1)) rcs $$@ $$<
145

146
rt/$(1)/stage$(2)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
D
Daniel Micay 已提交
147
                        $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2)) $$(JEMALLOC_LIB_$(1)_$(2))
148
	@$$(call E, link: $$@)
149
	$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
D
Daniel Micay 已提交
150
	  $$(JEMALLOC_LIB_$(1)_$(2)) $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(LIBUV_LIB_$(1)_$(2)) \
151
	  $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
152

M
Michael Sullivan 已提交
153 154 155 156
# FIXME: For some reason libuv's makefiles can't figure out the
# correct definition of CC on the mingw I'm using, so we are
# explicitly using gcc. Also, we have to list environment variables
# first on windows... mysterious
157 158 159 160 161 162 163 164 165 166 167

ifdef CFG_ENABLE_FAST_MAKE
LIBUV_DEPS := $$(S)/.gitmodules
else
LIBUV_DEPS := $$(wildcard \
              $$(S)src/libuv/* \
              $$(S)src/libuv/*/* \
              $$(S)src/libuv/*/*/* \
              $$(S)src/libuv/*/*/*/*)
endif

B
Brian Anderson 已提交
168
# XXX: Shouldn't need platform-specific conditions here
169
ifdef CFG_WINDOWSY_$(1)
170
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
171
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
172
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
173 174
		OS=mingw \
		V=$$(VERBOSE)
175
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
176
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
Y
Young-il Choi 已提交
177
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
178 179
		CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
B
Brian Anderson 已提交
180 181 182
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
Y
Young-il Choi 已提交
183
		BUILDTYPE=Release \
184
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
Y
Young-il Choi 已提交
185
		host=android OS=linux \
186
		V=$$(VERBOSE)
Y
Young-il Choi 已提交
187
else
188
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
189
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
190 191
		CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
J
Jyun-Yan You 已提交
192 193 194
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
195
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
196
		V=$$(VERBOSE)
197 198
endif

199 200 201 202 203 204 205 206 207 208 209
ifeq ($(OSTYPE_$(1)), linux-androideabi)
$$(JEMALLOC_LIB_$(1)_$(2)):
	cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
		--disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) --disable-tls \
		EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))"
	$$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
else
D
Daniel Micay 已提交
210
$$(JEMALLOC_LIB_$(1)_$(2)):
211
	cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
212 213 214 215 216 217
		--disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) \
		EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))"
D
Daniel Micay 已提交
218
	$$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
219
endif
G
Graydon Hoare 已提交
220

221

G
Graydon Hoare 已提交
222 223
# These could go in rt.mk or rustllvm.mk, they're needed for both.

224
# This regexp has a single $, escaped twice
U
User Jyyou 已提交
225 226 227 228 229 230
%.bsd.def:    %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

231
%.linux.def:    %.def.in $$(MKFILE_DEPS)
232 233
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
234
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
235
	$$(Q)echo "};" >> $$@
G
Graydon Hoare 已提交
236

237 238 239 240
%.darwin.def:	%.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)sed 's/^./_&/' $$< > $$@

Y
Young-il Choi 已提交
241 242 243 244 245 246
%.android.def:  %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

247
%.mingw32.def:	%.def.in $$(MKFILE_DEPS)
248 249 250 251 252 253 254 255
	@$$(call E, def: $$@)
	$$(Q)echo LIBRARY $$* > $$@
	$$(Q)echo EXPORTS >> $$@
	$$(Q)sed 's/^./    &/' $$< >> $$@

endef

# Instantiate template for all stages
256 257 258
$(foreach stage,$(STAGES), \
	$(foreach target,$(CFG_TARGET_TRIPLES), \
	 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))