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