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
25 DEFAULT_PREPARE_DIR_CMD = umask 022 && mkdir -p
26 DEFAULT_PREPARE_BIN_CMD = install -m755
27 DEFAULT_PREPARE_LIB_CMD = install -m644
28 DEFAULT_PREPARE_MAN_CMD = install -m644
31 # $(1) is the directory
33 @$(Q)$(call E, prepare: $(1))
34 $(Q)$(PREPARE_DIR_CMD) $(1)
38 # $(1) is the filename/libname-glob
40 @$(call E, prepare: $(PREPARE_DEST_BIN_DIR)/$(1))
41 $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
44 # Copy a dylib or rlib
45 # $(1) is the filename/libname-glob
47 # XXX: Don't remove the $(nop) command below!
48 # Yeah, that's right, it's voodoo. Something in the way this macro is being expanded
49 # causes it to parse incorrectly. Throwing in that empty command seems to fix the
50 # problem. I'm sorry, just don't remove the $(nop), alright?
53 @$(call E, prepare: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
54 $(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
55 MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))), \
56 $(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
57 if [ -n "$$MATCHES" ]; then \
58 echo "warning: one or libraries matching Rust library '$(1)'" && \
59 echo " (other than '$$LIB_NAME' itself) already present" && \
60 echo " at destination $(PREPARE_WORKING_DEST_LIB_DIR):" && \
63 $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1) | tail -1` $(PREPARE_WORKING_DEST_LIB_DIR)/
69 @$(call E, prepare: $(PREPARE_DEST_MAN_DIR)/$(1))
70 $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
73 PREPARE_TOOLS = $(filter-out compiletest rustbook, $(TOOLS))
80 define DEF_PREPARE_HOST_TOOL
81 prepare-host-tool-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
82 $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
83 $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
84 prepare-host-dirs-$(4)
85 $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
86 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
87 $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
88 $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
89 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
90 $$(call PREPARE_MAN,$(1).1),),)
93 # For host libraries only install dylibs, not rlibs since the host libs are only
94 # used to support rustc and rustc uses dynamic linking
100 define DEF_PREPARE_HOST_LIB
101 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
102 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
103 prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
104 $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
105 $$(HLIB$(2)_H_$(3))/stamp.$(1) \
106 prepare-host-dirs-$(4)
107 $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
108 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
109 $$(if $$(findstring 1,$$(ONLY_RLIB_$(1))),, \
110 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1)))),),)
118 define DEF_PREPARE_TARGET_N
119 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
120 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(2)/lib
121 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
122 prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \
123 $$(foreach crate,$$(TARGET_CRATES), \
124 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
125 $$(if $$(findstring $(2),$$(CFG_HOST)), \
126 $$(foreach crate,$$(HOST_CRATES), \
127 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
128 # Only install if this host and target combo is being prepared. Also be sure to
129 # *not* install the rlibs for host crates because there's no need to statically
130 # link against most of them. They just produce a large amount of extra size
132 $$(if $$(findstring $(1), $$(PREPARE_STAGE)), \
133 $$(if $$(findstring $(2), $$(PREPARE_TARGETS)), \
134 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
135 $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR)) \
136 $$(foreach crate,$$(TARGET_CRATES), \
137 $$(if $$(findstring 1, $$(ONLY_RLIB_$$(crate))),, \
138 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))) \
139 $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))) \
140 $$(if $$(findstring $(2),$$(CFG_HOST)), \
141 $$(foreach crate,$$(HOST_CRATES), \
142 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),) \
143 $$(call PREPARE_LIB,libmorestack.a) \
144 $$(call PREPARE_LIB,libcompiler-rt.a),),),)
147 define INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS
148 $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $(PREPARE_DEST_BIN_DIR)
149 $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
152 define INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS
153 $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_BIN_DIR)
154 $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
157 define INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS
158 $(Q)echo "No debugger scripts will be installed for host $(PREPARE_HOST)"
161 # $(1) is PREPARE_HOST
162 INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
163 $(INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS),\
164 $(if $(findstring darwin,$(1)),\
165 $(INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS),\
166 $(INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS)))
170 prepare-base-$(1): PREPARE_SOURCE_DIR=$$(PREPARE_HOST)/stage$$(PREPARE_STAGE)
171 prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/bin
172 prepare-base-$(1): PREPARE_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_LIBDIR_RELATIVE)
173 prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
174 prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
175 prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
176 prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
177 prepare-base-$(1): prepare-everything-$(1)
179 prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1) prepare-debugger-scripts-$(1)
181 prepare-host-$(1): prepare-host-tools-$(1)
183 prepare-host-tools-$(1): \
184 $$(foreach tool, $$(PREPARE_TOOLS), \
185 $$(foreach host,$$(CFG_HOST), \
186 prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
188 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
189 $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
190 $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
191 $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
192 $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
194 prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) \
195 $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) \
196 $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS)
197 $$(call INSTALL_DEBUGGER_SCRIPT_COMMANDS,$$(PREPARE_HOST))
199 $$(foreach tool,$$(PREPARE_TOOLS), \
200 $$(foreach host,$$(CFG_HOST), \
201 $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
203 $$(foreach lib,$$(CRATES), \
204 $$(foreach host,$$(CFG_HOST), \
205 $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
207 prepare-targets-$(1): \
208 $$(foreach host,$$(CFG_HOST), \
209 $$(foreach target,$$(CFG_TARGET), \
210 prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
212 $$(foreach host,$$(CFG_HOST), \
213 $$(foreach target,$$(CFG_TARGET), \
214 $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
216 prepare-maybe-clean-$(1):
217 $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
218 @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
219 $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
220 $$(Q)rm -rf $$(PREPARE_DEST_DIR),)