]> git.lizzy.rs Git - rust.git/blob - mk/rt.mk
pass along CFLAGS/LINK_FLAGS to libuv
[rust.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 LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
30 LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
31
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.
34
35 SNAP_DEFINES:=
36 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
37         SNAP_DEFINES=-DRUST_SNAPSHOT
38 endif
39
40
41 define DEF_RUNTIME_TARGETS
42
43 ######################################################################
44 # Runtime (C++) library variables
45 ######################################################################
46
47 RUNTIME_CXXS_$(1) := \
48               rt/sync/timer.cpp \
49               rt/sync/lock_and_signal.cpp \
50               rt/sync/rust_thread.cpp \
51               rt/rust.cpp \
52               rt/rust_builtin.cpp \
53               rt/rust_run_program.cpp \
54               rt/rust_env.cpp \
55               rt/rust_rng.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 \
61               rt/rust_task.cpp \
62               rt/rust_stack.cpp \
63               rt/rust_upcall.cpp \
64               rt/rust_uv.cpp \
65               rt/rust_crate_map.cpp \
66               rt/rust_log.cpp \
67               rt/rust_gc_metadata.cpp \
68               rt/rust_util.cpp \
69               rt/rust_exchange_alloc.cpp \
70               rt/isaac/randport.cpp \
71               rt/miniz.cpp \
72               rt/rust_kernel.cpp \
73               rt/rust_abi.cpp \
74               rt/rust_debug.cpp \
75               rt/memory_region.cpp \
76               rt/boxed_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
81
82 RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
83
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
87
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
100 else
101   LIBUV_OSTYPE_$(1) := unix/linux
102   LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
103 endif
104
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))
114
115 MORESTACK_OBJ_$(1) := rt/$(1)/arch/$$(HOST_$(1))/morestack.o
116 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))
117
118 RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
119
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)) $$<
124
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)) $$<
129
130 rt/$(1)/%.o: rt/%.S  $$(MKFILE_DEPS) \
131                      $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
132         @$$(call E, compile: $$@)
133         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
134
135 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1))
136         @$$(call E, link: $$@)
137         $$(Q)$(AR_$(1)) rcs $$@ $$<
138
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)))
146
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
151
152 ifdef CFG_ENABLE_FAST_MAKE
153 LIBUV_DEPS := $$(S)/.gitmodules
154 else
155 LIBUV_DEPS := $$(wildcard \
156               $$(S)src/libuv/* \
157               $$(S)src/libuv/*/* \
158               $$(S)src/libuv/*/*/* \
159               $$(S)src/libuv/*/*/*/*)
160 endif
161
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" \
169                 OS=mingw \
170                 V=$$(VERBOSE)
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)))" \
176                 CC="$$(CC_$(1))" \
177                 CXX="$$(CXX_$(1))" \
178                 AR="$$(AR_$(1))" \
179                 BUILDTYPE=Release \
180                 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
181                 host=android OS=linux \
182                 V=$$(VERBOSE)
183 else
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)))" \
188                 CC="$$(CC_$(1))" \
189                 CXX="$$(CXX_$(1))" \
190                 AR="$$(AR_$(1))" \
191                 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
192                 V=$$(VERBOSE)
193 endif
194
195
196 # These could go in rt.mk or rustllvm.mk, they're needed for both.
197
198 # This regexp has a single $, escaped twice
199 %.bsd.def:    %.def.in $$(MKFILE_DEPS)
200         @$$(call E, def: $$@)
201         $$(Q)echo "{" > $$@
202         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
203         $$(Q)echo "};" >> $$@
204
205 %.linux.def:    %.def.in $$(MKFILE_DEPS)
206         @$$(call E, def: $$@)
207         $$(Q)echo "{" > $$@
208         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
209         $$(Q)echo "};" >> $$@
210
211 %.darwin.def:   %.def.in $$(MKFILE_DEPS)
212         @$$(call E, def: $$@)
213         $$(Q)sed 's/^./_&/' $$< > $$@
214
215 %.android.def:  %.def.in $$(MKFILE_DEPS)
216         @$$(call E, def: $$@)
217         $$(Q)echo "{" > $$@
218         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
219         $$(Q)echo "};" >> $$@
220
221 %.mingw32.def:  %.def.in $$(MKFILE_DEPS)
222         @$$(call E, def: $$@)
223         $$(Q)echo LIBRARY $$* > $$@
224         $$(Q)echo EXPORTS >> $$@
225         $$(Q)sed 's/^./    &/' $$< >> $$@
226
227 endef
228
229 # Instantiate template for all stages
230 $(foreach target,$(CFG_TARGET_TRIPLES), \
231  $(eval $(call DEF_RUNTIME_TARGETS,$(target))))