]> git.proxmox.com Git - rustc.git/blob - mk/rt.mk
Imported Upstream version 0.7
[rustc.git] / mk / rt.mk
1 # This is a procedure to define the targets for building
2 # the runtime.
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
8 # cover the $ expansion system in use here, because it
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.
12 # That resulting text is then eval'd.
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
18 # least, you need $$< and $$@ in the variable text. This way, after
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
23 # fit the experimental data (i.e., I was able to get the system
24 # working under these assumptions).
25
26 # Hack for passing flags into LIBUV, see below.
27 LIBUV_FLAGS_i386 = -m32 -fPIC
28 LIBUV_FLAGS_x86_64 = -m64 -fPIC
29 ifeq ($(OSTYPE_$(1)), linux-androideabi)
30 LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
31 else
32 LIBUV_FLAGS_arm = -fPIC -std=gnu99
33 endif
34 LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
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
39 SNAP_DEFINES:=
40 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
41 SNAP_DEFINES=-DRUST_SNAPSHOT
42 endif
43
44 define DEF_RUNTIME_TARGETS
45
46 ######################################################################
47 # Runtime (C++) library variables
48 ######################################################################
49
50 # $(1) is the target triple
51 # $(2) is the stage number
52
53 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
54 RUNTIME_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
58 ifeq ($(2),0)
59 ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(1)))
60 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE1
61 RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
62 endif
63 endif
64
65 RUNTIME_CXXS_$(1)_$(2) := \
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 \
97 rt/rust_android_dummy.cpp \
98 rt/rust_test_helpers.cpp
99
100 RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
101
102 RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
103 rt/arch/$$(HOST_$(1))/ccall.S \
104 rt/arch/$$(HOST_$(1))/record_sp.S
105
106 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
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
110 else ifeq ($(OSTYPE_$(1)), apple-darwin)
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
114 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
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
118 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
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
122 else
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
126 endif
127
128 RUNTIME_DEF_$(1)_$(2) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
129 RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
130 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
131 -I $$(S)src/rt/linenoise \
132 -I $$(S)src/libuv/include
133 RUNTIME_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)
136 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
137
138 MORESTACK_OBJ_$(1)_$(2) := rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/morestack.o
139 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
140
141 rt/$(1)/stage$(2)/%.o: rt/%.cpp $$(MKFILE_DEPS)
142 @$$(call E, compile: $$@)
143 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
144 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
145
146 rt/$(1)/stage$(2)/%.o: rt/%.c $$(MKFILE_DEPS)
147 @$$(call E, compile: $$@)
148 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
149 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
150
151 rt/$(1)/stage$(2)/%.o: rt/%.S $$(MKFILE_DEPS) \
152 $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
153 @$$(call E, compile: $$@)
154 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
155
156 rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
157 @$$(call E, link: $$@)
158 $$(Q)$(AR_$(1)) rcs $$@ $$<
159
160 rt/$(1)/stage$(2)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
161 $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2))
162 @$$(call E, link: $$@)
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)))
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
172 ifdef CFG_ENABLE_FAST_MAKE
173 LIBUV_DEPS := $$(S)/.gitmodules
174 else
175 LIBUV_DEPS := $$(wildcard \
176 $$(S)src/libuv/* \
177 $$(S)src/libuv/*/* \
178 $$(S)src/libuv/*/*/* \
179 $$(S)src/libuv/*/*/*/*)
180 endif
181
182 # XXX: Shouldn't need platform-specific conditions here
183 ifdef CFG_WINDOWSY_$(1)
184 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
185 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
186 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
187 OS=mingw \
188 V=$$(VERBOSE)
189 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
190 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
191 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
192 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
193 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
194 CC="$$(CC_$(1))" \
195 CXX="$$(CXX_$(1))" \
196 AR="$$(AR_$(1))" \
197 BUILDTYPE=Release \
198 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
199 host=android OS=linux \
200 V=$$(VERBOSE)
201 else
202 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
203 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
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" \
210 V=$$(VERBOSE)
211 endif
212
213 ifeq ($(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
223 else
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
233 endif
234
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
267 endef
268
269 # Instantiate template for all stages
270 $(foreach stage,$(STAGES), \
271 $(foreach target,$(CFG_TARGET_TRIPLES), \
272 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))