]> git.lizzy.rs Git - rust.git/blob - mk/prepare.mk
use posix command to extract first 8 chars
[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 define PREPARE_DIR
33         @$(Q)$(call E, prepare: $(1))
34         $(Q)$(PREPARE_DIR_CMD) $(1)
35 endef
36
37 # Copy an executable
38 # $(1) is the filename/libname-glob
39 #
40 # Gee, what's up with that $(nop)? See comment below.
41 define PREPARE_BIN
42         $(nop)
43         @$(call E, prepare: $(PREPARE_DEST_BIN_DIR)/$(1))
44         $(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
45 endef
46
47 # Copy a dylib or rlib
48 # $(1) is the filename/libname-glob
49 #
50 # XXX: Don't remove the $(nop) command below!
51 # Yeah, that's right, it's voodoo. Something in the way this macro is being expanded
52 # causes it to parse incorrectly. Throwing in that empty command seems to fix the
53 # problem. I'm sorry, just don't remove the $(nop), alright?
54 define PREPARE_LIB
55         $(nop)
56         @$(call E, prepare: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
57         $(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
58         MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))), \
59                         $(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
60         if [ -n "$$MATCHES" ]; then \
61           echo "warning: one or libraries matching Rust library '$(1)'" && \
62           echo "  (other than '$$LIB_NAME' itself) already present"     && \
63           echo "  at destination $(PREPARE_WORKING_DEST_LIB_DIR):"      && \
64           echo $$MATCHES ; \
65         fi
66         $(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1) | tail -1` $(PREPARE_WORKING_DEST_LIB_DIR)/
67 endef
68
69 # Copy a man page
70 # $(1) - source dir
71 define PREPARE_MAN
72         @$(call E, prepare: $(PREPARE_DEST_MAN_DIR)/$(1))
73         $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
74 endef
75
76 PREPARE_TOOLS = $(filter-out compiletest rustbook error-index-generator, $(TOOLS))
77
78
79 # $(1) is tool
80 # $(2) is stage
81 # $(3) is host
82 # $(4) tag
83 define DEF_PREPARE_HOST_TOOL
84 prepare-host-tool-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
85                                   $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
86                                   $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \
87                                   prepare-host-dirs-$(4)
88         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
89       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
90         $$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
91         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
92       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
93         $$(call PREPARE_MAN,$(1).1),),)
94 endef
95
96 # For host libraries only install dylibs, not rlibs since the host libs are only
97 # used to support rustc and rustc uses dynamic linking
98 #
99 # $(1) is tool
100 # $(2) is stage
101 # $(3) is host
102 # $(4) tag
103 define DEF_PREPARE_HOST_LIB
104 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
105 prepare-host-lib-$(1)-$(2)-$(3)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
106 prepare-host-lib-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \
107                                  $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \
108                                  $$(HLIB$(2)_H_$(3))/stamp.$(1) \
109                                  prepare-host-dirs-$(4)
110         $$(if $$(findstring $(2), $$(PREPARE_STAGE)), \
111       $$(if $$(findstring $(3), $$(PREPARE_HOST)), \
112         $$(if $$(findstring 1,$$(ONLY_RLIB_$(1))),, \
113           $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1)))),),)
114 endef
115
116
117 # $(1) is stage
118 # $(2) is target
119 # $(3) is host
120 # $(4) tag
121 define DEF_PREPARE_TARGET_N
122 # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
123 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(2)/lib
124 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib
125 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(3)/bin
126 prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(3)/bin
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           $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR)) \
142           $$(foreach crate,$$(TARGET_CRATES), \
143             $$(if $$(or $$(findstring 1, $$(ONLY_RLIB_$$(crate))),$$(findstring 1,$$(CFG_INSTALL_ONLY_RLIB_$(2)))),, \
144               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))) \
145             $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))) \
146           $$(if $$(findstring $(2),$$(CFG_HOST)), \
147             $$(foreach crate,$$(HOST_CRATES), \
148               $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),) \
149           $$(foreach object,$$(INSTALLED_OBJECTS_$(2)),\
150             $$(call PREPARE_LIB,$$(object))) \
151           $$(foreach bin,$$(INSTALLED_BINS_$(3)),\
152             $$(call PREPARE_BIN,$$(bin))) \
153         ,),),)
154 endef
155
156 define INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS
157         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $(PREPARE_DEST_BIN_DIR)
158         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
159 endef
160
161 define INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS
162         $(Q)$(PREPARE_BIN_CMD) $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_BIN_DIR)
163         $(Q)$(PREPARE_LIB_CMD) $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $(PREPARE_DEST_LIB_DIR)/rustlib/etc
164 endef
165
166 define INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS
167         $(Q)echo "No debugger scripts will be installed for host $(PREPARE_HOST)"
168 endef
169
170 # $(1) is PREPARE_HOST
171 INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
172                                    $(INSTALL_NO_DEBUGGER_SCRIPTS_COMMANDS),\
173                                    $(if $(findstring darwin,$(1)),\
174                                      $(INSTALL_LLDB_DEBUGGER_SCRIPTS_COMMANDS),\
175                                      $(INSTALL_GDB_DEBUGGER_SCRIPTS_COMMANDS)))
176
177 define DEF_PREPARE
178
179 prepare-base-$(1): PREPARE_SOURCE_DIR=$$(PREPARE_HOST)/stage$$(PREPARE_STAGE)
180 prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/bin
181 prepare-base-$(1): PREPARE_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_LIBDIR_RELATIVE)
182 prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
183 prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
184 prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
185 prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
186 prepare-base-$(1): prepare-everything-$(1)
187
188 prepare-everything-$(1): prepare-host-$(1) prepare-targets-$(1) prepare-debugger-scripts-$(1)
189
190 prepare-host-$(1): prepare-host-tools-$(1)
191
192 prepare-host-tools-$(1): \
193         $$(foreach tool, $$(PREPARE_TOOLS), \
194           $$(foreach host,$$(CFG_HOST), \
195             prepare-host-tool-$$(tool)-$$(PREPARE_STAGE)-$$(host)-$(1)))
196
197 prepare-host-dirs-$(1): prepare-maybe-clean-$(1)
198         $$(call PREPARE_DIR,$$(PREPARE_DEST_BIN_DIR))
199         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR))
200         $$(call PREPARE_DIR,$$(PREPARE_DEST_LIB_DIR)/rustlib/etc)
201         $$(call PREPARE_DIR,$$(PREPARE_DEST_MAN_DIR))
202
203 prepare-debugger-scripts-$(1): prepare-host-dirs-$(1) \
204                                $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) \
205                                $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS)
206         $$(call INSTALL_DEBUGGER_SCRIPT_COMMANDS,$$(PREPARE_HOST))
207
208 $$(foreach tool,$$(PREPARE_TOOLS), \
209   $$(foreach host,$$(CFG_HOST), \
210       $$(eval $$(call DEF_PREPARE_HOST_TOOL,$$(tool),$$(PREPARE_STAGE),$$(host),$(1)))))
211
212 $$(foreach lib,$$(CRATES), \
213   $$(foreach host,$$(CFG_HOST), \
214     $$(eval $$(call DEF_PREPARE_HOST_LIB,$$(lib),$$(PREPARE_STAGE),$$(host),$(1)))))
215
216 prepare-targets-$(1): \
217         $$(foreach host,$$(CFG_HOST), \
218            $$(foreach target,$$(CFG_TARGET), \
219              prepare-target-$$(target)-host-$$(host)-$$(PREPARE_STAGE)-$(1)))
220
221 $$(foreach host,$$(CFG_HOST), \
222   $$(foreach target,$$(CFG_TARGET), \
223     $$(eval $$(call DEF_PREPARE_TARGET_N,$$(PREPARE_STAGE),$$(target),$$(host),$(1)))))
224
225 prepare-maybe-clean-$(1):
226         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
227       @$$(call E, cleaning destination $$(PREPARE_DEST_DIR)),)
228         $$(if $$(findstring true,$$(PREPARE_CLEAN)), \
229       $$(Q)rm -rf $$(PREPARE_DEST_DIR),)
230
231
232 endef