]> git.lizzy.rs Git - rust.git/blob - mk/rt.mk
2ba8610f344ebcd47346d62aa82492d61507dd93
[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 define DEF_RUNTIME_TARGETS
31
32 ######################################################################
33 # Runtime (C++) library variables
34 ######################################################################
35
36 RUNTIME_CS_$(1) := \
37               rt/sync/timer.cpp \
38               rt/sync/lock_and_signal.cpp \
39               rt/sync/rust_thread.cpp \
40               rt/rust.cpp \
41               rt/rust_builtin.cpp \
42               rt/rust_run_program.cpp \
43               rt/rust_crate_cache.cpp \
44               rt/rust_env.cpp \
45               rt/rust_task_thread.cpp \
46               rt/rust_scheduler.cpp \
47               rt/rust_task.cpp \
48               rt/rust_stack.cpp \
49               rt/rust_task_list.cpp \
50               rt/rust_port.cpp \
51               rt/rust_upcall.cpp \
52               rt/rust_uv.cpp \
53               rt/rust_uvtmp.cpp \
54               rt/rust_log.cpp \
55               rt/circular_buffer.cpp \
56               rt/isaac/randport.cpp \
57               rt/rust_srv.cpp \
58               rt/rust_kernel.cpp \
59               rt/rust_shape.cpp \
60               rt/rust_obstack.cpp \
61               rt/rust_abi.cpp \
62               rt/rust_cc.cpp \
63               rt/rust_debug.cpp \
64               rt/memory_region.cpp \
65               rt/boxed_region.cpp \
66               rt/arch/$$(HOST_$(1))/context.cpp
67
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
71
72 RUNTIME_HDR_$(1) := rt/globals.h \
73                rt/rust.h \
74                rt/rust_abi.h \
75                rt/rust_cc.h \
76                rt/rust_debug.h \
77                rt/rust_internal.h \
78                rt/rust_util.h \
79                rt/rust_env.h \
80                rt/rust_obstack.h \
81                rt/rust_unwind.h \
82                rt/rust_upcall.h \
83                rt/rust_port.h \
84                rt/rust_task_thread.h \
85                rt/rust_scheduler.h \
86                rt/rust_shape.h \
87                rt/rust_task.h \
88                rt/rust_stack.h \
89                rt/rust_task_list.h \
90                rt/rust_log.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 \
95                rt/util/hash_map.h \
96                rt/sync/sync.h \
97                rt/sync/timer.h \
98                rt/sync/lock_and_signal.h \
99                rt/sync/lock_free_queue.h \
100                rt/sync/rust_thread.h \
101                rt/rust_srv.h \
102                rt/rust_kernel.h \
103                rt/memory_region.h \
104                rt/memory.h \
105                rt/arch/$$(HOST_$(1))/context.h \
106                rt/arch/$$(HOST_$(1))/regs.h
107
108 ifeq ($$(HOST_$(1)), i386)
109   LIBUV_ARCH_$(1) := ia32
110 else
111   LIBUV_ARCH_$(1) := x86_64
112 endif
113
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
123 else
124   LIBUV_OSTYPE_$(1) := unix/linux
125   LIBUV_LIB_$(1) := rt/$(1)/libuv/Release/obj.target/src/libuv/libuv.a
126 endif
127
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))
135
136 rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
137         @$$(call E, compile: $$@)
138         $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$<
139
140 rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) $$(LLVM_CONFIG_$$(CFG_HOST_TRIPLE))
141         @$$(call E, compile: $$@)
142         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
143
144 rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: \
145                 rt/$(1)/arch/$$(HOST_$(1))/morestack.o
146         @$$(call E, link: $$@)
147         $$(Q)ar rcs $$@ $$<
148
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))
157
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 \
162                      $$(S)src/libuv/* \
163                      $$(S)src/libuv/*/* \
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)" \
172                 BUILDTYPE=Release \
173                 builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
174                 V=$$(VERBOSE) FLOCK= uv
175
176 # These could go in rt.mk or rustllvm.mk, they're needed for both.
177
178 # This regexp has a single $, escaped twice
179 %.bsd.def:    %.def.in $$(MKFILE_DEPS)
180         @$$(call E, def: $$@)
181         $$(Q)echo "{" > $$@
182         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
183         $$(Q)echo "};" >> $$@
184
185 %.linux.def:    %.def.in $$(MKFILE_DEPS)
186         @$$(call E, def: $$@)
187         $$(Q)echo "{" > $$@
188         $$(Q)sed 's/.$$$$/&;/' $$< >> $$@
189         $$(Q)echo "};" >> $$@
190
191 %.darwin.def:   %.def.in $$(MKFILE_DEPS)
192         @$$(call E, def: $$@)
193         $$(Q)sed 's/^./_&/' $$< > $$@
194
195 ifdef CFG_WINDOWSY
196 %.def:  %.def.in $$(MKFILE_DEPS)
197         @$$(call E, def: $$@)
198         $$(Q)echo LIBRARY $$* > $$@
199         $$(Q)echo EXPORTS >> $$@
200         $$(Q)sed 's/^./    &/' $$< >> $$@
201 endif
202
203 endef
204
205 # Instantiate template for all stages
206 $(foreach target,$(CFG_TARGET_TRIPLES), \
207  $(eval $(call DEF_RUNTIME_TARGETS,$(target))))