1 # This is a procedure to define the targets for building
4 # Argument 1 is the target triple.
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.
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.
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).
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
32 LIBUV_FLAGS_arm = -fPIC -std=gnu99
34 LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
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.
40 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
41 SNAP_DEFINES=-DRUST_SNAPSHOT
44 define DEF_LIBUV_ARCH_VAR
45 LIBUV_ARCH_$(1) = $$(subst i386,ia32,$$(subst x86_64,x64,$$(HOST_$(1))))
47 $(foreach t,$(CFG_TARGET_TRIPLES),$(eval $(call DEF_LIBUV_ARCH_VAR,$(t))))
49 define DEF_RUNTIME_TARGETS
51 ######################################################################
52 # Runtime (C++) library variables
53 ######################################################################
55 # $(1) is the target triple
56 # $(2) is the stage number
58 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
59 RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
61 # XXX: Like with --cfg stage0, pass the defines for stage1 to the stage0
62 # build of non-build-triple host compilers
64 ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(1)))
65 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE1
66 RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
70 RUNTIME_CXXS_$(1)_$(2) := \
71 rt/sync/lock_and_signal.cpp \
72 rt/sync/rust_thread.cpp \
74 rt/rust_run_program.cpp \
78 rt/rust_crate_map.cpp \
80 rt/isaac/randport.cpp \
82 rt/memory_region.cpp \
84 rt/arch/$$(HOST_$(1))/context.cpp \
85 rt/arch/$$(HOST_$(1))/gpr.cpp \
86 rt/rust_android_dummy.cpp \
87 rt/rust_test_helpers.cpp
89 RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
91 RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
92 rt/arch/$$(HOST_$(1))/ccall.S \
93 rt/arch/$$(HOST_$(1))/record_sp.S
95 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
96 LIBUV_OSTYPE_$(1)_$(2) := win
97 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
98 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/jemalloc.lib
99 else ifeq ($(OSTYPE_$(1)), apple-darwin)
100 LIBUV_OSTYPE_$(1)_$(2) := mac
101 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
102 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
103 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
104 LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
105 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
106 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
107 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
108 LIBUV_OSTYPE_$(1)_$(2) := unix/android
109 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
110 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
112 LIBUV_OSTYPE_$(1)_$(2) := unix/linux
113 LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
114 JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
117 RUNTIME_DEF_$(1)_$(2) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
118 RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
119 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
120 -I $$(S)src/rt/linenoise \
121 -I $$(S)src/libuv/include
122 RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=rt/$(1)/stage$(2)/%.o) \
123 $$(RUNTIME_CS_$(1)_$(2):rt/%.c=rt/$(1)/stage$(2)/%.o) \
124 $$(RUNTIME_S_$(1)_$(2):rt/%.S=rt/$(1)/stage$(2)/%.o)
125 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
127 MORESTACK_OBJ_$(1)_$(2) := rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/morestack.o
128 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
130 rt/$(1)/stage$(2)/%.o: rt/%.cpp $$(MKFILE_DEPS)
131 @$$(call E, compile: $$@)
132 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
133 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
135 rt/$(1)/stage$(2)/%.o: rt/%.c $$(MKFILE_DEPS)
136 @$$(call E, compile: $$@)
137 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
138 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
140 rt/$(1)/stage$(2)/%.o: rt/%.S $$(MKFILE_DEPS) \
141 $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
142 @$$(call E, compile: $$@)
143 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
145 rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
146 @$$(call E, link: $$@)
147 $$(Q)$(AR_$(1)) rcs $$@ $$<
149 rt/$(1)/stage$(2)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
150 $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2)) $$(JEMALLOC_LIB_$(1)_$(2))
151 @$$(call E, link: $$@)
152 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
153 $$(JEMALLOC_LIB_$(1)_$(2)) $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(LIBUV_LIB_$(1)_$(2)) \
154 $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
156 # FIXME: For some reason libuv's makefiles can't figure out the
157 # correct definition of CC on the mingw I'm using, so we are
158 # explicitly using gcc. Also, we have to list environment variables
159 # first on windows... mysterious
161 ifdef CFG_ENABLE_FAST_MAKE
162 LIBUV_DEPS := $$(S)/.gitmodules
164 LIBUV_DEPS := $$(wildcard \
167 $$(S)src/libuv/*/*/* \
168 $$(S)src/libuv/*/*/*/*)
171 # XXX: Shouldn't need platform-specific conditions here
172 ifdef CFG_WINDOWSY_$(1)
173 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
174 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
175 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
178 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
179 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
180 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
181 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
182 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
185 LINK="$$(CXX_$(1))" \
189 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
190 host=android OS=linux \
193 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
194 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
195 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
196 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
200 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
204 ifeq ($(OSTYPE_$(1)), linux-androideabi)
205 $$(JEMALLOC_LIB_$(1)_$(2)):
206 cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
207 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) --disable-tls \
208 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
209 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
213 $$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
215 $$(JEMALLOC_LIB_$(1)_$(2)):
216 cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure \
217 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) \
218 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
219 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
223 $$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
227 # These could go in rt.mk or rustllvm.mk, they're needed for both.
229 # This regexp has a single $, escaped twice
230 %.bsd.def: %.def.in $$(MKFILE_DEPS)
231 @$$(call E, def: $$@)
233 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
234 $$(Q)echo "};" >> $$@
236 %.linux.def: %.def.in $$(MKFILE_DEPS)
237 @$$(call E, def: $$@)
239 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
240 $$(Q)echo "};" >> $$@
242 %.darwin.def: %.def.in $$(MKFILE_DEPS)
243 @$$(call E, def: $$@)
244 $$(Q)sed 's/^./_&/' $$< > $$@
246 %.android.def: %.def.in $$(MKFILE_DEPS)
247 @$$(call E, def: $$@)
249 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
250 $$(Q)echo "};" >> $$@
252 %.mingw32.def: %.def.in $$(MKFILE_DEPS)
253 @$$(call E, def: $$@)
254 $$(Q)echo LIBRARY $$* > $$@
255 $$(Q)echo EXPORTS >> $$@
256 $$(Q)sed 's/^./ &/' $$< >> $$@
260 # Instantiate template for all stages
261 $(foreach stage,$(STAGES), \
262 $(foreach target,$(CFG_TARGET_TRIPLES), \
263 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))