]> git.lizzy.rs Git - rust.git/blob - mk/prepare.mk
auto merge of #13112 : ktt3ja/rust/issue-13058, r=pnkfelix
[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
24 # On windows we install from stage3, but on unix only stage2
25 ifdef CFG_WINDOWSY_$(CFG_BUILD)
26 PREPARE_STAGE=3
27 else
28 PREPARE_STAGE=2
29 endif
30
31 DEFAULT_PREPARE_DIR_CMD = umask 022 && mkdir -p
32 DEFAULT_PREPARE_BIN_CMD = install -m755
33 DEFAULT_PREPARE_LIB_CMD = install -m644
34 DEFAULT_PREPARE_MAN_CMD = install -m644
35
36 # Create a directory
37 # $(1) is the directory
38 define PREPARE_DIR
39         @$(Q)$(call E, prepare: $(1))
40         $(Q)$(PREPARE_DIR_CMD) $(1)
41 endef
42
43 # Copy an executable
44 # $(1) is the filename/libname-glob
45 define PREPARE_BIN
46         @$(call E, prepare: $(PREPARE_DEST_BIN_DIR)/$(1))
47         $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
48 endef
49
50 # Copy a dylib or rlib
51 # $(1) is the filename/libname-glob
52 #
53 # XXX: Don't remove the $(nop) command below!
54 # Yeah, that's right, it's voodoo. Something in the way this macro is being expanded
55 # causes it to parse incorrectly. Throwing in that empty command seems to fix the
56 # problem. I'm sorry, just don't remove the $(nop), alright?
57 define PREPARE_LIB
58         $(nop)
59         @$(call E, prepare: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
60         $(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
61         MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))),\
62                         $(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
63         if [ -n "$$MATCHES" ]; then                                              \
64           echo "warning: one or libraries matching Rust library '$(1)'" &&       \
65           echo "  (other than '$$LIB_NAME' itself) already present"     &&       \
66           echo "  at destination $(PREPARE_WORKING_DEST_LIB_DIR):"                    &&       \
67           echo $$MATCHES ;                                                       \
68         fi
69         $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1) | tail -1` $(PREPARE_WORKING_DEST_LIB_DIR)/
70 endef
71
72 # Copy a man page
73 # $(1) - source dir
74 define PREPARE_MAN
75         @$(call E, prepare: $(PREPARE_DEST_MAN_DIR)/$(1))
76         $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
77 endef
78
79 PREPARE_TOOLS = $(filter-out compiletest, $(TOOLS))
80
81
82 # $(1) is tool
83 # $(2) is stage
84 # $(3) is host
85 # $(4) tag
86 define DEF_PREPARE_HOST_TOOL
87 prepare-host-tool-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
88                                   $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
89                                   $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
90                                   prepare-host-dirs-$(4)
91         $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
92       $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
93         $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
94         $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
95       $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
96         $$(call PREPARE_MAN,$(1).1),),)
97 endef
98
99 # For host libraries only install dylibs, not rlibs since the host libs are only
100 # used to support rustc and rustc uses dynamic linking
101 #
102 # $(1) is tool
103 # $(2) is stage
104 # $(3) is host
105 # $(4) tag
106 define DEF_PREPARE_HOST_LIB
107 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
108 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
109 prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
110                                  $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4))\
111                                  $$(HLIB$(2)_H_$(3))/stamp.$(1) \
112                                  prepare-host-dirs-$(4)
113         $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
114       $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
115         $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1))),),)
116 endef
117
118
119 # $(1) is stage
120 # $(2) is target
121 # $(3) is host
122 # $(4) tag
123 define DEF_PREPARE_TARGET_N
124 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
125 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(2)/lib
126 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
127 prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \
128         $$(foreach crate,$$(TARGET_CRATES), \
129           $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
130         $$(if $$(findstring $(2),$$(CFG_HOST)), \
131           $$(foreach crate,$$(HOST_CRATES), \
132             $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
133 # Only install if this host and target combo is being prepared. Also be sure to
134 # *not* install the rlibs for host crates because there's no need to statically
135 # link against most of them. They just produce a large amount of extra size
136 # bloat.
137         $$(if $$(findstring $(1), $$(PREPARE_STAGE)),\
138       $$(if $$(findstring $(2), $$(PREPARE_TARGETS)),\
139         $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
140           $$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR))\
141           $$(foreach crate,$$(TARGET_CRATES),\
142             $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))\
143             $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate))))\
144           $$(if $$(findstring $(2),$$(CFG_HOST)),\
145             $$(foreach crate,$$(HOST_CRATES),\
146               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),)\
147           $$(call PREPARE_LIB,libmorestack.a) \
148           $$(call PREPARE_LIB,libcompiler-rt.a),),),)
149 endef
150
151 define DEF_PREPARE
152
153 prepare-base-$(1): PREPARE_SOURCE_DIR=$$(PREPARE_HOST)/stage$$(PREPARE_STAGE)
154 prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/bin
155 prepare-base-$(1): PREPARE_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_LIBDIR_RELATIVE)
156 prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
157 prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
158 prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
159 prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
160 prepare-base-$(1): prepare-everything-$(1)
161
162 prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1)
163
164 prepare-host-$(1): prepare-host-tools-$(1)
165
166 prepare-host-tools-$(1): \
167         $$(foreach tool, $$(PREPARE_TOOLS),\
168           $$(foreach host,$$(CFG_HOST),\
169             prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
170
171 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
172         $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
173         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
174         $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
175
176 $$(foreach tool,$$(PREPARE_TOOLS),\
177   $$(foreach host,$$(CFG_HOST),\
178       $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
179
180 $$(foreach lib,$$(CRATES),\
181   $$(foreach host,$$(CFG_HOST),\
182     $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
183
184 prepare-targets-$(1):\
185         $$(foreach host,$$(CFG_HOST),\
186            $$(foreach target,$$(CFG_TARGET),\
187              prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
188
189 $$(foreach host,$$(CFG_HOST),\
190   $$(foreach target,$$(CFG_TARGET), \
191     $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
192
193 prepare-maybe-clean-$(1):
194         $$(if $$(findstring true,$$(PREPARE_CLEAN)),\
195       @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
196         $$(if $$(findstring true,$$(PREPARE_CLEAN)),\
197       $$(Q)rm -rf $$(PREPARE_DEST_DIR),)
198
199
200 endef
201
202