rust/mk/rt.mk

197 lines
6.8 KiB
Makefile
Raw Normal View History

# 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).
2011-11-01 23:05:56 -05:00
# Hack for passing flags into LIBUV, see below.
LIBUV_FLAGS_i386 = -m32
LIBUV_FLAGS_x86_64 = -m64
define DEF_RUNTIME_TARGETS
2011-05-01 15:18:52 -05:00
######################################################################
# Runtime (C++) library variables
######################################################################
RUNTIME_CS_$(1) := \
rt/sync/timer.cpp \
2011-05-01 15:18:52 -05:00
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 \
rt/rust_env.cpp \
rt/rust_scheduler.cpp \
2011-05-01 15:18:52 -05:00
rt/rust_task.cpp \
rt/rust_task_list.cpp \
rt/rust_chan.cpp \
rt/rust_port.cpp \
rt/rust_upcall.cpp \
2011-11-07 21:35:39 -06:00
rt/rust_aio.cpp \
2011-05-01 15:18:52 -05:00
rt/rust_log.cpp \
rt/rust_timer.cpp \
rt/circular_buffer.cpp \
rt/isaac/randport.cpp \
rt/rust_srv.cpp \
rt/rust_kernel.cpp \
rt/rust_shape.cpp \
rt/rust_obstack.cpp \
2011-08-18 20:48:32 -05:00
rt/rust_gc.cpp \
rt/rust_abi.cpp \
2011-09-20 18:47:59 -05:00
rt/rust_cc.cpp \
rt/rust_debug.cpp \
2011-05-01 15:18:52 -05:00
rt/memory_region.cpp \
rt/test/rust_test_harness.cpp \
rt/test/rust_test_runtime.cpp \
2011-10-13 19:11:28 -05:00
rt/test/rust_test_util.cpp \
rt/arch/$$(HOST_$(1))/context.cpp
2011-05-18 14:43:48 -05:00
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
rt/arch/$$(HOST_$(1))/ccall.S \
rt/arch/$$(HOST_$(1))/morestack.S
RUNTIME_HDR_$(1) := rt/globals.h \
2011-05-01 15:18:52 -05:00
rt/rust.h \
2011-10-05 19:41:01 -05:00
rt/rust_abi.h \
rt/rust_cc.h \
rt/rust_debug.h \
rt/rust_gc.h \
2011-05-01 15:18:52 -05:00
rt/rust_internal.h \
rt/rust_util.h \
rt/rust_chan.h \
rt/rust_env.h \
2011-10-05 19:41:01 -05:00
rt/rust_obstack.h \
rt/rust_unwind.h \
rt/rust_upcall.h \
2011-05-01 15:18:52 -05:00
rt/rust_port.h \
rt/rust_scheduler.h \
2011-10-05 19:41:01 -05:00
rt/rust_shape.h \
2011-05-01 15:18:52 -05:00
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 \
rt/test/rust_test_harness.h \
rt/test/rust_test_runtime.h \
rt/test/rust_test_util.h \
2011-11-08 19:07:11 -06:00
rt/arch/$$(HOST_$(1))/context.h \
rt/arch/$$(HOST_$(1))/regs.h
2011-05-01 15:18:52 -05:00
ifeq ($$(HOST_$(1)), i386)
LIBUV_ARCH_$(1) := ia32
else
LIBUV_ARCH_$(1) := x86_64
endif
ifeq ($$(CFG_WINDOWSY), 1)
LIBUV_OSTYPE_$(1) := win
2011-11-08 16:36:19 -06:00
LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/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
2011-11-08 16:36:19 -06:00
LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/libuv/libuv.a
endif
2011-05-01 15:18:52 -05:00
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)) \
2011-11-08 16:36:19 -06:00
-I $$(S)src/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))
2011-06-14 10:28:10 -05:00
2011-08-04 16:11:33 -05:00
# 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
$$(LIBUV_LIB_$(1)): $$(wildcard \
2011-11-08 16:36:19 -06:00
$$(S)src/libuv/* \
$$(S)src/libuv/*/* \
$$(S)src/libuv/*/*/* \
$$(S)src/libuv/*/*/*/*)
$$(Q)$$(MAKE) -C $$(S)mk/libuv/$$(LIBUV_ARCH_$(1))/$$(LIBUV_OSTYPE_$(1)) \
2011-11-01 23:05:56 -05:00
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
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
2011-05-01 15:18:52 -05:00
# These could go in rt.mk or rustllvm.mk, they're needed for both.
2011-11-02 16:22:07 -05:00
# This regexp has a single $, escaped twice
%.linux.def: %.def.in $$(MKFILES)
@$$(call E, def: $$@)
$$(Q)echo "{" > $$@
2011-11-02 16:22:07 -05:00
$$(Q)sed 's/.$$$$/&;/' $$< >> $$@
$$(Q)echo "};" >> $$@
2011-05-01 15:18:52 -05:00
%.darwin.def: %.def.in $$(MKFILES)
@$$(call E, def: $$@)
$$(Q)sed 's/^./_&/' $$< > $$@
2011-05-01 15:18:52 -05:00
ifdef CFG_WINDOWSY
%.def: %.def.in $$(MKFILES)
@$$(call E, def: $$@)
$$(Q)echo LIBRARY $$* > $$@
$$(Q)echo EXPORTS >> $$@
$$(Q)sed 's/^./ &/' $$< >> $$@
2011-05-01 15:18:52 -05:00
endif
endef
# Instantiate template for all stages
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_RUNTIME_TARGETS,$(target))))