rt.mk 7.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# This is a procedure to define the targets for building
# the runtime.  
#
# 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
# cover the $ expansion system in use here, because it 
# 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.
# That resulting text is then eval'd. 
#
# 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
# least, you need $$< and $$@ in the variable text.  This way, after 
# 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
# fit the experimental data (i.e., I was able to get the system 
# working under these assumptions). 

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
Y
Young-il Choi 已提交
29
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
J
Jyun-Yan You 已提交
30
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
N
Niko Matsakis 已提交
31

32 33 34 35 36 37 38 39 40
# 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


41 42
define DEF_RUNTIME_TARGETS

G
Graydon Hoare 已提交
43 44 45 46
######################################################################
# Runtime (C++) library variables
######################################################################

47
RUNTIME_CXXS_$(1) := \
48
              rt/sync/timer.cpp \
G
Graydon Hoare 已提交
49
              rt/sync/lock_and_signal.cpp \
50
              rt/sync/rust_thread.cpp \
G
Graydon Hoare 已提交
51 52 53
              rt/rust.cpp \
              rt/rust_builtin.cpp \
              rt/rust_run_program.cpp \
54
              rt/rust_env.cpp \
55
              rt/rust_rng.cpp \
56
              rt/rust_sched_loop.cpp \
57
              rt/rust_sched_launcher.cpp \
58
              rt/rust_sched_driver.cpp \
59
              rt/rust_scheduler.cpp \
B
Brian Anderson 已提交
60
              rt/rust_sched_reaper.cpp \
G
Graydon Hoare 已提交
61
              rt/rust_task.cpp \
62
              rt/rust_stack.cpp \
G
Graydon Hoare 已提交
63
              rt/rust_upcall.cpp \
64
              rt/rust_uv.cpp \
65
              rt/rust_crate_map.cpp \
G
Graydon Hoare 已提交
66
              rt/rust_log.cpp \
67
              rt/rust_gc_metadata.cpp \
68
              rt/rust_util.cpp \
69
              rt/rust_exchange_alloc.cpp \
G
Graydon Hoare 已提交
70
              rt/isaac/randport.cpp \
71
              rt/miniz.cpp \
G
Graydon Hoare 已提交
72
              rt/rust_kernel.cpp \
73
              rt/rust_abi.cpp \
74
              rt/rust_debug.cpp \
G
Graydon Hoare 已提交
75
              rt/memory_region.cpp \
76
              rt/boxed_region.cpp \
77
              rt/arch/$$(HOST_$(1))/context.cpp \
Y
Young-il Choi 已提交
78 79
              rt/arch/$$(HOST_$(1))/gpr.cpp \
              rt/rust_android_dummy.cpp
80

81
RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
82

83 84
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
                  rt/arch/$$(HOST_$(1))/ccall.S \
85
                  rt/arch/$$(HOST_$(1))/record_sp.S
86

87 88
ifeq ($$(CFG_WINDOWSY_$(1)), 1)
  LIBUV_OSTYPE_$(1) := win
Y
Young-il Choi 已提交
89
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
90
else ifeq ($(OSTYPE_$(1)), apple-darwin)
91
  LIBUV_OSTYPE_$(1) := mac
92
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
93
else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
94
  LIBUV_OSTYPE_$(1) := unix/freebsd
95
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
96
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
97
  LIBUV_OSTYPE_$(1) := unix/android
98
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
99
else
100
  LIBUV_OSTYPE_$(1) := unix/linux
101
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
102
endif
G
Graydon Hoare 已提交
103

Y
Young-il Choi 已提交
104
RUNTIME_DEF_$(1) := rt/rustrt$(CFG_DEF_SUFFIX_$(1))
105
RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
106 107 108 109 110
                     -I $$(S)src/rt/arch/$$(HOST_$(1)) \
                     -I $$(S)src/rt/linenoise \
                     -I $$(S)src/libuv/include
RUNTIME_OBJS_$(1) := $$(RUNTIME_CXXS_$(1):rt/%.cpp=rt/$(1)/%.o) \
                     $$(RUNTIME_CS_$(1):rt/%.c=rt/$(1)/%.o) \
111
                     $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
112 113 114 115 116
ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1))

MORESTACK_OBJ_$(1) := rt/$(1)/arch/$$(HOST_$(1))/morestack.o
ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1))

117 118
RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))

119
rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS)
120
	@$$(call E, compile: $$@)
121
	$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
122
                 $$(SNAP_DEFINES)) $$<
123

124
rt/$(1)/%.o: rt/%.c $$(MKFILE_DEPS)
125
	@$$(call E, compile: $$@)
126 127
	$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \
                 $$(SNAP_DEFINES)) $$<
128

129
rt/$(1)/%.o: rt/%.S  $$(MKFILE_DEPS) \
130
                     $$(LLVM_CONFIG_$$(CFG_BUILD_TRIPLE))
131
	@$$(call E, compile: $$@)
132
	$$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
133

134
rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1))
135
	@$$(call E, link: $$@)
136
	$$(Q)$(AR_$(1)) rcs $$@ $$<
137

Y
Young-il Choi 已提交
138
rt/$(1)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
139 140
                        $$(RUNTIME_DEF_$(1)) \
                        $$(RUNTIME_LIBS_$(1))
141
	@$$(call E, link: $$@)
142
	$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
Y
Young-il Choi 已提交
143
	  $$(CFG_GCCISH_POST_LIB_FLAGS_$(1)) $$(RUNTIME_LIBS_$(1)) \
144
	  $$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME_$(1)))
145

M
Michael Sullivan 已提交
146 147 148 149
# 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
150 151 152 153 154 155 156 157 158 159 160

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 已提交
161
# XXX: Shouldn't need platform-specific conditions here
162
ifdef CFG_WINDOWSY_$(1)
163 164 165 166 167
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
		OS=mingw \
		V=$$(VERBOSE)
168
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
Y
Young-il Choi 已提交
169 170 171 172
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
		CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
		LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
B
Brian Anderson 已提交
173 174 175
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
Y
Young-il Choi 已提交
176 177 178
		BUILDTYPE=Release \
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
		host=android OS=linux \
179
		V=$$(VERBOSE)
Y
Young-il Choi 已提交
180
else
181
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
182
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
183
		CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
J
Jyun-Yan You 已提交
184 185 186 187
		LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
		CC="$$(CC_$(1))" \
		CXX="$$(CXX_$(1))" \
		AR="$$(AR_$(1))" \
188
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
189
		V=$$(VERBOSE)
190 191
endif

G
Graydon Hoare 已提交
192 193 194

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

195
# This regexp has a single $, escaped twice
U
User Jyyou 已提交
196 197 198 199 200 201
%.bsd.def:    %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

202
%.linux.def:    %.def.in $$(MKFILE_DEPS)
203 204
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
205
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
206
	$$(Q)echo "};" >> $$@
G
Graydon Hoare 已提交
207

208 209 210 211
%.darwin.def:	%.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)sed 's/^./_&/' $$< > $$@

Y
Young-il Choi 已提交
212 213 214 215 216 217
%.android.def:  %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

218
%.mingw32.def:	%.def.in $$(MKFILE_DEPS)
219 220 221 222 223 224 225 226 227 228
	@$$(call E, def: $$@)
	$$(Q)echo LIBRARY $$* > $$@
	$$(Q)echo EXPORTS >> $$@
	$$(Q)sed 's/^./    &/' $$< >> $$@

endef

# Instantiate template for all stages
$(foreach target,$(CFG_TARGET_TRIPLES), \
 $(eval $(call DEF_RUNTIME_TARGETS,$(target))))