]> git.proxmox.com Git - rustc.git/blame - mk/prepare.mk
New upstream version 1.16.0+dfsg1
[rustc.git] / mk / prepare.mk
CommitLineData
1a4d82fc
JJ
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
23PREPARE_STAGE=2
24
25DEFAULT_PREPARE_DIR_CMD = umask 022 && mkdir -p
26DEFAULT_PREPARE_BIN_CMD = install -m755
27DEFAULT_PREPARE_LIB_CMD = install -m644
28DEFAULT_PREPARE_MAN_CMD = install -m644
29
30# Create a directory
31# $(1) is the directory
62682a34
SL
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.
1a4d82fc 36define PREPARE_DIR
62682a34
SL
37
38 @$(call E, prepare: $(1))
1a4d82fc 39 $(Q)$(PREPARE_DIR_CMD) $(1)
62682a34 40
1a4d82fc
JJ
41endef
42
43# Copy an executable
44# $(1) is the filename/libname-glob
62682a34
SL
45#
46# See above for an explanation on the surrounding blank lines
1a4d82fc 47define PREPARE_BIN
62682a34 48
1a4d82fc
JJ
49 @$(call E, prepare: $(PREPARE_DEST_BIN_DIR)/$(1))
50 $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
62682a34 51
1a4d82fc
JJ
52endef
53
54# Copy a dylib or rlib
55# $(1) is the filename/libname-glob
56#
62682a34 57# See above for an explanation on the surrounding blank lines
1a4d82fc 58define PREPARE_LIB
62682a34 59
1a4d82fc
JJ
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
62682a34
SL
70 $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)` $(PREPARE_WORKING_DEST_LIB_DIR)/
71
1a4d82fc
JJ
72endef
73
74# Copy a man page
75# $(1) - source dir
62682a34
SL
76#
77# See above for an explanation on the surrounding blank lines
1a4d82fc 78define PREPARE_MAN
62682a34 79
1a4d82fc
JJ
80 @$(call E, prepare: $(PREPARE_DEST_MAN_DIR)/$(1))
81 $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
62682a34 82
1a4d82fc
JJ
83endef
84
7453a54e 85PREPARE_TOOLS = $(filter-out compiletest rustbook error_index_generator, $(TOOLS))
1a4d82fc
JJ
86
87
88# $(1) is tool
89# $(2) is stage
90# $(3) is host
91# $(4) tag
92define DEF_PREPARE_HOST_TOOL
92a42be0
SL
93prepare-host-tool-$(1)-$(2)-$(3)-$(4): \
94 PREPARE_SOURCE_BIN_DIR=$$(HBIN$(2)_H_$(3))
1a4d82fc
JJ
95prepare-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),),)
105endef
106
92a42be0
SL
107# Libraries are compiled using the --libdir provided to configure, but
108# we store them in the tarball using just "lib" so that the install
109# script can then rewrite them back to the correct path.
110PREPARE_TAR_LIB_DIR = $(patsubst $(CFG_LIBDIR_RELATIVE)%,lib%,$(1))
111
1a4d82fc
JJ
112# For host libraries only install dylibs, not rlibs since the host libs are only
113# used to support rustc and rustc uses dynamic linking
114#
115# $(1) is tool
116# $(2) is stage
117# $(3) is host
118# $(4) tag
119define DEF_PREPARE_HOST_LIB
92a42be0
SL
120prepare-host-lib-$(1)-$(2)-$(3)-$(4): \
121 PREPARE_WORKING_SOURCE_LIB_DIR=$$(HLIB$(2)_H_$(3))
122prepare-host-lib-$(1)-$(2)-$(3)-$(4): \
123 PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(call PREPARE_TAR_LIB_DIR,$$(HLIB_RELATIVE$(2)_H_$(3)))
1a4d82fc 124prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
7453a54e 125 $$(foreach dep,$$(RUST_DEPS_$(1)_T_$(3)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
1a4d82fc
JJ
126 $$(HLIB$(2)_H_$(3))/stamp.$(1) \
127 prepare-host-dirs-$(4)
128 $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
129 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
130 $$(if $$(findstring 1,$$(ONLY_RLIB_$(1))),, \
131 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1)))),),)
132endef
133
134
135# $(1) is stage
136# $(2) is target
137# $(3) is host
138# $(4) tag
139define DEF_PREPARE_TARGET_N
140# Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
92a42be0
SL
141prepare-target-$(2)-host-$(3)-$(1)-$(4): \
142 PREPARE_WORKING_SOURCE_LIB_DIR=$$(TLIB$(1)_T_$(2)_H_$(3))
143prepare-target-$(2)-host-$(3)-$(1)-$(4): \
144 PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
145prepare-target-$(2)-host-$(3)-$(1)-$(4): \
146 PREPARE_SOURCE_BIN_DIR=$$(TBIN$(1)_T_$(2)_H_$(3))
147prepare-target-$(2)-host-$(3)-$(1)-$(4): \
148 PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(3)/bin
1a4d82fc 149prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \
7453a54e 150 $$(foreach crate,$$(TARGET_CRATES_$(2)), \
1a4d82fc
JJ
151 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
152 $$(if $$(findstring $(2),$$(CFG_HOST)), \
153 $$(foreach crate,$$(HOST_CRATES), \
154 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
155# Only install if this host and target combo is being prepared. Also be sure to
156# *not* install the rlibs for host crates because there's no need to statically
157# link against most of them. They just produce a large amount of extra size
158# bloat.
159 $$(if $$(findstring $(1), $$(PREPARE_STAGE)), \
160 $$(if $$(findstring $(2), $$(PREPARE_TARGETS)), \
161 $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
162 $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR)) \
62682a34 163 $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR)) \
7453a54e 164 $$(foreach crate,$$(TARGET_CRATES_$(2)), \
85aaf69f 165 $$(if $$(or $$(findstring 1, $$(ONLY_RLIB_$$(crate))),$$(findstring 1,$$(CFG_INSTALL_ONLY_RLIB_$(2)))),, \
1a4d82fc
JJ
166 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))) \
167 $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))) \
168 $$(if $$(findstring $(2),$$(CFG_HOST)), \
169 $$(foreach crate,$$(HOST_CRATES), \
170 $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),) \
62682a34
SL
171 $$(foreach object,$$(INSTALLED_OBJECTS_$(2)),\
172 $$(call PREPARE_LIB,$$(object))) \
173 $$(foreach bin,$$(INSTALLED_BINS_$(3)),\
174 $$(call PREPARE_BIN,$$(bin))) \
175 ,),),)
1a4d82fc
JJ
176endef
177
178define INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS
179 $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $(PREPARE_DEST_BIN_DIR)
180 $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
181endef
182
183define INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS
184 $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_BIN_DIR)
185 $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
186endef
187
188define INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS
189 $(Q)echo "No debugger scripts will be installed for host $(PREPARE_HOST)"
190endef
191
192# $(1) is PREPARE_HOST
193INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
194 $(INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS),\
195 $(if $(findstring darwin,$(1)),\
196 $(INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS),\
197 $(INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS)))
198
199define DEF_PREPARE
200
b039eaaf
SL
201prepare-base-$(1)-%: PREPARE_SOURCE_MAN_DIR=$$(S)/man
202prepare-base-$(1)-%: PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
92a42be0 203prepare-base-$(1)-%: PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(call PREPARE_TAR_LIB_DIR,$$(CFG_LIBDIR_RELATIVE))
b039eaaf 204prepare-base-$(1)-%: PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
1a4d82fc 205
b039eaaf
SL
206prepare-base-$(1)-target: prepare-target-$(1)
207prepare-base-$(1)-host: prepare-host-$(1) prepare-debugger-scripts-$(1)
1a4d82fc
JJ
208
209prepare-host-$(1): prepare-host-tools-$(1)
210
211prepare-host-tools-$(1): \
212 $$(foreach tool, $$(PREPARE_TOOLS), \
213 $$(foreach host,$$(CFG_HOST), \
214 prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
215
216prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
217 $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
218 $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
219 $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
220 $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
221
222prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) \
223 $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) \
224 $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS)
225 $$(call INSTALL_DEBUGGER_SCRIPT_COMMANDS,$$(PREPARE_HOST))
226
227$$(foreach tool,$$(PREPARE_TOOLS), \
228 $$(foreach host,$$(CFG_HOST), \
229 $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
230
231$$(foreach lib,$$(CRATES), \
232 $$(foreach host,$$(CFG_HOST), \
233 $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
234
b039eaaf 235prepare-target-$(1): \
1a4d82fc
JJ
236 $$(foreach host,$$(CFG_HOST), \
237 $$(foreach target,$$(CFG_TARGET), \
238 prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
239
240$$(foreach host,$$(CFG_HOST), \
241 $$(foreach target,$$(CFG_TARGET), \
242 $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
243
244prepare-maybe-clean-$(1):
245 $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
246 @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
247 $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
248 $$(Q)rm -rf $$(PREPARE_DEST_DIR),)
249
250
251endef