rt.mk 6.7 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
N
Niko Matsakis 已提交
29

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


39 40
define DEF_RUNTIME_TARGETS

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

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

78
RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
79

80 81
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
                  rt/arch/$$(HOST_$(1))/ccall.S \
82
                  rt/arch/$$(HOST_$(1))/record_sp.S
83

84 85
ifeq ($$(HOST_$(1)), i386)
  LIBUV_ARCH_$(1) := ia32
E
Erick Tryzelaar 已提交
86
else
87
  LIBUV_ARCH_$(1) := x86_64
E
Erick Tryzelaar 已提交
88 89
endif

90 91
ifeq ($$(CFG_WINDOWSY), 1)
  LIBUV_OSTYPE_$(1) := win
92
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
93 94
else ifeq ($(CFG_OSTYPE), apple-darwin)
  LIBUV_OSTYPE_$(1) := mac
95
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
U
User Jyyou 已提交
96
else ifeq ($(CFG_OSTYPE), unknown-freebsd)
J
Jyun-Yan You 已提交
97
  LIBUV_OSTYPE_$(1) := unix/freebsd
98
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
99
else
J
Jyun-Yan You 已提交
100
  LIBUV_OSTYPE_$(1) := unix/linux
101
  LIBUV_LIB_$(1) := rt/$(1)/libuv/libuv.a
102
endif
G
Graydon Hoare 已提交
103

104
RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX)
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 136 137
	@$$(call E, link: $$@)
	$$(Q)ar rcs $$@ $$<

138 139 140
rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \
                        $$(RUNTIME_DEF_$(1)) \
                        $$(RUNTIME_LIBS_$(1))
141
	@$$(call E, link: $$@)
142
	$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
143 144
	  $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \
	  $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME))
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

161
ifdef CFG_WINDOWSY
162 163 164 165 166
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
		OS=mingw \
		V=$$(VERBOSE)
167
else
168
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
169
	$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
170
		CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
171
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
172
		V=$$(VERBOSE)
173 174
endif

G
Graydon Hoare 已提交
175 176 177

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

178
# This regexp has a single $, escaped twice
U
User Jyyou 已提交
179 180 181 182 183 184
%.bsd.def:    %.def.in $$(MKFILE_DEPS)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@

185
%.linux.def:    %.def.in $$(MKFILE_DEPS)
186 187
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
188
	$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
189
	$$(Q)echo "};" >> $$@
G
Graydon Hoare 已提交
190

191
%.darwin.def:	%.def.in $$(MKFILE_DEPS)
192 193
	@$$(call E, def: $$@)
	$$(Q)sed 's/^./_&/' $$< > $$@
G
Graydon Hoare 已提交
194 195

ifdef CFG_WINDOWSY
196
%.def:	%.def.in $$(MKFILE_DEPS)
197 198 199 200
	@$$(call E, def: $$@)
	$$(Q)echo LIBRARY $$* > $$@
	$$(Q)echo EXPORTS >> $$@
	$$(Q)sed 's/^./    &/' $$< >> $$@
G
Graydon Hoare 已提交
201
endif
202 203 204 205 206 207

endef

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