]> git.lizzy.rs Git - rust.git/blob - mk/prepare.mk
Rollup merge of #29617 - steveklabnik:gh29591, r=alexcrichton
[rust.git] / mk / prepare.mk
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.
4 #
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.
10
11 # Basic support for producing installation images.
12 #
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.
16 #
17 # It requires the following variables to be set:
18 #
19 #   PREPARE_HOST - the host triple
20 #   PREPARE_TARGETS - the target triples, space separated
21 #   PREPARE_DEST_DIR - the directory to put the image
22
23 PREPARE_STAGE=2
24
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
29
30 # Create a directory
31 # $(1) is the directory
32 #
33 # XXX: These defines are called to generate make steps.
34 # Adding blank lines means two steps from different defines will not end up on
35 # the same line.
36 define PREPARE_DIR
37
38         @$(call E, prepare: $(1))
39         $(Q)$(PREPARE_DIR_CMD) $(1)
40
41 endef
42
43 # Copy an executable
44 # $(1) is the filename/libname-glob
45 #
46 # See above for an explanation on the surrounding blank lines
47 define PREPARE_BIN
48
49         @$(call E, prepare: $(PREPARE_DEST_BIN_DIR)/$(1))
50         $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
51
52 endef
53
54 # Copy a dylib or rlib
55 # $(1) is the filename/libname-glob
56 #
57 # See above for an explanation on the surrounding blank lines
58 define PREPARE_LIB
59
60         @$(call E, prepare: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
61         $(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
62         MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))), \
63                         $(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
64         if [ -n "$$MATCHES" ]; then \
65           echo "warning: one or libraries matching Rust library '$(1)'" && \
66           echo "  (other than '$$LIB_NAME' itself) already present"     && \
67           echo "  at destination $(PREPARE_WORKING_DEST_LIB_DIR):"      && \
68           echo $$MATCHES ; \
69         fi
70         $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)` $(PREPARE_WORKING_DEST_LIB_DIR)/
71
72 endef
73
74 # Copy a man page
75 # $(1) - source dir
76 #
77 # See above for an explanation on the surrounding blank lines
78 define PREPARE_MAN
79
80         @$(call E, prepare: $(PREPARE_DEST_MAN_DIR)/$(1))
81         $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
82
83 endef
84
85 PREPARE_TOOLS = $(filter-out compiletest rustbook error-index-generator, $(TOOLS))
86
87
88 # $(1) is tool
89 # $(2) is stage
90 # $(3) is host
91 # $(4) tag
92 define DEF_PREPARE_HOST_TOOL
93 prepare-host-tool-$(1)-$(2)-$(3)-$(4): \
94         PREPARE_SOURCE_BIN_DIR=$$(HBIN$(2)_H_$(3))
95 prepare-host-tool-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
96                                   $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
97                                   $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
98                                   prepare-host-dirs-$(4)
99         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
100       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
101         $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
102         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
103       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
104         $$(call PREPARE_MAN,$(1).1),),)
105 endef
106
107 # For host libraries only install dylibs, not rlibs since the host libs are only
108 # used to support rustc and rustc uses dynamic linking
109 #
110 # $(1) is tool
111 # $(2) is stage
112 # $(3) is host
113 # $(4) tag
114 define DEF_PREPARE_HOST_LIB
115 prepare-host-lib-$(1)-$(2)-$(3)-$(4): \
116         PREPARE_WORKING_SOURCE_LIB_DIR=$$(HLIB$(2)_H_$(3))
117 prepare-host-lib-$(1)-$(2)-$(3)-$(4): \
118         PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(notdir $$(HLIB$(2)_H_$(3)))
119 prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
120                                  $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
121                                  $$(HLIB$(2)_H_$(3))/stamp.$(1) \
122                                  prepare-host-dirs-$(4)
123         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
124       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
125         $$(if $$(findstring 1,$$(ONLY_RLIB_$(1))),, \
126           $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1)))),),)
127 endef
128
129
130 # $(1) is stage
131 # $(2) is target
132 # $(3) is host
133 # $(4) tag
134 define DEF_PREPARE_TARGET_N
135 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
136 prepare-target-$(2)-host-$(3)-$(1)-$(4): \
137         PREPARE_WORKING_SOURCE_LIB_DIR=$$(TLIB$(1)_T_$(2)_H_$(3))
138 prepare-target-$(2)-host-$(3)-$(1)-$(4): \
139         PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
140 prepare-target-$(2)-host-$(3)-$(1)-$(4): \
141         PREPARE_SOURCE_BIN_DIR=$$(TBIN$(1)_T_$(2)_H_$(3))
142 prepare-target-$(2)-host-$(3)-$(1)-$(4): \
143         PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(3)/bin
144 prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \
145         $$(foreach crate,$$(TARGET_CRATES), \
146           $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
147         $$(if $$(findstring $(2),$$(CFG_HOST)), \
148           $$(foreach crate,$$(HOST_CRATES), \
149             $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
150 # Only install if this host and target combo is being prepared. Also be sure to
151 # *not* install the rlibs for host crates because there's no need to statically
152 # link against most of them. They just produce a large amount of extra size
153 # bloat.
154         $$(if $$(findstring $(1), $$(PREPARE_STAGE)), \
155       $$(if $$(findstring $(2), $$(PREPARE_TARGETS)), \
156         $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
157           $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR)) \
158           $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR)) \
159           $$(foreach crate,$$(TARGET_CRATES), \
160             $$(if $$(or $$(findstring 1, $$(ONLY_RLIB_$$(crate))),$$(findstring 1,$$(CFG_INSTALL_ONLY_RLIB_$(2)))),, \
161               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))) \
162             $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))) \
163           $$(if $$(findstring $(2),$$(CFG_HOST)), \
164             $$(foreach crate,$$(HOST_CRATES), \
165               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),) \
166           $$(foreach object,$$(INSTALLED_OBJECTS_$(2)),\
167             $$(call PREPARE_LIB,$$(object))) \
168           $$(foreach bin,$$(INSTALLED_BINS_$(3)),\
169             $$(call PREPARE_BIN,$$(bin))) \
170         ,),),)
171 endef
172
173 define INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS
174         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $(PREPARE_DEST_BIN_DIR)
175         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
176 endef
177
178 define INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS
179         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_BIN_DIR)
180         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
181 endef
182
183 define INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS
184         $(Q)echo "No debugger scripts will be installed for host $(PREPARE_HOST)"
185 endef
186
187 # $(1) is PREPARE_HOST
188 INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
189                                    $(INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS),\
190                                    $(if $(findstring darwin,$(1)),\
191                                      $(INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS),\
192                                      $(INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS)))
193
194 define DEF_PREPARE
195
196 prepare-base-$(1)-%: PREPARE_SOURCE_MAN_DIR=$$(S)/man
197 prepare-base-$(1)-%: PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
198 prepare-base-$(1)-%: PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
199 prepare-base-$(1)-%: PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
200
201 prepare-base-$(1)-target: prepare-target-$(1)
202 prepare-base-$(1)-host: prepare-host-$(1) prepare-debugger-scripts-$(1)
203
204 prepare-host-$(1): prepare-host-tools-$(1)
205
206 prepare-host-tools-$(1): \
207         $$(foreach tool, $$(PREPARE_TOOLS), \
208           $$(foreach host,$$(CFG_HOST), \
209             prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
210
211 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
212         $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
213         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
214         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
215         $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
216
217 prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) \
218                                $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) \
219                                $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS)
220         $$(call INSTALL_DEBUGGER_SCRIPT_COMMANDS,$$(PREPARE_HOST))
221
222 $$(foreach tool,$$(PREPARE_TOOLS), \
223   $$(foreach host,$$(CFG_HOST), \
224       $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
225
226 $$(foreach lib,$$(CRATES), \
227   $$(foreach host,$$(CFG_HOST), \
228     $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
229
230 prepare-target-$(1): \
231         $$(foreach host,$$(CFG_HOST), \
232            $$(foreach target,$$(CFG_TARGET), \
233              prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
234
235 $$(foreach host,$$(CFG_HOST), \
236   $$(foreach target,$$(CFG_TARGET), \
237     $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
238
239 prepare-maybe-clean-$(1):
240         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
241       @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
242         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
243       $$(Q)rm -rf $$(PREPARE_DEST_DIR),)
244
245
246 endef