]> git.lizzy.rs Git - rust.git/blob - mk/rt.mk
Merge remote-tracking branch 'brson/repl'
[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
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.
32
33 SNAP_DEFINES:=
34 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
35         SNAP_DEFINES=-DRUST_SNAPSHOT
36 endif
37
38
39 define DEF_RUNTIME_TARGETS
40
41 ######################################################################
42 # Runtime (C++) library variables
43 ######################################################################
44
45 RUNTIME_CXXS_$(1) := \
46               rt/sync/timer.cpp \
47               rt/sync/lock_and_signal.cpp \
48               rt/sync/rust_thread.cpp \
49               rt/rust.cpp \
50               rt/rust_builtin.cpp \
51               rt/rust_run_program.cpp \
52               rt/rust_env.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 \
58               rt/rust_task.cpp \
59               rt/rust_stack.cpp \
60               rt/rust_port.cpp \
61               rt/rust_upcall.cpp \
62               rt/rust_uv.cpp \
63               rt/rust_crate_map.cpp \
64               rt/rust_log.cpp \
65               rt/rust_gc_metadata.cpp \
66               rt/rust_port_selector.cpp \
67               rt/rust_util.cpp \
68               rt/circular_buffer.cpp \
69               rt/isaac/randport.cpp \
70               rt/miniz.cpp \
71               rt/rust_kernel.cpp \
72               rt/rust_shape.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
80 RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
81
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
85
86 ifeq ($$(HOST_$(1)), i386)
87   LIBUV_ARCH_$(1) := ia32
88 else
89   LIBUV_ARCH_$(1) := x86_64
90 endif
91
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
101 else
102   LIBUV_OSTYPE_$(1) := unix/linux
103   LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
104 endif
105
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))
115
116 MORESTACK_OBJ_$(1) := rt/$(1)/arch/$$(HOST_$(1))/morestack.o
117 ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))
118
119 RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))
120
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)) $$<
125
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)) $$<
130
131 rt/$(1)/%.o: rt/%.S  $$(MKFILE_DEPS) \
132                      $$(LLVM_CONFIG_$$(CFG_HOST_TRIPLE))
133         @$$(call E, compile: $$@)
134         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
135
136 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1))
137         @$$(call E, link: $$@)
138         $$(Q)ar rcs $$@ $$<
139
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))
147
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
152
153 ifdef CFG_ENABLE_FAST_MAKE
154 LIBUV_DEPS := $$(S)/.gitmodules
155 else
156 LIBUV_DEPS := $$(wildcard \
157               $$(S)src/libuv/* \
158               $$(S)src/libuv/*/* \
159               $$(S)src/libuv/*/*/* \
160               $$(S)src/libuv/*/*/*/*)
161 endif
162
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)" \
170                 BUILDTYPE=Release \
171                 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
172                 V=$$(VERBOSE) FLOCK= uv
173
174 # These could go in rt.mk or rustllvm.mk, they're needed for both.
175
176 # This regexp has a single $, escaped twice
177 %.bsd.def:    %.def.in $$(MKFILE_DEPS)
178         @$$(call E, def: $$@)
179         $$(Q)echo "{" > $$@
180         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
181         $$(Q)echo "};" >> $$@
182
183 %.linux.def:    %.def.in $$(MKFILE_DEPS)
184         @$$(call E, def: $$@)
185         $$(Q)echo "{" > $$@
186         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
187         $$(Q)echo "};" >> $$@
188
189 %.darwin.def:   %.def.in $$(MKFILE_DEPS)
190         @$$(call E, def: $$@)
191         $$(Q)sed 's/^./_&/' $$< > $$@
192
193 ifdef CFG_WINDOWSY
194 %.def:  %.def.in $$(MKFILE_DEPS)
195         @$$(call E, def: $$@)
196         $$(Q)echo LIBRARY $$* > $$@
197         $$(Q)echo EXPORTS >> $$@
198         $$(Q)sed 's/^./    &/' $$< >> $$@
199 endif
200
201 endef
202
203 # Instantiate template for all stages
204 $(foreach target,$(CFG_TARGET_TRIPLES), \
205  $(eval $(call DEF_RUNTIME_TARGETS,$(target))))