]> git.proxmox.com Git - rustc.git/blame - mk/rt.mk
Merge tag 'upstream-tar/0.7'
[rustc.git] / mk / rt.mk
CommitLineData
223e47cc 1# This is a procedure to define the targets for building
970d7e83 2# the runtime.
223e47cc
LB
3#
4# Argument 1 is the target triple.
5#
6# This is not really the right place to explain this, but
7# for those of you who are not Makefile gurus, let me briefly
970d7e83 8# cover the $ expansion system in use here, because it
223e47cc
LB
9# confused me for a while! The variable DEF_RUNTIME_TARGETS
10# will be defined once and then expanded with different
11# values substituted for $(1) each time it is called.
970d7e83 12# That resulting text is then eval'd.
223e47cc
LB
13#
14# For most variables, you could use a single $ sign. The result
15# is that the substitution would occur when the CALL occurs,
16# I believe. The problem is that the automatic variables $< and $@
17# need to be expanded-per-rule. Therefore, for those variables at
970d7e83 18# least, you need $$< and $$@ in the variable text. This way, after
223e47cc
LB
19# the CALL substitution occurs, you will have $< and $@. This text
20# will then be evaluated, and all will work as you like.
21#
22# Reader beware, this explanantion could be wrong, but it seems to
970d7e83
LB
23# fit the experimental data (i.e., I was able to get the system
24# working under these assumptions).
223e47cc
LB
25
26# Hack for passing flags into LIBUV, see below.
27LIBUV_FLAGS_i386 = -m32 -fPIC
28LIBUV_FLAGS_x86_64 = -m64 -fPIC
970d7e83 29ifeq ($(OSTYPE_$(1)), linux-androideabi)
223e47cc 30LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
970d7e83
LB
31else
32LIBUV_FLAGS_arm = -fPIC -std=gnu99
33endif
34LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
223e47cc
LB
35
36# when we're doing a snapshot build, we intentionally degrade as many
37# features in libuv and the runtime as possible, to ease portability.
38
39SNAP_DEFINES:=
40ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
41 SNAP_DEFINES=-DRUST_SNAPSHOT
42endif
43
223e47cc
LB
44define DEF_RUNTIME_TARGETS
45
46######################################################################
47# Runtime (C++) library variables
48######################################################################
49
970d7e83
LB
50# $(1) is the target triple
51# $(2) is the stage number
52
53RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
54RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
55
56# XXX: Like with --cfg stage0, pass the defines for stage1 to the stage0
57# build of non-build-triple host compilers
58ifeq ($(2),0)
59ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(1)))
60RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE1
61RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
62endif
63endif
64
65RUNTIME_CXXS_$(1)_$(2) := \
223e47cc
LB
66 rt/sync/timer.cpp \
67 rt/sync/lock_and_signal.cpp \
68 rt/sync/rust_thread.cpp \
69 rt/rust.cpp \
70 rt/rust_builtin.cpp \
71 rt/rust_run_program.cpp \
72 rt/rust_env.cpp \
73 rt/rust_rng.cpp \
74 rt/rust_sched_loop.cpp \
75 rt/rust_sched_launcher.cpp \
76 rt/rust_sched_driver.cpp \
77 rt/rust_scheduler.cpp \
78 rt/rust_sched_reaper.cpp \
79 rt/rust_task.cpp \
80 rt/rust_stack.cpp \
81 rt/rust_upcall.cpp \
82 rt/rust_uv.cpp \
83 rt/rust_crate_map.cpp \
84 rt/rust_log.cpp \
85 rt/rust_gc_metadata.cpp \
86 rt/rust_util.cpp \
87 rt/rust_exchange_alloc.cpp \
88 rt/isaac/randport.cpp \
89 rt/miniz.cpp \
90 rt/rust_kernel.cpp \
91 rt/rust_abi.cpp \
92 rt/rust_debug.cpp \
93 rt/memory_region.cpp \
94 rt/boxed_region.cpp \
95 rt/arch/$$(HOST_$(1))/context.cpp \
96 rt/arch/$$(HOST_$(1))/gpr.cpp \
970d7e83
LB
97 rt/rust_android_dummy.cpp \
98 rt/rust_test_helpers.cpp
223e47cc 99
970d7e83 100RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
223e47cc 101
970d7e83
LB
102RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
103 rt/arch/$$(HOST_$(1))/ccall.S \
104 rt/arch/$$(HOST_$(1))/record_sp.S
223e47cc
LB
105
106ifeq ($$(CFG_WINDOWSY_$(1)), 1)
970d7e83
LB
107 LIBUV_OSTYPE_$(1)_$(2) := win
108 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
109 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/jemalloc.lib
223e47cc 110else ifeq ($(OSTYPE_$(1)), apple-darwin)
970d7e83
LB
111 LIBUV_OSTYPE_$(1)_$(2) := mac
112 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
113 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
223e47cc 114else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
970d7e83
LB
115 LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
116 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
117 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
223e47cc 118else ifeq ($(OSTYPE_$(1)), linux-androideabi)
970d7e83
LB
119 LIBUV_OSTYPE_$(1)_$(2) := unix/android
120 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
121 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
223e47cc 122else
970d7e83
LB
123 LIBUV_OSTYPE_$(1)_$(2) := unix/linux
124 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
125 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
223e47cc
LB
126endif
127
970d7e83
LB
128RUNTIME_DEF_$(1)_$(2) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
129RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
223e47cc
LB
130 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
131 -I $$(S)src/rt/linenoise \
132 -I $$(S)src/libuv/include
970d7e83
LB
133RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=rt/$(1)/stage$(2)/%.o) \
134 $$(RUNTIME_CS_$(1)_$(2):rt/%.c=rt/$(1)/stage$(2)/%.o) \
135 $$(RUNTIME_S_$(1)_$(2):rt/%.S=rt/$(1)/stage$(2)/%.o)
136ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
223e47cc 137
970d7e83
LB
138MORESTACK_OBJ_$(1)_$(2) := rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/morestack.o
139ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
223e47cc 140
970d7e83 141rt/$(1)/stage$(2)/%.o: rt/%.cpp $$(MKFILE_DEPS)
223e47cc 142 @$$(call E, compile: $$@)
970d7e83
LB
143 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
144 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
223e47cc 145
970d7e83 146rt/$(1)/stage$(2)/%.o: rt/%.c $$(MKFILE_DEPS)
223e47cc 147 @$$(call E, compile: $$@)
970d7e83
LB
148 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
149 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
223e47cc 150
970d7e83 151rt/$(1)/stage$(2)/%.o: rt/%.S $$(MKFILE_DEPS) \
223e47cc
LB
152 $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
153 @$$(call E, compile: $$@)
154 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
155
970d7e83 156rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
223e47cc
LB
157 @$$(call E, link: $$@)
158 $$(Q)$(AR_$(1)) rcs $$@ $$<
159
970d7e83
LB
160rt/$(1)/stage$(2)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
161 $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2))
223e47cc 162 @$$(call E, link: $$@)
970d7e83
LB
163 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
164 $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(LIBUV_LIB_$(1)_$(2)) \
165 $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
223e47cc
LB
166
167# FIXME: For some reason libuv's makefiles can't figure out the
168# correct definition of CC on the mingw I'm using, so we are
169# explicitly using gcc. Also, we have to list environment variables
170# first on windows... mysterious
171
172ifdef CFG_ENABLE_FAST_MAKE
173LIBUV_DEPS := $$(S)/.gitmodules
174else
175LIBUV_DEPS := $$(wildcard \
176 $$(S)src/libuv/* \
177 $$(S)src/libuv/*/* \
178 $$(S)src/libuv/*/*/* \
179 $$(S)src/libuv/*/*/*/*)
180endif
181
182# XXX: Shouldn't need platform-specific conditions here
183ifdef CFG_WINDOWSY_$(1)
970d7e83 184$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
223e47cc 185 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
970d7e83 186 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
223e47cc
LB
187 OS=mingw \
188 V=$$(VERBOSE)
189else ifeq ($(OSTYPE_$(1)), linux-androideabi)
970d7e83 190$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
223e47cc 191 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
970d7e83
LB
192 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
193 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
223e47cc
LB
194 CC="$$(CC_$(1))" \
195 CXX="$$(CXX_$(1))" \
196 AR="$$(AR_$(1))" \
197 BUILDTYPE=Release \
970d7e83 198 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
223e47cc
LB
199 host=android OS=linux \
200 V=$$(VERBOSE)
201else
970d7e83 202$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
223e47cc 203 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
970d7e83
LB
204 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
205 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
206 CC="$$(CC_$(1))" \
207 CXX="$$(CXX_$(1))" \
208 AR="$$(AR_$(1))" \
209 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
223e47cc
LB
210 V=$$(VERBOSE)
211endif
212
970d7e83
LB
213ifeq ($(OSTYPE_$(1)), linux-androideabi)
214$$(JEMALLOC_LIB_$(1)_$(2)):
215 cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
216 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) --disable-tls \
217 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
218 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
219 CC="$$(CC_$(1))" \
220 CXX="$$(CXX_$(1))" \
221 AR="$$(AR_$(1))"
222 $$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
223else
224$$(JEMALLOC_LIB_$(1)_$(2)):
225 cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
226 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) \
227 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
228 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
229 CC="$$(CC_$(1))" \
230 CXX="$$(CXX_$(1))" \
231 AR="$$(AR_$(1))"
232 $$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
233endif
234
223e47cc
LB
235
236# These could go in rt.mk or rustllvm.mk, they're needed for both.
237
238# This regexp has a single $, escaped twice
239%.bsd.def: %.def.in $$(MKFILE_DEPS)
240 @$$(call E, def: $$@)
241 $$(Q)echo "{" > $$@
242 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
243 $$(Q)echo "};" >> $$@
244
245%.linux.def: %.def.in $$(MKFILE_DEPS)
246 @$$(call E, def: $$@)
247 $$(Q)echo "{" > $$@
248 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
249 $$(Q)echo "};" >> $$@
250
251%.darwin.def: %.def.in $$(MKFILE_DEPS)
252 @$$(call E, def: $$@)
253 $$(Q)sed 's/^./_&/' $$< > $$@
254
255%.android.def: %.def.in $$(MKFILE_DEPS)
256 @$$(call E, def: $$@)
257 $$(Q)echo "{" > $$@
258 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
259 $$(Q)echo "};" >> $$@
260
261%.mingw32.def: %.def.in $$(MKFILE_DEPS)
262 @$$(call E, def: $$@)
263 $$(Q)echo LIBRARY $$* > $$@
264 $$(Q)echo EXPORTS >> $$@
265 $$(Q)sed 's/^./ &/' $$< >> $$@
266
267endef
268
269# Instantiate template for all stages
970d7e83
LB
270$(foreach stage,$(STAGES), \
271 $(foreach target,$(CFG_TARGET_TRIPLES), \
272 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))