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 \
79 rt/isaac/randport.cpp \
81 rt/memory_region.cpp \
83 rt/arch/$$(HOST_$(1))/context.cpp \
84 rt/arch/$$(HOST_$(1))/gpr.cpp \
85 rt/rust_android_dummy.cpp \
86 rt/rust_test_helpers.cpp
88 RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
90 RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
91 rt/arch/$$(HOST_$(1))/ccall.S \
92 rt/arch/$$(HOST_$(1))/record_sp.S
94 RT_OUTPUT_DIR_$(1) := $(1)/rt
95 RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
97 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
98 LIBUV_OSTYPE_$(1)_$(2) := win
99 LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
100 JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/jemalloc.lib
101 else ifeq ($(OSTYPE_$(1)), apple-darwin)
102 LIBUV_OSTYPE_$(1)_$(2) := mac
103 LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
104 JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
105 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
106 LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
107 LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
108 JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
109 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
110 LIBUV_OSTYPE_$(1)_$(2) := unix/android
111 LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
112 JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
114 LIBUV_OSTYPE_$(1)_$(2) := unix/linux
115 LIBUV_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/libuv/libuv.a
116 JEMALLOC_LIB_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc/lib/libjemalloc_pic.a
119 RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
120 RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
121 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
122 -I $$(S)src/rt/linenoise \
123 -I $$(S)src/libuv/include
124 RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
125 $$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
126 $$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
127 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
129 MORESTACK_OBJ_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/morestack.o
130 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
132 $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.cpp $$(MKFILE_DEPS)
133 @$$(call E, compile: $$@)
134 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
135 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
137 $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.c $$(MKFILE_DEPS)
138 @$$(call E, compile: $$@)
139 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
140 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
142 $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.S $$(MKFILE_DEPS) \
143 $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
144 @$$(call E, compile: $$@)
145 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
147 $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
148 @$$(call E, link: $$@)
149 $$(Q)$(AR_$(1)) rcs $$@ $$<
151 $$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
152 $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2)) $$(JEMALLOC_LIB_$(1)_$(2))
153 @$$(call E, link: $$@)
154 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
155 $$(JEMALLOC_LIB_$(1)_$(2)) $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(LIBUV_LIB_$(1)_$(2)) \
156 $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
158 # FIXME: For some reason libuv's makefiles can't figure out the
159 # correct definition of CC on the mingw I'm using, so we are
160 # explicitly using gcc. Also, we have to list environment variables
161 # first on windows... mysterious
163 ifdef CFG_ENABLE_FAST_MAKE
164 LIBUV_DEPS := $$(S)/.gitmodules
166 LIBUV_DEPS := $$(wildcard \
169 $$(S)src/libuv/*/*/* \
170 $$(S)src/libuv/*/*/*/*)
173 # XXX: Shouldn't need platform-specific conditions here
174 ifdef CFG_WINDOWSY_$(1)
175 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
176 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
177 builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
180 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
181 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
182 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
183 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
184 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
187 LINK="$$(CXX_$(1))" \
191 builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
192 host=android OS=linux \
195 $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
196 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
197 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
198 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
202 builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
206 ifeq ($(OSTYPE_$(1)), linux-androideabi)
207 $$(JEMALLOC_LIB_$(1)_$(2)):
208 cd $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc; $(S)src/rt/jemalloc/configure \
209 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) --disable-tls \
210 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
211 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
215 $$(Q)$$(MAKE) -C $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc
217 $$(JEMALLOC_LIB_$(1)_$(2)):
218 cd $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc; $(S)src/rt/jemalloc/configure \
219 --disable-experimental --build=$(CFG_BUILD_TRIPLE) --host=$(1) \
220 EXTRA_CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
221 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
225 $$(Q)$$(MAKE) -C $$(RT_BUILD_DIR_$(1)_$(2))/jemalloc
229 # These could go in rt.mk or rustllvm.mk, they're needed for both.
231 # This regexp has a single $, escaped twice
232 $(1)/%.bsd.def: %.def.in $$(MKFILE_DEPS)
233 @$$(call E, def: $$@)
235 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
236 $$(Q)echo "};" >> $$@
238 $(1)/%.linux.def: %.def.in $$(MKFILE_DEPS)
239 @$$(call E, def: $$@)
241 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
242 $$(Q)echo "};" >> $$@
244 $(1)/%.darwin.def: %.def.in $$(MKFILE_DEPS)
245 @$$(call E, def: $$@)
246 $$(Q)sed 's/^./_&/' $$< > $$@
248 $(1)/%.android.def: %.def.in $$(MKFILE_DEPS)
249 @$$(call E, def: $$@)
251 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
252 $$(Q)echo "};" >> $$@
254 $(1)/%.mingw32.def: %.def.in $$(MKFILE_DEPS)
255 @$$(call E, def: $$@)
256 $$(Q)echo LIBRARY $$* > $$@
257 $$(Q)echo EXPORTS >> $$@
258 $$(Q)sed 's/^./ &/' $$< >> $$@
262 # Instantiate template for all stages
263 $(foreach stage,$(STAGES), \
264 $(foreach target,$(CFG_TARGET_TRIPLES), \
265 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))