rt.mk 8.9 KB
Newer Older
1
# This is a procedure to define the targets for building
2
# the runtime.
3 4 5 6 7
#
# Argument 1 is the target triple.
#
# This is not really the right place to explain this, but
# for those of you who are not Makefile gurus, let me briefly
8
# cover the $ expansion system in use here, because it
9 10 11
# confused me for a while!  The variable DEF_RUNTIME_TARGETS
# will be defined once and then expanded with different
# values substituted for $(1) each time it is called.
12
# That resulting text is then eval'd.
13 14 15 16 17
#
# For most variables, you could use a single $ sign.  The result
# is that the substitution would occur when the CALL occurs,
# I believe.  The problem is that the automatic variables $< and $@
# need to be expanded-per-rule.  Therefore, for those variables at
18
# least, you need $$< and $$@ in the variable text.  This way, after
19 20 21 22
# the CALL substitution occurs, you will have $< and $@.  This text
# will then be evaluated, and all will work as you like.
#
# Reader beware, this explanantion could be wrong, but it seems to
23 24
# fit the experimental data (i.e., I was able to get the system
# working under these assumptions).
25

N
Niko Matsakis 已提交
26
# Hack for passing flags into LIBUV, see below.
27 28
LIBUV_FLAGS_i386 = -m32 -fPIC
LIBUV_FLAGS_x86_64 = -m64 -fPIC
J
Jyun-Yan You 已提交
29
ifeq ($(OSTYPE_$(1)), linux-androideabi)
Y
Young-il Choi 已提交
30
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
J
Jyun-Yan You 已提交
31 32 33
else
LIBUV_FLAGS_arm = -fPIC -std=gnu99
endif
J
Jyun-Yan You 已提交
34
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
N
Niko Matsakis 已提交
35

36 37 38 39 40 41 42 43
# when we're doing a snapshot build, we intentionally degrade as many
# features in libuv and the runtime as possible, to ease portability.

SNAP_DEFINES:=
ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))),)
	SNAP_DEFINES=-DRUST_SNAPSHOT
endif

44 45
define DEF_RUNTIME_TARGETS

G
Graydon Hoare 已提交
46 47 48 49
######################################################################
# Runtime (C++) library variables
######################################################################

50 51 52 53 54 55 56
# $(1) is the target triple
# $(2) is the stage number

RUNTIME_CFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)
RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE$(2)

RUNTIME_CXXS_$(1)_$(2) := \
57
              rt/sync/timer.cpp \
G
Graydon Hoare 已提交
58
              rt/sync/lock_and_signal.cpp \
59
              rt/sync/rust_thread.cpp \
G
Graydon Hoare 已提交
60 61 62
              rt/rust.cpp \
              rt/rust_builtin.cpp \
              rt/rust_run_program.cpp \
63
              rt/rust_env.cpp \
64
              rt/rust_rng.cpp \
65
              rt/rust_sched_loop.cpp \
66
              rt/rust_sched_launcher.cpp \
67
              rt/rust_sched_driver.cpp \
68
              rt/rust_scheduler.cpp \
B
Brian Anderson 已提交
69
              rt/rust_sched_reaper.cpp \
G
Graydon Hoare 已提交
70
              rt/rust_task.cpp \
71
              rt/rust_stack.cpp \
G
Graydon Hoare 已提交
72
              rt/rust_upcall.cpp \
73
              rt/rust_uv.cpp \
74
              rt/rust_crate_map.cpp \
G
Graydon Hoare 已提交
75
              rt/rust_log.cpp \
76
              rt/rust_gc_metadata.cpp \
77
              rt/rust_util.cpp \
78
              rt/rust_exchange_alloc.cpp \
G
Graydon Hoare 已提交
79
              rt/isaac/randport.cpp \
80
              rt/miniz.cpp \
G
Graydon Hoare 已提交
81
              rt/rust_kernel.cpp \
82
              rt/rust_abi.cpp \
83
              rt/rust_debug.cpp \
G
Graydon Hoare 已提交
84
              rt/memory_region.cpp \
85
              rt/boxed_region.cpp \
86
              rt/arch/$$(HOST_$(1))/context.cpp \
Y
Young-il Choi 已提交
87
              rt/arch/$$(HOST_$(1))/gpr.cpp \
88 89
              rt/rust_android_dummy.cpp \
              rt/rust_test_helpers.cpp
90

91
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
92

93 94 95
RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
			rt/arch/$$(HOST_$(1))/ccall.S \
			rt/arch/$$(HOST_$(1))/record_sp.S
96

97
ifeq ($$(CFG_WINDOWSY_$(1)), 1)
98 99
  LIBUV_OSTYPE_$(1)_$(2) := win
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
100
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
101
else ifeq ($(OSTYPE_$(1)), apple-darwin)
102 103
  LIBUV_OSTYPE_$(1)_$(2) := mac
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
104
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
105
else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
106 107
  LIBUV_OSTYPE_$(1)_$(2) := unix/freebsd
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
108
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
109
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
110 111
  LIBUV_OSTYPE_$(1)_$(2) := unix/android
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
112
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
113
else
114 115
  LIBUV_OSTYPE_$(1)_$(2) := unix/linux
  LIBUV_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/libuv/libuv.a
D
Daniel Micay 已提交
116
  JEMALLOC_LIB_$(1)_$(2) := rt/$(1)/stage$(2)/jemalloc/lib/libjemalloc_pic.a
117
endif
G
Graydon Hoare 已提交
118

119 120
RUNTIME_DEF_$(1)_$(2) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
121 122 123
                     -I $$(S)src/rt/arch/$$(HOST_$(1)) \
                     -I $$(S)src/rt/linenoise \
                     -I $$(S)src/libuv/include
124 125 126 127
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=rt/$(1)/stage$(2)/%.o) \
                     $$(RUNTIME_CS_$(1)_$(2):rt/%.c=rt/$(1)/stage$(2)/%.o) \
                     $$(RUNTIME_S_$(1)_$(2):rt/%.S=rt/$(1)/stage$(2)/%.o)
ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
128

129 130
MORESTACK_OBJ_$(1)_$(2) := rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/morestack.o
ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
131

132
rt/$(1)/stage$(2)/%.o: rt/%.cpp $$(MKFILE_DEPS)
133
	@$$(call E, compile: $$@)
134 135
	$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
                 $$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
136

137
rt/$(1)/stage$(2)/%.o: rt/%.c $$(MKFILE_DEPS)
138
	@$$(call E, compile: $$@)
139 140
	$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
                 $$(SNAP_DEFINES) $$(RUNTIME_CFLAGS_$(1)_$(2))) $$<
141

142
rt/$(1)/stage$(2)/%.o: rt/%.S  $$(MKFILE_DEPS) \
143
                     $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
144
	@$$(call E, compile: $$@)
145
	$$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
146

147
rt/$(1)/stage$(2)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)_$(2))
148
	@$$(call E, link: $$@)
149
	$$(Q)$(AR_$(1)) rcs $$@ $$<
150

151
rt/$(1)/stage$(2)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
D
Daniel Micay 已提交
152
                        $$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1)_$(2)) $$(JEMALLOC_LIB_$(1)_$(2))
153
	@$$(call E, link: $$@)
154
	$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
D
Daniel Micay 已提交
155
	  $$(JEMALLOC_LIB_$(1)_$(2)) $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(LIBUV_LIB_$(1)_$(2)) \
156
	  $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
157

M
Michael Sullivan 已提交
158 159 160 161
# FIXME: For some reason libuv's makefiles can't figure out the
# correct definition of CC on the mingw I'm using, so we are
# explicitly using gcc. Also, we have to list environment variables
# first on windows... mysterious
162 163 164 165 166 167 168 169 170 171 172

ifdef CFG_ENABLE_FAST_MAKE
LIBUV_DEPS := $$(S)/.gitmodules
else
LIBUV_DEPS := $$(wildcard \
              $$(S)src/libuv/* \
              $$(S)src/libuv/*/* \
              $$(S)src/libuv/*/*/* \
              $$(S)src/libuv/*/*/*/*)
endif

B
Brian Anderson 已提交
173
# XXX: Shouldn't need platform-specific conditions here
174
ifdef CFG_WINDOWSY_$(1)
175
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
176
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
177
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
178 179
		OS=mingw \
		V=$$(VERBOSE)
180
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
181
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
Y
Young-il Choi 已提交
182
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
183 184
		CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
B
Brian Anderson 已提交
185 186 187
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
Y
Young-il Choi 已提交
188
		BUILDTYPE=Release \
189
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
Y
Young-il Choi 已提交
190
		host=android OS=linux \
191
		V=$$(VERBOSE)
Y
Young-il Choi 已提交
192
else
193
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
194
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
195 196
		CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
J
Jyun-Yan You 已提交
197 198 199
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
200
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
201
		V=$$(VERBOSE)
202 203
endif

D
Daniel Micay 已提交
204 205 206
$$(JEMALLOC_LIB_$(1)_$(2)):
	cd $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc; $(S)src/rt/jemalloc/configure --disable-experimental
	$$(Q)$$(MAKE) -C $$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/jemalloc
G
Graydon Hoare 已提交
207 208 209

# These could go in rt.mk or rustllvm.mk, they're needed for both.

210
# This regexp has a single $, escaped twice
U
User Jyyou 已提交
211 212 213 214 215 216
%.bsd.def:    %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

217
%.linux.def:    %.def.in $$(MKFILE_DEPS)
218 219
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
220
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
221
	$$(Q)echo "};" >> $$@
G
Graydon Hoare 已提交
222

223 224 225 226
%.darwin.def:	%.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)sed 's/^./_&/' $$< > $$@

Y
Young-il Choi 已提交
227 228 229 230 231 232
%.android.def:  %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

233
%.mingw32.def:	%.def.in $$(MKFILE_DEPS)
234 235 236 237 238 239 240 241
	@$$(call E, def: $$@)
	$$(Q)echo LIBRARY $$* > $$@
	$$(Q)echo EXPORTS >> $$@
	$$(Q)sed 's/^./    &/' $$< >> $$@

endef

# Instantiate template for all stages
242 243 244
$(foreach stage,$(STAGES), \
	$(foreach target,$(CFG_TARGET_TRIPLES), \
	 $(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))