1 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
11 # Basic support for producing installation images.
13 # The 'prepare' build target copies all release artifacts from the build
14 # directory to some other location, placing all binaries, libraries, and
15 # docs in their final locations relative to each other.
17 # It requires the following variables to be set:
19 # PREPARE_HOST - the host triple
20 # PREPARE_TARGETS - the target triples, space separated
21 # PREPARE_DEST_DIR - the directory to put the image
23 prepare: PREPARE_STAGE=2
24 prepare: PREPARE_DIR_CMD=$(DEFAULT_PREPARE_DIR_CMD)
25 prepare: PREPARE_BIN_CMD=$(DEFAULT_PREPARE_BIN_CMD)
26 prepare: PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD)
27 prepare: PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
30 prepare-base: PREPARE_SOURCE_DIR=$(PREPARE_HOST)/stage$(PREPARE_STAGE)
31 prepare-base: PREPARE_SOURCE_BIN_DIR=$(PREPARE_SOURCE_DIR)/bin
32 prepare-base: PREPARE_SOURCE_LIB_DIR=$(PREPARE_SOURCE_DIR)/$(CFG_LIBDIR_RELATIVE)
33 prepare-base: PREPARE_SOURCE_MAN_DIR=$(S)/man
34 prepare-base: PREPARE_DEST_BIN_DIR=$(PREPARE_DEST_DIR)/bin
35 prepare-base: PREPARE_DEST_LIB_DIR=$(PREPARE_DEST_DIR)/$(CFG_LIBDIR_RELATIVE)
36 prepare-base: PREPARE_DEST_MAN_DIR=$(PREPARE_DEST_DIR)/man1
37 prepare-base: prepare-host prepare-targets
39 prepare-everything: prepare-host prepare-targets
41 DEFAULT_PREPARE_DIR_CMD = umask 022 && mkdir -p
42 DEFAULT_PREPARE_BIN_CMD = install -m755
43 DEFAULT_PREPARE_LIB_CMD = install -m644
44 DEFAULT_PREPARE_MAN_CMD = install -m755
46 # On windows we install from stage3, but on unix only stage2
47 # Because of the way these rules are organized, preparing from any
48 # stage requires all these stages to be built
49 ifdef CFG_WINDOWSY_$(CFG_BUILD)
56 # $(1) is the directory
58 @$(Q)$(call E, install: $(1))
59 $(Q)$(PREPARE_DIR_CMD) $(1)
63 # $(1) is the filename/libname-glob
65 @$(call E, install: $(PREPARE_DEST_BIN_DIR)/$(1))
66 $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
69 # Copy a dylib or rlib
70 # $(1) is the filename/libname-glob
72 # XXX: Don't remove the $(nop) command below!
73 # Yeah, that's right, it's voodoo. Something in the way this macro is being expanded
74 # causes it to parse incorrectly. Throwing in that empty command seems to fix the
75 # problem. I'm sorry, just don't remove the $(nop), alright?
78 @$(call E, install: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
79 $(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
80 MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))),\
81 $(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
82 if [ -n "$$MATCHES" ]; then \
83 echo "warning: one or libraries matching Rust library '$(1)'" && \
84 echo " (other than '$$LIB_NAME' itself) already present" && \
85 echo " at destination $(PREPARE_WORKING_DEST_LIB_DIR):" && \
88 $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1) | tail -1` $(PREPARE_WORKING_DEST_LIB_DIR)/
94 @$(call E, install: $(PREPARE_DEST_MAN_DIR)/$(1))
95 $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
99 PREPARE_TOOLS = $(filter-out compiletest, $(TOOLS))
101 prepare-host: prepare-host-tools
103 prepare-host-tools: \
104 $(foreach tool, $(PREPARE_TOOLS),\
105 $(foreach stage,$(PREPARE_STAGES),\
106 $(foreach host,$(CFG_HOST),\
107 prepare-host-tool-$(tool)-$(stage)-$(host))))
110 $(call PREPARE_DIR,$(PREPARE_DEST_BIN_DIR))
111 $(call PREPARE_DIR,$(PREPARE_DEST_LIB_DIR))
112 $(call PREPARE_DIR,$(PREPARE_DEST_MAN_DIR))
117 define DEF_PREPARE_HOST_TOOL
118 prepare-host-tool-$(1)-$(2)-$(3): $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)) \
119 $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
121 $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
122 $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
123 $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
124 $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
125 $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
126 $$(call PREPARE_MAN,$(1).1),),)
129 $(foreach tool,$(PREPARE_TOOLS),\
130 $(foreach stage,$(PREPARE_STAGES),\
131 $(foreach host,$(CFG_HOST),\
132 $(eval $(call DEF_PREPARE_HOST_TOOL,$(tool),$(stage),$(host))))))
134 # For host libraries only install dylibs, not rlibs since the host libs are only
135 # used to support rustc and rustc uses dynamic linking
140 define DEF_PREPARE_HOST_LIB
141 prepare-host-lib-$(1)-$(2)-$(3): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
142 prepare-host-lib-$(1)-$(2)-$(3): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
143 prepare-host-lib-$(1)-$(2)-$(3): $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3))\
144 $$(HLIB$(2)_H_$(3))/stamp.$(1) \
146 $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
147 $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
148 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1))),),)
151 $(foreach lib,$(CRATES),\
152 $(foreach stage,$(PREPARE_STAGES),\
153 $(foreach host,$(CFG_HOST),\
154 $(eval $(call DEF_PREPARE_HOST_LIB,$(lib),$(stage),$(host))))))
157 $(foreach host,$(CFG_HOST),\
158 $(foreach target,$(CFG_TARGET),\
159 $(foreach stage,$(PREPARE_STAGES),\
160 prepare-target-$(target)-host-$(host)-$(stage))))
165 define DEF_PREPARE_TARGET_N
166 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
167 prepare-target-$(2)-host-$(3)-$(1): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/$$(CFG_RUSTLIBDIR)/$(2)/lib
168 prepare-target-$(2)-host-$(3)-$(1): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/$$(CFG_RUSTLIBDIR)/$(2)/lib
169 prepare-target-$(2)-host-$(3)-$(1): \
170 $$(foreach crate,$$(TARGET_CRATES), \
171 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
172 $$(if $$(findstring $(2),$$(CFG_HOST)), \
173 $$(foreach crate,$$(HOST_CRATES), \
174 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
175 # Only install if this host and target combo is being prepared. Also be sure to
176 # *not* install the rlibs for host crates because there's no need to statically
177 # link against most of them. They just produce a large amount of extra size
179 $$(if $$(findstring $(1), $$(PREPARE_STAGE)),\
180 $$(if $$(findstring $(2), $$(PREPARE_TARGETS)),\
181 $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
182 $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR))\
183 $$(foreach crate,$$(TARGET_CRATES),\
184 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))\
185 $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate))))\
186 $$(if $$(findstring $(2),$$(CFG_HOST)),\
187 $$(foreach crate,$$(HOST_CRATES),\
188 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),)\
189 $$(call PREPARE_LIB,libmorestack.a) \
190 $$(call PREPARE_LIB,libcompiler-rt.a),),),)
193 $(foreach host,$(CFG_HOST),\
194 $(foreach target,$(CFG_TARGET), \
195 $(foreach stage,$(PREPARE_STAGES),\
196 $(eval $(call DEF_PREPARE_TARGET_N,$(stage),$(target),$(host))))))