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 define DEF_LIBUV_FLAGS
28 ifeq ($(HOST_$(1)), i386)
29 ifneq (,$(findstring mingw32,$(OSTYPE_$(1))))
30 # Don't add -fPIC since it's ignored for this target
31 # and it will just cause the build to fail due to -Werror
32 LIBUV_FLAGS_$(1) = -m32 -I$(S)src/etc/mingw-fix-include
34 LIBUV_FLAGS_$(1) = -m32 -fPIC -I$(S)src/etc/mingw-fix-include
36 else ifeq ($(HOST_$(1)), x86_64)
37 ifneq (,$(findstring mingw32,$(OSTYPE_$(1))))
38 # Don't add -fPIC since it's ignored for this target
39 # and it will just cause the build to fail due to -Werror
40 LIBUV_FLAGS_$(1) = -m64
42 LIBUV_FLAGS_$(1) = -m64 -fPIC
44 else ifeq ($(HOST_$(1)), arm)
45 ifeq ($(OSTYPE_$(1)), apple-darwin)
46 IOS_SDK := $(shell xcrun --show-sdk-path -sdk iphoneos 2>/dev/null)
47 LIBUV_FLAGS_$(1) = -fPIC -std=gnu99 -I$(IOS_SDK)/usr/include -I$(IOS_SDK)/usr/include/c++/4.2.1
49 LIBUV_FLAGS_$(1) = -fPIC -std=gnu99
51 else ifeq ($(HOST_$(1)), mips)
52 LIBUV_FLAGS_$(1) = -fPIC -mips32r2 -msoft-float -mabi=32
54 LIBUV_FLAGS_$(1) = -fPIC -std=gnu99
57 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_LIBUV_FLAGS,$(t))))
59 # when we're doing a snapshot build, we intentionally degrade as many
60 # features in libuv and the runtime as possible, to ease portability.
63 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
64 SNAP_DEFINES=-DRUST_SNAPSHOT
67 define DEF_LIBUV_ARCH_VAR
68 LIBUV_ARCH_$(1) = $$(subst i386,ia32,$$(subst x86_64,x64,$$(HOST_$(1))))
70 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_LIBUV_ARCH_VAR,$(t))))
72 ifdef CFG_ENABLE_FAST_MAKE
73 LIBUV_DEPS := $(S)/.gitmodules
75 LIBUV_DEPS := $(wildcard \
79 $(S)src/libuv/*/*/*/*)
82 LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
83 uv_dtrace_header.target.mk uv_dtrace_provider.target.mk
85 export PYTHONPATH := $(PYTHONPATH):$(S)src/gyp/pylib
87 define DEF_RUNTIME_TARGETS
89 ######################################################################
90 # Runtime (C++) library variables
91 ######################################################################
93 # $(1) is the target triple
94 # $(2) is the stage number
96 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
97 RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
99 # XXX: Like with --cfg stage0, pass the defines for stage1 to the stage0
100 # build of non-build-triple host compilers
102 ifneq ($(strip $(CFG_BUILD)),$(strip $(1)))
103 RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE1
104 RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
108 RUNTIME_CXXS_$(1)_$(2) := \
111 RUNTIME_CS_$(1)_$(2) := \
115 rt/rust_android_dummy.c \
116 rt/rust_test_helpers.c
118 # stage0 remove this after the next snapshot
122 RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
123 rt/arch/$$(HOST_$(1))/record_sp.S
125 RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
127 RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
128 RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
129 -I $$(S)src/rt/arch/$$(HOST_$(1))
130 RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
131 $$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
132 $$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
133 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
135 MORESTACK_OBJS_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/morestack.o
136 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
138 $$(RT_BUILD_DIR_$(1)_$(2))/rust_cxx_glue.o: rt/rust_cxx_glue.cpp $$(MKFILE_DEPS)
139 @$$(call E, compile: $$@)
140 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
141 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
143 $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.c $$(MKFILE_DEPS)
144 @$$(call E, compile: $$@)
145 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
146 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
148 $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.S $$(MKFILE_DEPS) \
149 $$(LLVM_CONFIG_$$(CFG_BUILD))
150 @$$(call E, compile: $$@)
151 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
153 $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJS_$(1)_$(2))
154 @$$(call E, link: $$@)
155 $$(Q)$(AR_$(1)) rcs $$@ $$^
157 $$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
158 $$(RUNTIME_DEF_$(1)_$(2))
159 @$$(call E, link: $$@)
160 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
161 $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
163 # These could go in rt.mk or rustllvm.mk, they're needed for both.
165 # This regexp has a single $$ escaped twice
166 $(1)/%.bsd.def: %.def.in $$(MKFILE_DEPS)
167 @$$(call E, def: $$@)
169 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
170 $$(Q)echo "};" >> $$@
172 $(1)/%.linux.def: %.def.in $$(MKFILE_DEPS)
173 @$$(call E, def: $$@)
175 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
176 $$(Q)echo "};" >> $$@
178 $(1)/%.darwin.def: %.def.in $$(MKFILE_DEPS)
179 @$$(call E, def: $$@)
180 $$(Q)sed 's/^./_&/' $$< > $$@
182 $(1)/%.android.def: %.def.in $$(MKFILE_DEPS)
183 @$$(call E, def: $$@)
185 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
186 $$(Q)echo "};" >> $$@
188 $(1)/%.mingw32.def: %.def.in $$(MKFILE_DEPS)
189 @$$(call E, def: $$@)
190 $$(Q)echo LIBRARY $$* > $$@
191 $$(Q)echo EXPORTS >> $$@
192 $$(Q)sed 's/^./ &/' $$< >> $$@
197 ######################################################################
198 # Runtime third party targets (libuv, jemalloc, etc.)
200 # These targets do not need to be built once per stage, so these
201 # rules just build them once and then we're done with them.
202 ######################################################################
204 define DEF_THIRD_PARTY_TARGETS
206 # $(1) is the target triple
208 RT_OUTPUT_DIR_$(1) := $(1)/rt
210 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
211 LIBUV_OSTYPE_$(1) := win
212 else ifeq ($(OSTYPE_$(1)), apple-darwin)
213 LIBUV_OSTYPE_$(1) := mac
214 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
215 LIBUV_OSTYPE_$(1) := freebsd
216 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
217 LIBUV_OSTYPE_$(1) := android
218 LIBUV_ARGS_$(1) := PLATFORM=android host=android OS=linux
220 LIBUV_OSTYPE_$(1) := linux
223 LIBUV_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv)
224 LIBUV_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/libuv/$$(LIBUV_NAME_$(1))
226 LIBUV_MAKEFILE_$(1) := $$(CFG_BUILD_DIR)$$(RT_OUTPUT_DIR_$(1))/libuv/Makefile
228 $$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS)
229 (cd $(S)src/libuv/ && \
230 $$(CFG_PYTHON) ./gyp_uv.py -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) \
232 -DOS=$$(LIBUV_OSTYPE_$(1)) \
233 -Goutput_dir=$$(@D) --generator-output $$(@D))
235 # Windows has a completely different build system for libuv because of mingw. In
236 # theory when we support msvc then we should be using gyp's msvc output instead
237 # of mingw's makefile for windows
238 ifdef CFG_WINDOWSY_$(1)
239 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
240 $$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
241 CC="$$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) $$(LIBUV_FLAGS_$(1)) $$(SNAP_DEFINES)" \
244 $$(Q)cp $$(S)src/libuv/libuv.a $$@
246 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1))
247 $$(Q)$$(MAKE) -C $$(@D) \
248 CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1)) $$(LIBUV_FLAGS_$(1)) $$(SNAP_DEFINES)" \
249 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS_$(1)) $$(LIBUV_FLAGS_$(1))" \
253 $$(LIBUV_ARGS_$(1)) \
256 NO_LOAD="$$(LIBUV_NO_LOAD)" \
260 # libuv support functionality (extra C/C++ that we need to use libuv)
262 UV_SUPPORT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv_support)
263 UV_SUPPORT_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/uv_support
264 UV_SUPPORT_LIB_$(1) := $$(UV_SUPPORT_DIR_$(1))/$$(UV_SUPPORT_NAME_$(1))
265 UV_SUPPORT_CS_$(1) := rt/rust_uv.c
266 UV_SUPPORT_OBJS_$(1) := $$(UV_SUPPORT_CS_$(1):rt/%.c=$$(UV_SUPPORT_DIR_$(1))/%.o)
268 $$(UV_SUPPORT_DIR_$(1))/%.o: rt/%.c
269 @$$(call E, compile: $$@)
271 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
272 -I $$(S)src/libuv/include \
273 $$(RUNTIME_CFLAGS_$(1))) $$<
275 $$(UV_SUPPORT_LIB_$(1)): $$(UV_SUPPORT_OBJS_$(1))
276 @$$(call E, link: $$@)
277 $$(Q)$$(AR_$(1)) rcs $$@ $$^
279 # sundown markdown library (used by librustdoc)
281 SUNDOWN_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),sundown)
282 SUNDOWN_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/sundown
283 SUNDOWN_LIB_$(1) := $$(SUNDOWN_DIR_$(1))/$$(SUNDOWN_NAME_$(1))
285 SUNDOWN_CS_$(1) := rt/sundown/src/autolink.c \
286 rt/sundown/src/buffer.c \
287 rt/sundown/src/stack.c \
288 rt/sundown/src/markdown.c \
289 rt/sundown/html/houdini_href_e.c \
290 rt/sundown/html/houdini_html_e.c \
291 rt/sundown/html/html_smartypants.c \
292 rt/sundown/html/html.c
294 SUNDOWN_OBJS_$(1) := $$(SUNDOWN_CS_$(1):rt/%.c=$$(SUNDOWN_DIR_$(1))/%.o)
296 $$(SUNDOWN_DIR_$(1))/%.o: rt/%.c
297 @$$(call E, compile: $$@)
299 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
300 -I $$(S)src/rt/sundown/src -I $$(S)src/rt/sundown/html \
301 $$(RUNTIME_CFLAGS_$(1))) $$<
303 $$(SUNDOWN_LIB_$(1)): $$(SUNDOWN_OBJS_$(1))
304 @$$(call E, link: $$@)
305 $$(Q)$$(AR_$(1)) rcs $$@ $$^
309 # Instantiate template for all stages/targets
310 $(foreach target,$(CFG_TARGET), \
311 $(eval $(call DEF_THIRD_PARTY_TARGETS,$(target))))
312 $(foreach stage,$(STAGES), \
313 $(foreach target,$(CFG_TARGET), \
314 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))