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_RUNTIME_TARGETS
46 ######################################################################
47 # Runtime (C++) library variables
48 ######################################################################
50 # $(1) is the target triple
51 # $(2) is the stage number
53 RUNTIME_CFLAGS_
$(1)_
$(2) = -D_RUST_STAGE
$(2)
54 RUNTIME_CXXFLAGS_
$(1)_
$(2) = -D_RUST_STAGE
$(2)
56 # XXX: Like with --cfg stage0, pass the defines for stage1 to the stage0
57 # build of non-build-triple host compilers
59 ifneq ($(strip $(CFG_BUILD_TRIPLE
)),$(strip $(1)))
60 RUNTIME_CFLAGS_
$(1)_
$(2) = -D_RUST_STAGE1
61 RUNTIME_CXXFLAGS_
$(1)_
$(2) = -D_RUST_STAGE1
65 RUNTIME_CXXS_
$(1)_
$(2) := \
67 rt
/sync
/lock_and_signal.
cpp \
68 rt
/sync
/rust_thread.
cpp \
71 rt
/rust_run_program.
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 \
83 rt
/rust_crate_map.
cpp \
85 rt
/rust_gc_metadata.
cpp \
87 rt
/rust_exchange_alloc.
cpp \
88 rt
/isaac
/randport.
cpp \
93 rt
/memory_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
100 RUNTIME_CS_
$(1)_
$(2) := rt
/linenoise
/linenoise.c rt
/linenoise
/utf8.c
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
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
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
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))
138 MORESTACK_OBJ_
$(1)_
$(2) := rt
/$(1)/stage
$(2)/arch
/$$(HOST_
$(1))/morestack.o
139 ALL_OBJ_FILES
+= $$(MORESTACK_OBJS_
$(1)_
$(2))
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))) $$<
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))) $$<
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),$$@
,$$<)
156 rt
/$(1)/stage
$(2)/arch
/$$(HOST_
$(1))/libmorestack.a
: $$(MORESTACK_OBJ_
$(1)_
$(2))
157 @
$$(call E
, link
: $$@
)
158 $$(Q
)$(AR_
$(1)) rcs
$$@
$$<
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)))
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
172 ifdef CFG_ENABLE_FAST_MAKE
173 LIBUV_DEPS
:= $$(S
)/.gitmodules
175 LIBUV_DEPS
:= $$(wildcard \
178 $$(S
)src
/libuv
/*/*/* \
179 $$(S
)src
/libuv
/*/*/*/*)
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" \
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)))" \
198 builddir_name
="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
199 host
=android OS
=linux \
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)))" \
209 builddir_name
="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
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)))" \
222 $$(Q
)$$(MAKE
) -C
$$(CFG_BUILD_DIR
)/rt
/$(1)/stage
$(2)/jemalloc
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)))" \
232 $$(Q
)$$(MAKE
) -C
$$(CFG_BUILD_DIR
)/rt
/$(1)/stage
$(2)/jemalloc
236 # These could go in rt.mk or rustllvm.mk, they're needed for both.
238 # This regexp has a single $, escaped twice
239 %.bsd.def
: %.def.in
$$(MKFILE_DEPS
)
240 @
$$(call E
, def
: $$@
)
242 $$(Q
)sed
's/.$$$$/&;/' $$< >> $$@
243 $$(Q
)echo
"};" >> $$@
245 %.linux.def
: %.def.in
$$(MKFILE_DEPS
)
246 @
$$(call E
, def
: $$@
)
248 $$(Q
)sed
's/.$$$$/&;/' $$< >> $$@
249 $$(Q
)echo
"};" >> $$@
251 %.darwin.def
: %.def.in
$$(MKFILE_DEPS
)
252 @
$$(call E
, def
: $$@
)
253 $$(Q
)sed
's/^./_&/' $$< > $$@
255 %.android.def
: %.def.in
$$(MKFILE_DEPS
)
256 @
$$(call E
, def
: $$@
)
258 $$(Q
)sed
's/.$$$$/&;/' $$< >> $$@
259 $$(Q
)echo
"};" >> $$@
261 %.mingw32.def
: %.def.in
$$(MKFILE_DEPS
)
262 @
$$(call E
, def
: $$@
)
263 $$(Q
)echo LIBRARY
$$* > $$@
264 $$(Q
)echo EXPORTS
>> $$@
265 $$(Q
)sed
's/^./ &/' $$< >> $$@
269 # Instantiate template for all stages
270 $(foreach stage
,$(STAGES
), \
271 $(foreach target
,$(CFG_TARGET_TRIPLES
), \
272 $(eval
$(call DEF_RUNTIME_TARGETS
,$(target
),$(stage
)))))