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 define DEF_RUNTIME_TARGETS
32 ######################################################################
33 # Runtime (C++) library variables
34 ######################################################################
38 rt/sync/lock_and_signal.cpp \
39 rt/sync/rust_thread.cpp \
42 rt/rust_run_program.cpp \
43 rt/rust_crate_cache.cpp \
45 rt/rust_task_thread.cpp \
46 rt/rust_scheduler.cpp \
49 rt/rust_task_list.cpp \
55 rt/circular_buffer.cpp \
56 rt/isaac/randport.cpp \
64 rt/memory_region.cpp \
66 rt/arch/$$(HOST_$(1))/context.cpp
68 RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
69 rt/arch/$$(HOST_$(1))/ccall.S \
70 rt/arch/$$(HOST_$(1))/record_sp.S
72 RUNTIME_HDR_$(1) := rt/globals.h \
84 rt/rust_task_thread.h \
91 rt/circular_buffer.h \
92 rt/util/array_list.h \
93 rt/util/indexed_list.h \
94 rt/util/synchronized_indexed_list.h \
98 rt/sync/lock_and_signal.h \
99 rt/sync/lock_free_queue.h \
100 rt/sync/rust_thread.h \
105 rt/arch/$$(HOST_$(1))/context.h \
106 rt/arch/$$(HOST_$(1))/regs.h
108 ifeq ($$(HOST_$(1)), i386)
109 LIBUV_ARCH_$(1) := ia32
111 LIBUV_ARCH_$(1) := x86_64
114 ifeq ($$(CFG_WINDOWSY), 1)
115 LIBUV_OSTYPE_$(1) := win
116 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
117 else ifeq ($(CFG_OSTYPE), apple-darwin)
118 LIBUV_OSTYPE_$(1) := mac
119 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/libuv.a
120 else ifeq ($(CFG_OSTYPE), unknown-freebsd)
121 LIBUV_OSTYPE_$(1) := unix/freebsd
122 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
124 LIBUV_OSTYPE_$(1) := unix/linux
125 LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
128 RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX)
129 RUNTIME_INCS_$(1) := -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/libuv/include
132 RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \
133 $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
134 RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
136 rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
137 @$$(call E, compile: $$@)
138 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$<
140 rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) $$(LLVM_CONFIG_$$(CFG_HOST_TRIPLE))
141 @$$(call E, compile: $$@)
142 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
144 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: \
145 rt/$(1)/arch/$$(HOST_$(1))/morestack.o
146 @$$(call E, link: $$@)
149 rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
150 $$(RUNTIME_HDR_$(1)) \
151 $$(RUNTIME_DEF_$(1)) \
152 $$(RUNTIME_LIBS_$(1))
153 @$$(call E, link: $$@)
154 $$(Q)$$(call CFG_LINK_C_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
155 $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \
156 $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME))
158 # FIXME: For some reason libuv's makefiles can't figure out the correct definition
159 # of CC on the mingw I'm using, so we are explicitly using gcc. Also, we
160 # have to list environment variables first on windows... mysterious
161 $$(LIBUV_LIB_$(1)): $$(wildcard \
164 $$(S)src/libuv/*/*/* \
165 $$(S)src/libuv/*/*/*/*)
166 $$(Q)$$(MAKE) -C $$(S)mk/libuv/$$(LIBUV_ARCH_$(1))/$$(LIBUV_OSTYPE_$(1)) \
167 CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
168 LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
169 CC="$$(CFG_GCCISH_CROSS)$$(CC)" \
170 CXX="$$(CFG_GCCISH_CROSS)$$(CXX)" \
171 AR="$$(CFG_GCCISH_CROSS)$$(AR)" \
173 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
174 V=$$(VERBOSE) FLOCK= uv
176 # These could go in rt.mk or rustllvm.mk, they're needed for both.
178 # This regexp has a single $, escaped twice
179 %.bsd.def: %.def.in $$(MKFILE_DEPS)
180 @$$(call E, def: $$@)
182 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
183 $$(Q)echo "};" >> $$@
185 %.linux.def: %.def.in $$(MKFILE_DEPS)
186 @$$(call E, def: $$@)
188 $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
189 $$(Q)echo "};" >> $$@
191 %.darwin.def: %.def.in $$(MKFILE_DEPS)
192 @$$(call E, def: $$@)
193 $$(Q)sed 's/^./_&/' $$< > $$@
196 %.def: %.def.in $$(MKFILE_DEPS)
197 @$$(call E, def: $$@)
198 $$(Q)echo LIBRARY $$* > $$@
199 $$(Q)echo EXPORTS >> $$@
200 $$(Q)sed 's/^./ &/' $$< >> $$@
205 # Instantiate template for all stages
206 $(foreach target,$(CFG_TARGET_TRIPLES), \
207 $(eval $(call DEF_RUNTIME_TARGETS,$(target))))