]> git.lizzy.rs Git - rust.git/blob - mk/prepare.mk
Auto merge of #28841 - jld:const-slice-ice, r=Aatch
[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): prepare-maybe-clean-$(4) \
94                                   $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
95                                   $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
96                                   prepare-host-dirs-$(4)
97         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
98       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
99         $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
100         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
101       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
102         $$(call PREPARE_MAN,$(1).1),),)
103 endef
104
105 # For host libraries only install dylibs, not rlibs since the host libs are only
106 # used to support rustc and rustc uses dynamic linking
107 #
108 # $(1) is tool
109 # $(2) is stage
110 # $(3) is host
111 # $(4) tag
112 define DEF_PREPARE_HOST_LIB
113 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
114 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
115 prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
116                                  $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
117                                  $$(HLIB$(2)_H_$(3))/stamp.$(1) \
118                                  prepare-host-dirs-$(4)
119         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
120       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
121         $$(if $$(findstring 1,$$(ONLY_RLIB_$(1))),, \
122           $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1)))),),)
123 endef
124
125
126 # $(1) is stage
127 # $(2) is target
128 # $(3) is host
129 # $(4) tag
130 define DEF_PREPARE_TARGET_N
131 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
132 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(2)/lib
133 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
134 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(3)/bin
135 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(3)/bin
136 prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \
137         $$(foreach crate,$$(TARGET_CRATES), \
138           $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
139         $$(if $$(findstring $(2),$$(CFG_HOST)), \
140           $$(foreach crate,$$(HOST_CRATES), \
141             $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
142 # Only install if this host and target combo is being prepared. Also be sure to
143 # *not* install the rlibs for host crates because there's no need to statically
144 # link against most of them. They just produce a large amount of extra size
145 # bloat.
146         $$(if $$(findstring $(1), $$(PREPARE_STAGE)), \
147       $$(if $$(findstring $(2), $$(PREPARE_TARGETS)), \
148         $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
149           $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR)) \
150           $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR)) \
151           $$(foreach crate,$$(TARGET_CRATES), \
152             $$(if $$(or $$(findstring 1, $$(ONLY_RLIB_$$(crate))),$$(findstring 1,$$(CFG_INSTALL_ONLY_RLIB_$(2)))),, \
153               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))) \
154             $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))) \
155           $$(if $$(findstring $(2),$$(CFG_HOST)), \
156             $$(foreach crate,$$(HOST_CRATES), \
157               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),) \
158           $$(foreach object,$$(INSTALLED_OBJECTS_$(2)),\
159             $$(call PREPARE_LIB,$$(object))) \
160           $$(foreach bin,$$(INSTALLED_BINS_$(3)),\
161             $$(call PREPARE_BIN,$$(bin))) \
162         ,),),)
163 endef
164
165 define INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS
166         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $(PREPARE_DEST_BIN_DIR)
167         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
168 endef
169
170 define INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS
171         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_BIN_DIR)
172         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
173 endef
174
175 define INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS
176         $(Q)echo "No debugger scripts will be installed for host $(PREPARE_HOST)"
177 endef
178
179 # $(1) is PREPARE_HOST
180 INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
181                                    $(INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS),\
182                                    $(if $(findstring darwin,$(1)),\
183                                      $(INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS),\
184                                      $(INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS)))
185
186 define DEF_PREPARE
187
188 prepare-base-$(1): PREPARE_SOURCE_DIR=$$(PREPARE_HOST)/stage$$(PREPARE_STAGE)
189 prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/bin
190 prepare-base-$(1): PREPARE_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_LIBDIR_RELATIVE)
191 prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
192 prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
193 prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
194 prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
195 prepare-base-$(1): prepare-everything-$(1)
196
197 prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1) prepare-debugger-scripts-$(1)
198
199 prepare-host-$(1): prepare-host-tools-$(1)
200
201 prepare-host-tools-$(1): \
202         $$(foreach tool, $$(PREPARE_TOOLS), \
203           $$(foreach host,$$(CFG_HOST), \
204             prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
205
206 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
207         $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
208         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
209         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
210         $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
211
212 prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) \
213                                $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) \
214                                $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS)
215         $$(call INSTALL_DEBUGGER_SCRIPT_COMMANDS,$$(PREPARE_HOST))
216
217 $$(foreach tool,$$(PREPARE_TOOLS), \
218   $$(foreach host,$$(CFG_HOST), \
219       $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
220
221 $$(foreach lib,$$(CRATES), \
222   $$(foreach host,$$(CFG_HOST), \
223     $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
224
225 prepare-targets-$(1): \
226         $$(foreach host,$$(CFG_HOST), \
227            $$(foreach target,$$(CFG_TARGET), \
228              prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
229
230 $$(foreach host,$$(CFG_HOST), \
231   $$(foreach target,$$(CFG_TARGET), \
232     $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
233
234 prepare-maybe-clean-$(1):
235         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
236       @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
237         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
238       $$(Q)rm -rf $$(PREPARE_DEST_DIR),)
239
240
241 endef