|
| 1 | +# This is a procedure to define the targets for building |
| 2 | +# the runtime. |
| 3 | +# |
| 4 | +# Argument 1 is the target triple. |
| 5 | +# |
| 6 | +# This is not really the right place to explain this, but |
| 7 | +# for those of you who are not Makefile gurus, let me briefly |
| 8 | +# cover the $ expansion system in use here, because it |
| 9 | +# confused me for a while! The variable DEF_RUNTIME_TARGETS |
| 10 | +# will be defined once and then expanded with different |
| 11 | +# values substituted for $(1) each time it is called. |
| 12 | +# That resulting text is then eval'd. |
| 13 | +# |
| 14 | +# For most variables, you could use a single $ sign. The result |
| 15 | +# is that the substitution would occur when the CALL occurs, |
| 16 | +# I believe. The problem is that the automatic variables $< and $@ |
| 17 | +# need to be expanded-per-rule. Therefore, for those variables at |
| 18 | +# least, you need $$< and $$@ in the variable text. This way, after |
| 19 | +# the CALL substitution occurs, you will have $< and $@. This text |
| 20 | +# will then be evaluated, and all will work as you like. |
| 21 | +# |
| 22 | +# Reader beware, this explanantion could be wrong, but it seems to |
| 23 | +# fit the experimental data (i.e., I was able to get the system |
| 24 | +# working under these assumptions). |
| 25 | + |
| 26 | +define DEF_RUNTIME_TARGETS |
| 27 | + |
1 | 28 | ######################################################################
|
2 | 29 | # Runtime (C++) library variables
|
3 | 30 | ######################################################################
|
4 | 31 |
|
5 |
| -RUNTIME_CS := rt/sync/timer.cpp \ |
| 32 | +RUNTIME_CS_$(1) := \ |
| 33 | + rt/sync/timer.cpp \ |
6 | 34 | rt/sync/sync.cpp \
|
7 | 35 | rt/sync/lock_and_signal.cpp \
|
8 | 36 | rt/rust.cpp \
|
@@ -33,15 +61,13 @@ RUNTIME_CS := rt/sync/timer.cpp \
|
33 | 61 | rt/test/rust_test_harness.cpp \
|
34 | 62 | rt/test/rust_test_runtime.cpp \
|
35 | 63 | rt/test/rust_test_util.cpp \
|
36 |
| - rt/arch/i386/context.cpp |
37 |
| - |
38 |
| -RUNTIME_LL := |
| 64 | + rt/arch/$$(HOST_$(1))/context.cpp |
39 | 65 |
|
40 |
| -RUNTIME_S := rt/arch/i386/_context.S \ |
41 |
| - rt/arch/i386/ccall.S \ |
42 |
| - rt/arch/i386/morestack.S |
| 66 | +RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \ |
| 67 | + rt/arch/$$(HOST_$(1))/ccall.S \ |
| 68 | + rt/arch/$$(HOST_$(1))/morestack.S |
43 | 69 |
|
44 |
| -RUNTIME_HDR := rt/globals.h \ |
| 70 | +RUNTIME_HDR_$(1) := rt/globals.h \ |
45 | 71 | rt/rust.h \
|
46 | 72 | rt/rust_abi.h \
|
47 | 73 | rt/rust_cc.h \
|
@@ -76,81 +102,88 @@ RUNTIME_HDR := rt/globals.h \
|
76 | 102 | rt/test/rust_test_harness.h \
|
77 | 103 | rt/test/rust_test_runtime.h \
|
78 | 104 | rt/test/rust_test_util.h \
|
79 |
| - rt/arch/i386/context.h |
| 105 | + rt/arch/$$(HOST_$(1))/context.h |
80 | 106 |
|
81 |
| -ifeq ($(CFG_WINDOWSY), 1) |
82 |
| - LIBUV_OSTYPE := win |
83 |
| - LIBUV_ARCH := ia32 |
84 |
| - LIBUV_LIB := rt/libuv/Default/obj.target/src/rt/libuv/libuv.a |
85 |
| -else ifeq ($(CFG_OSTYPE), apple-darwin) |
86 |
| - LIBUV_OSTYPE := mac |
87 |
| - LIBUV_ARCH := ia32 |
88 |
| - LIBUV_LIB := rt/libuv/Default/libuv.a |
| 107 | +ifeq ($$(HOST_$(1)), i386) |
| 108 | + LIBUV_ARCH_$(1) := ia32 |
89 | 109 | else
|
90 |
| - LIBUV_OSTYPE := unix |
91 |
| - LIBUV_ARCH := ia32 |
92 |
| - LIBUV_LIB := rt/libuv/Default/obj.target/src/rt/libuv/libuv.a |
| 110 | + LIBUV_ARCH_$(1) := x86_64 |
93 | 111 | endif
|
94 | 112 |
|
95 |
| -RUNTIME_DEF := rt/rustrt$(CFG_DEF_SUFFIX) |
96 |
| -RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash \ |
97 |
| - -I $(S)src/rt/arch/i386 \ |
98 |
| - -I $(S)src/rt/libuv/include |
99 |
| -RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o) $(RUNTIME_LL:.ll=.o) $(RUNTIME_S:.S=.o) |
100 |
| -RUNTIME_LIBS := $(LIBUV_LIB) |
101 |
| - |
102 |
| -RT_COMPILE_C := $(call CFG_COMPILE_C, $(0), $(1) -I $(S)src/rt/arch/$(2)) |
103 |
| - |
104 |
| -rt/%.o: rt/%.cpp $(MKFILES) |
105 |
| - @$(call E, compile: $@) |
106 |
| - $(Q)$(call CFG_COMPILE_C, $@, $(RUNTIME_INCS)) $< |
107 |
| - |
108 |
| -rt/%.o: rt/%.S $(MKFILES) |
109 |
| - @$(call E, compile: $@) |
110 |
| - $(Q)$(call CFG_COMPILE_C, $@, $(RUNTIME_INCS)) $< |
111 |
| - |
112 |
| -rt/%.o: rt/%.ll $(MKFILES) |
113 |
| - @$(call E, llc: $@) |
114 |
| - $(Q)$(LLC) -filetype=obj -relocation-model=pic -march=x86 -o $@ $< |
| 113 | +ifeq ($$(CFG_WINDOWSY), 1) |
| 114 | + LIBUV_OSTYPE_$(1) := win |
| 115 | + LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/rt/libuv/libuv.a |
| 116 | +else ifeq ($(CFG_OSTYPE), apple-darwin) |
| 117 | + LIBUV_OSTYPE_$(1) := mac |
| 118 | + LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/libuv.a |
| 119 | +else |
| 120 | + LIBUV_OSTYPE_$(1) := unix |
| 121 | + LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/rt/libuv/libuv.a |
| 122 | +endif |
115 | 123 |
|
116 |
| -rt/$(CFG_RUNTIME): $(RUNTIME_OBJS) $(MKFILES) $(RUNTIME_HDR) $(RUNTIME_DEF) $(RUNTIME_LIBS) |
117 |
| - @$(call E, link: $@) |
118 |
| - $(Q)$(call CFG_LINK_C,$@, $(RUNTIME_OBJS) \ |
119 |
| - $(CFG_GCCISH_POST_LIB_FLAGS) $(RUNTIME_LIBS) \ |
120 |
| - $(CFG_LIBUV_LINK_FLAGS),$(RUNTIME_DEF),$(CFG_RUNTIME)) |
| 124 | +RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX) |
| 125 | +RUNTIME_INCS_$(1) := -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \ |
| 126 | + -I $$(S)src/rt/arch/$$(HOST_$(1)) \ |
| 127 | + -I $$(S)src/rt/libuv/include |
| 128 | +RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \ |
| 129 | + $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o) |
| 130 | +RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1)) |
| 131 | + |
| 132 | +rt/$(1)/%.o: rt/%.cpp $$(MKFILES) |
| 133 | + @$$(call E, compile: $$@) |
| 134 | + $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$< |
| 135 | + |
| 136 | +rt/$(1)/%.o: rt/%.S $$(MKFILES) |
| 137 | + @$$(call E, compile: $$@) |
| 138 | + $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1))) $$< |
| 139 | + |
| 140 | +rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILES) \ |
| 141 | + $$(RUNTIME_HDR_$(1)) \ |
| 142 | + $$(RUNTIME_DEF_$(1)) \ |
| 143 | + $$(RUNTIME_LIBS_$(1)) |
| 144 | + @$$(call E, link: $$@) |
| 145 | + $$(Q)$$(call CFG_LINK_C_$(1),$$@, $$(RUNTIME_OBJS_$(1)) \ |
| 146 | + $$(CFG_GCCISH_POST_LIB_FLAGS) $$(RUNTIME_LIBS_$(1)) \ |
| 147 | + $$(CFG_LIBUV_LINK_FLAGS),$$(RUNTIME_DEF_$(1)),$$(CFG_RUNTIME)) |
121 | 148 |
|
122 | 149 | # FIXME: For some reason libuv's makefiles can't figure out the correct definition
|
123 | 150 | # of CC on the mingw I'm using, so we are explicitly using gcc. Also, we
|
124 | 151 | # have to list environment variables first on windows... mysterious
|
125 |
| -$(LIBUV_LIB): $(wildcard \ |
126 |
| - $(S)src/rt/libuv/* \ |
127 |
| - $(S)src/rt/libuv/*/* \ |
128 |
| - $(S)src/rt/libuv/*/*/* \ |
129 |
| - $(S)src/rt/libuv/*/*/*/*) |
130 |
| - $(Q)$(MAKE) -C $(S)mk/libuv/$(LIBUV_ARCH)/$(LIBUV_OSTYPE) \ |
131 |
| - CFLAGS="-m32" LDFLAGS="-m32" \ |
132 |
| - CC="$(CFG_GCCISH_CROSS)$(CC)" \ |
133 |
| - CXX="$(CFG_GCCISH_CROSS)$(CXX)" \ |
134 |
| - AR="$(CFG_GCCISH_CROSS)$(AR)" \ |
135 |
| - builddir_name="$(CFG_BUILD_DIR)/rt/libuv" \ |
136 |
| - V=$(VERBOSE) FLOCK= uv |
| 152 | +$$(LIBUV_LIB_$(1)): $$(wildcard \ |
| 153 | + $$(S)src/rt/libuv/* \ |
| 154 | + $$(S)src/rt/libuv/*/* \ |
| 155 | + $$(S)src/rt/libuv/*/*/* \ |
| 156 | + $$(S)src/rt/libuv/*/*/*/*) |
| 157 | + $$(Q)$$(MAKE) -C $$(S)mk/libuv/$$(LIBUV_ARCH_$(1))/$$(LIBUV_OSTYPE_$(1)) \ |
| 158 | + CFLAGS="$$(TAR_CFLAGS)" LDFLAGS="-m32" \ |
| 159 | + CC="$$(CFG_GCCISH_CROSS)$$(CC)" \ |
| 160 | + CXX="$$(CFG_GCCISH_CROSS)$$(CXX)" \ |
| 161 | + AR="$$(CFG_GCCISH_CROSS)$$(AR)" \ |
| 162 | + builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \ |
| 163 | + V=$$(VERBOSE) FLOCK= uv |
137 | 164 |
|
138 | 165 | # These could go in rt.mk or rustllvm.mk, they're needed for both.
|
139 | 166 |
|
140 |
| -%.linux.def: %.def.in $(MKFILES) |
141 |
| - @$(call E, def: $@) |
142 |
| - $(Q)echo "{" > $@ |
143 |
| - $(Q)sed 's/.$$/&;/' $< >> $@ |
144 |
| - $(Q)echo "};" >> $@ |
| 167 | +%.linux.def: %.def.in $$(MKFILES) |
| 168 | + @$$(call E, def: $$@) |
| 169 | + $$(Q)echo "{" > $$@ |
| 170 | + $$(Q)sed 's/.$$/&;/' $$< >> $$@ |
| 171 | + $$(Q)echo "};" >> $$@ |
145 | 172 |
|
146 |
| -%.darwin.def: %.def.in $(MKFILES) |
147 |
| - @$(call E, def: $@) |
148 |
| - $(Q)sed 's/^./_&/' $< > $@ |
| 173 | +%.darwin.def: %.def.in $$(MKFILES) |
| 174 | + @$$(call E, def: $$@) |
| 175 | + $$(Q)sed 's/^./_&/' $$< > $$@ |
149 | 176 |
|
150 | 177 | ifdef CFG_WINDOWSY
|
151 |
| -%.def: %.def.in $(MKFILES) |
152 |
| - @$(call E, def: $@) |
153 |
| - $(Q)echo LIBRARY $* > $@ |
154 |
| - $(Q)echo EXPORTS >> $@ |
155 |
| - $(Q)sed 's/^./ &/' $< >> $@ |
| 178 | +%.def: %.def.in $$(MKFILES) |
| 179 | + @$$(call E, def: $$@) |
| 180 | + $$(Q)echo LIBRARY $$* > $$@ |
| 181 | + $$(Q)echo EXPORTS >> $$@ |
| 182 | + $$(Q)sed 's/^./ &/' $$< >> $$@ |
156 | 183 | endif
|
| 184 | + |
| 185 | +endef |
| 186 | + |
| 187 | +# Instantiate template for all stages |
| 188 | +$(foreach target,$(CFG_TARGET_TRIPLES), \ |
| 189 | + $(eval $(call DEF_RUNTIME_TARGETS,$(target)))) |
0 commit comments