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