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
30 # when we're doing a snapshot build, we intentionally degrade as many
31 # features in libuv and the runtime as possible, to ease portability.
34 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
35 SNAP_DEFINES=-DRUST_SNAPSHOT
39 define DEF_RUNTIME_TARGETS
41 ######################################################################
42 # Runtime (C++) library variables
43 ######################################################################
45 RUNTIME_CXXS_$(1) := \
47 rt/sync/lock_and_signal.cpp \
48 rt/sync/rust_thread.cpp \
51 rt/rust_run_program.cpp \
53 rt/rust_sched_loop.cpp \
54 rt/rust_sched_launcher.cpp \
55 rt/rust_sched_driver.cpp \
56 rt/rust_scheduler.cpp \
57 rt/rust_sched_reaper.cpp \
63 rt/rust_crate_map.cpp \
65 rt/rust_gc_metadata.cpp \
66 rt/rust_port_selector.cpp \
68 rt/circular_buffer.cpp \
69 rt/isaac/randport.cpp \
75 rt/memory_region.cpp \
77 rt/arch/$$(HOST_$(1))/context.cpp \
78 rt/arch/$$(HOST_$(1))/gpr.cpp
80 RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
82 RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
83 rt/arch/$$(HOST_$(1))/ccall.S \
84 rt/arch/$$(HOST_$(1))/record_sp.S
86 ifeq ($$(HOST_$(1)), i386)
87 LIBUV_ARCH_$(1) := ia32
89 LIBUV_ARCH_$(1) := x86_64
92 ifeq ($$(CFG_WINDOWSY), 1)
93 LIBUV_OSTYPE_$(1) := win
94 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
95 else ifeq ($(CFG_OSTYPE), apple-darwin)
96 LIBUV_OSTYPE_$(1) := mac
97 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/libuv.a
98 else ifeq ($(CFG_OSTYPE), unknown-freebsd)
99 LIBUV_OSTYPE_$(1) := unix/freebsd
100 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
102 LIBUV_OSTYPE_$(1) := unix/linux
103 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
106 RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX)
107 RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
108 -I $$(S)src/rt/arch/$$(HOST_$(1)) \
109 -I $$(S)src/rt/linenoise \
110 -I $$(S)src/libuv/include
111 RUNTIME_OBJS_$(1) := $$(RUNTIME_CXXS_$(1):rt/%.cpp=rt/$(1)/%.o) \
112 $$(RUNTIME_CS_$(1):rt/%.c=rt/$(1)/%.o) \
113 $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
114 ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1))
116 MORESTACK_OBJ_$(1) := rt/$(1)/arch/$$(HOST_$(1))/morestack.o
117 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))
119 RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
121 rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
122 @$$(call E, compile: $$@)
123 $$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
124 $$(SNAP_DEFINES)) $$<
126 rt/$(1)/%.o: rt/%.c $$(MKFILE_DEPS)
127 @$$(call E, compile: $$@)
128 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
129 $$(SNAP_DEFINES)) $$<
131 rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) \
132 $$(LLVM_CONFIG_$$(CFG_HOST_TRIPLE))
133 @$$(call E, compile: $$@)
134 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
136 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1))
137 @$$(call E, link: $$@)
140 rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
141 $$(RUNTIME_DEF_$(1)) \
142 $$(RUNTIME_LIBS_$(1))
143 @$$(call E, link: $$@)
144 $$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
145 $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \
146 $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME))
148 # FIXME: For some reason libuv's makefiles can't figure out the
149 # correct definition of CC on the mingw I'm using, so we are
150 # explicitly using gcc. Also, we have to list environment variables
151 # first on windows... mysterious
153 ifdef CFG_ENABLE_FAST_MAKE
154 LIBUV_DEPS := $$(S)/.gitmodules
156 LIBUV_DEPS := $$(wildcard \
159 $$(S)src/libuv/*/*/* \
160 $$(S)src/libuv/*/*/*/*)
163 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
164 $$(Q)$$(MAKE) -C $$(S)mk/libuv/$$(LIBUV_ARCH_$(1))/$$(LIBUV_OSTYPE_$(1)) \
165 CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
166 LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
167 CC="$$(CFG_GCCISH_CROSS)$$(CC)" \
168 CXX="$$(CFG_GCCISH_CROSS)$$(CXX)" \
169 AR="$$(CFG_GCCISH_CROSS)$$(AR)" \
171 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
172 V=$$(VERBOSE) FLOCK= uv
174 # These could go in rt.mk or rustllvm.mk, they're needed for both.
176 # This regexp has a single $, escaped twice
177 %.bsd.def: %.def.in $$(MKFILE_DEPS)
178 @$$(call E, def: $$@)
180 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
181 $$(Q)echo "};" >> $$@
183 %.linux.def: %.def.in $$(MKFILE_DEPS)
184 @$$(call E, def: $$@)
186 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
187 $$(Q)echo "};" >> $$@
189 %.darwin.def: %.def.in $$(MKFILE_DEPS)
190 @$$(call E, def: $$@)
191 $$(Q)sed 's/^./_&/' $$< > $$@
194 %.def: %.def.in $$(MKFILE_DEPS)
195 @$$(call E, def: $$@)
196 $$(Q)echo LIBRARY $$* > $$@
197 $$(Q)echo EXPORTS >> $$@
198 $$(Q)sed 's/^./ &/' $$< >> $$@
203 # Instantiate template for all stages
204 $(foreach target,$(CFG_TARGET_TRIPLES), \
205 $(eval $(call DEF_RUNTIME_TARGETS,$(target))))