rt.mk 6.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 26 27
# 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). 

define DEF_RUNTIME_TARGETS

G
Graydon Hoare 已提交
28 29 30 31
######################################################################
# Runtime (C++) library variables
######################################################################

32 33
RUNTIME_CS_$(1) := \
              rt/sync/timer.cpp \
G
Graydon Hoare 已提交
34 35 36 37 38 39
              rt/sync/sync.cpp \
              rt/sync/lock_and_signal.cpp \
              rt/rust.cpp \
              rt/rust_builtin.cpp \
              rt/rust_run_program.cpp \
              rt/rust_crate_cache.cpp \
40
              rt/rust_env.cpp \
41
              rt/rust_scheduler.cpp \
G
Graydon Hoare 已提交
42 43 44 45 46
              rt/rust_task.cpp \
              rt/rust_task_list.cpp \
              rt/rust_chan.cpp \
              rt/rust_port.cpp \
              rt/rust_upcall.cpp \
R
Rob Arnold 已提交
47
              rt/rust_uv.cpp \
G
Graydon Hoare 已提交
48 49 50 51 52 53
              rt/rust_log.cpp \
              rt/rust_timer.cpp \
              rt/circular_buffer.cpp \
              rt/isaac/randport.cpp \
              rt/rust_srv.cpp \
              rt/rust_kernel.cpp \
54
              rt/rust_shape.cpp \
55
              rt/rust_obstack.cpp \
P
Patrick Walton 已提交
56
              rt/rust_gc.cpp \
57
              rt/rust_abi.cpp \
58
              rt/rust_cc.cpp \
59
              rt/rust_debug.cpp \
G
Graydon Hoare 已提交
60
              rt/memory_region.cpp \
61 62
              rt/test/rust_test_harness.cpp \
              rt/test/rust_test_runtime.cpp \
N
Niko Matsakis 已提交
63
              rt/test/rust_test_util.cpp \
64
              rt/arch/$$(HOST_$(1))/context.cpp
65

66 67 68
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
                  rt/arch/$$(HOST_$(1))/ccall.S \
                  rt/arch/$$(HOST_$(1))/morestack.S
69

70
RUNTIME_HDR_$(1) := rt/globals.h \
G
Graydon Hoare 已提交
71
               rt/rust.h \
B
Brian Anderson 已提交
72 73 74 75
               rt/rust_abi.h \
               rt/rust_cc.h \
               rt/rust_debug.h \
               rt/rust_gc.h \
G
Graydon Hoare 已提交
76 77 78
               rt/rust_internal.h \
               rt/rust_util.h \
               rt/rust_chan.h \
79
               rt/rust_env.h \
B
Brian Anderson 已提交
80 81 82
               rt/rust_obstack.h \
               rt/rust_unwind.h \
               rt/rust_upcall.h \
G
Graydon Hoare 已提交
83
               rt/rust_port.h \
84
               rt/rust_scheduler.h \
B
Brian Anderson 已提交
85
               rt/rust_shape.h \
G
Graydon Hoare 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
               rt/rust_task.h \
               rt/rust_task_list.h \
               rt/rust_log.h \
               rt/circular_buffer.h \
               rt/util/array_list.h \
               rt/util/indexed_list.h \
               rt/util/synchronized_indexed_list.h \
               rt/util/hash_map.h \
               rt/sync/sync.h \
               rt/sync/timer.h \
               rt/sync/lock_and_signal.h \
               rt/sync/lock_free_queue.h \
               rt/rust_srv.h \
               rt/rust_kernel.h \
               rt/memory_region.h \
               rt/memory.h \
102 103 104
               rt/test/rust_test_harness.h \
               rt/test/rust_test_runtime.h \
               rt/test/rust_test_util.h \
105
               rt/arch/$$(HOST_$(1))/context.h
G
Graydon Hoare 已提交
106

107 108
ifeq ($$(HOST_$(1)), i386)
  LIBUV_ARCH_$(1) := ia32
E
Erick Tryzelaar 已提交
109
else
110
  LIBUV_ARCH_$(1) := x86_64
E
Erick Tryzelaar 已提交
111 112
endif

113 114 115 116 117 118 119 120 121 122
ifeq ($$(CFG_WINDOWSY), 1)
  LIBUV_OSTYPE_$(1) := win
  LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/rt/libuv/libuv.a
else ifeq ($(CFG_OSTYPE), apple-darwin)
  LIBUV_OSTYPE_$(1) := mac
  LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/libuv.a
else
  LIBUV_OSTYPE_$(1) := unix
  LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/rt/libuv/libuv.a
endif
G
Graydon Hoare 已提交
123

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX)
RUNTIME_INCS_$(1) := -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
                -I $$(S)src/rt/arch/$$(HOST_$(1)) \
				-I $$(S)src/rt/libuv/include
RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \
                     $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o)
RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1))

rt/$(1)/%.o: rt/%.cpp $$(MKFILES)
	@$$(call E, compile: $$@)
	$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$<

rt/$(1)/%.o: rt/%.S $$(MKFILES)
	@$$(call E, compile: $$@)
	$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$<

rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILES) \
			  				 $$(RUNTIME_HDR_$(1)) \
                             $$(RUNTIME_DEF_$(1)) \
                             $$(RUNTIME_LIBS_$(1))
	@$$(call E, link: $$@)
	$$(Q)$$(call CFG_LINK_C_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \
	  $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \
	  $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME))
148

B
Brian Anderson 已提交
149 150 151
# 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
152 153 154 155 156 157 158 159 160 161 162 163
$$(LIBUV_LIB_$(1)): $$(wildcard \
                     $$(S)src/rt/libuv/* \
                     $$(S)src/rt/libuv/*/* \
                     $$(S)src/rt/libuv/*/*/* \
                     $$(S)src/rt/libuv/*/*/*/*)
	$$(Q)$$(MAKE) -C $$(S)mk/libuv/$$(LIBUV_ARCH_$(1))/$$(LIBUV_OSTYPE_$(1)) \
		CFLAGS="$$(TAR_CFLAGS)" LDFLAGS="-m32" \
		CC="$$(CFG_GCCISH_CROSS)$$(CC)" \
		CXX="$$(CFG_GCCISH_CROSS)$$(CXX)" \
		AR="$$(CFG_GCCISH_CROSS)$$(AR)" \
		builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
		V=$$(VERBOSE) FLOCK= uv
G
Graydon Hoare 已提交
164 165 166

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

167 168 169 170 171
%.linux.def:    %.def.in $$(MKFILES)
	@$$(call E, def: $$@)
	$$(Q)echo "{" > $$@
	$$(Q)sed 's/.$$/&;/' $$< >> $$@
	$$(Q)echo "};" >> $$@
G
Graydon Hoare 已提交
172

173 174 175
%.darwin.def:	%.def.in $$(MKFILES)
	@$$(call E, def: $$@)
	$$(Q)sed 's/^./_&/' $$< > $$@
G
Graydon Hoare 已提交
176 177

ifdef CFG_WINDOWSY
178 179 180 181 182
%.def:	%.def.in $$(MKFILES)
	@$$(call E, def: $$@)
	$$(Q)echo LIBRARY $$* > $$@
	$$(Q)echo EXPORTS >> $$@
	$$(Q)sed 's/^./    &/' $$< >> $$@
G
Graydon Hoare 已提交
183
endif
184 185 186 187 188 189

endef

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