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 LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
30 LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
32 # when we're doing a snapshot build, we intentionally degrade as many
33 # features in libuv and the runtime as possible, to ease portability.
36 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
37 SNAP_DEFINES=-DRUST_SNAPSHOT
41 define DEF_RUNTIME_TARGETS
43 ######################################################################
44 # Runtime (C++) library variables
45 ######################################################################
47 RUNTIME_CXXS_$(1) := \
49 rt/sync/lock_and_signal.cpp \
50 rt/sync/rust_thread.cpp \
53 rt/rust_run_program.cpp \
56 rt/rust_sched_loop.cpp \
57 rt/rust_sched_launcher.cpp \
58 rt/rust_sched_driver.cpp \
59 rt/rust_scheduler.cpp \
60 rt/rust_sched_reaper.cpp \
65 rt/rust_crate_map.cpp \
67 rt/rust_gc_metadata.cpp \
69 rt/rust_exchange_alloc.cpp \
70 rt/isaac/randport.cpp \
75 rt/memory_region.cpp \
77 rt/arch/$$(HOST_$(1))/context.cpp \
78 rt/arch/$$(HOST_$(1))/gpr.cpp \
79 rt/rust_android_dummy.cpp \
80 rt/rust_test_helpers.cpp
82 RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
84 RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
85 rt/arch/$$(HOST_$(1))/ccall.S \
86 rt/arch/$$(HOST_$(1))/record_sp.S
88 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
89 LIBUV_OSTYPE_$(1) := win
90 LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
91 else ifeq ($(OSTYPE_$(1)), apple-darwin)
92 LIBUV_OSTYPE_$(1) := mac
93 LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
94 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
95 LIBUV_OSTYPE_$(1) := unix/freebsd
96 LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
97 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
98 LIBUV_OSTYPE_$(1) := unix/android
99 LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
101 LIBUV_OSTYPE_$(1) := unix/linux
102 LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
105 RUNTIME_DEF_$(1) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
106 RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
107 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
108 -I $$(S)src/rt/linenoise \
109 -I $$(S)src/libuv/include
110 RUNTIME_OBJS_$(1) := $$(RUNTIME_CXXS_$(1):rt/%.cpp=rt/$(1)/%.o) \
111 $$(RUNTIME_CS_$(1):rt/%.c=rt/$(1)/%.o) \
112 $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
113 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1))
115 MORESTACK_OBJ_$(1) := rt/$(1)/arch/$$(HOST_$(1))/morestack.o
116 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))
118 RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
120 rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
121 @$$(call E, compile: $$@)
122 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
123 $$(SNAP_DEFINES)) $$<
125 rt/$(1)/%.o: rt/%.c $$(MKFILE_DEPS)
126 @$$(call E, compile: $$@)
127 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
128 $$(SNAP_DEFINES)) $$<
130 rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) \
131 $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
132 @$$(call E, compile: $$@)
133 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
135 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1))
136 @$$(call E, link: $$@)
137 $$(Q)$(AR_$(1)) rcs $$@ $$<
139 rt/$(1)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
140 $$(RUNTIME_DEF_$(1)) \
141 $$(RUNTIME_LIBS_$(1))
142 @$$(call E, link: $$@)
143 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
144 $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(RUNTIME_LIBS_$(1)) \
145 $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME_$(1)))
147 # FIXME: For some reason libuv's makefiles can't figure out the
148 # correct definition of CC on the mingw I'm using, so we are
149 # explicitly using gcc. Also, we have to list environment variables
150 # first on windows... mysterious
152 ifdef CFG_ENABLE_FAST_MAKE
153 LIBUV_DEPS := $$(S)/.gitmodules
155 LIBUV_DEPS := $$(wildcard \
158 $$(S)src/libuv/*/*/* \
159 $$(S)src/libuv/*/*/*/*)
162 # XXX: Shouldn't need platform-specific conditions here
163 ifdef CFG_WINDOWSY_$(1)
164 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
165 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
166 CFLAGS="$$(CFG_GCCISH_CFLAGS)" \
167 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS)" \
168 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
171 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
172 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
173 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
174 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
175 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
180 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
181 host=android OS=linux \
184 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
185 $$(Q)$$(MAKE) -C $$(S)src/libuv/ \
186 CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
187 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
191 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
196 # These could go in rt.mk or rustllvm.mk, they're needed for both.
198 # This regexp has a single $, escaped twice
199 %.bsd.def: %.def.in $$(MKFILE_DEPS)
200 @$$(call E, def: $$@)
202 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
203 $$(Q)echo "};" >> $$@
205 %.linux.def: %.def.in $$(MKFILE_DEPS)
206 @$$(call E, def: $$@)
208 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
209 $$(Q)echo "};" >> $$@
211 %.darwin.def: %.def.in $$(MKFILE_DEPS)
212 @$$(call E, def: $$@)
213 $$(Q)sed 's/^./_&/' $$< > $$@
215 %.android.def: %.def.in $$(MKFILE_DEPS)
216 @$$(call E, def: $$@)
218 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
219 $$(Q)echo "};" >> $$@
221 %.mingw32.def: %.def.in $$(MKFILE_DEPS)
222 @$$(call E, def: $$@)
223 $$(Q)echo LIBRARY $$* > $$@
224 $$(Q)echo EXPORTS >> $$@
225 $$(Q)sed 's/^./ &/' $$< >> $$@
229 # Instantiate template for all stages
230 $(foreach target,$(CFG_TARGET_TRIPLES), \
231 $(eval $(call DEF_RUNTIME_TARGETS,$(target))))