Skip to content

Commit 4cd8bdc

Browse files
committed
mk: Add prepare.mk
This is a slightly more generic rewrite of install.mk. Currently used for nothing, but we'll base all the binary distributables off it.
1 parent 5d88a4a commit 4cd8bdc

File tree

2 files changed

+200
-12
lines changed

2 files changed

+200
-12
lines changed

Makefile.in

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,6 @@ include $(CFG_SRC_DIR)mk/llvm.mk
198198
# Secondary makefiles, conditionalized for speed
199199
######################################################################
200200

201-
# Source and binary distribution artifacts
202-
ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
203-
$(findstring clean,$(MAKECMDGOALS))),)
204-
CFG_INFO := $(info cfg: including dist rules)
205-
include $(CFG_SRC_DIR)mk/dist.mk
206-
endif
207-
208201
# Binary snapshots
209202
ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
210203
$(findstring clean,$(MAKECMDGOALS))),)
@@ -227,18 +220,32 @@ ifneq ($(findstring perf,$(MAKECMDGOALS)),)
227220
include $(CFG_SRC_DIR)mk/perf.mk
228221
endif
229222

230-
# Cleaning
231-
ifneq ($(findstring clean,$(MAKECMDGOALS)),)
232-
CFG_INFO := $(info cfg: including clean rules)
233-
include $(CFG_SRC_DIR)mk/clean.mk
223+
# Copy all the distributables to another directory for binary install
224+
ifneq ($(strip $(findstring prepare,$(MAKECMDGOALS)) \
225+
$(findstring install,$(MAKECMDGOALS))),)
226+
CFG_INFO := $(info cfg: including prepare rules)
227+
include $(CFG_SRC_DIR)mk/prepare.mk
234228
endif
235229

236-
# Installation from the build directory
230+
# (Unix) Installation from the build directory
237231
ifneq ($(findstring install,$(MAKECMDGOALS)),)
238232
CFG_INFO := $(info cfg: including install rules)
239233
include $(CFG_SRC_DIR)mk/install.mk
240234
endif
241235

236+
# Source and binary distribution artifacts
237+
ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
238+
$(findstring clean,$(MAKECMDGOALS))),)
239+
CFG_INFO := $(info cfg: including dist rules)
240+
include $(CFG_SRC_DIR)mk/dist.mk
241+
endif
242+
243+
# Cleaning
244+
ifneq ($(findstring clean,$(MAKECMDGOALS)),)
245+
CFG_INFO := $(info cfg: including clean rules)
246+
include $(CFG_SRC_DIR)mk/clean.mk
247+
endif
248+
242249
# CTAGS building
243250
ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
244251
$(findstring TAGS.vi,$(MAKECMDGOALS))),)

mk/prepare.mk

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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)/man1
37+
prepare-base: prepare-host prepare-targets
38+
39+
DEFAULT_PREPARE_DIR_CMD = umask 022 && mkdir -p
40+
DEFAULT_PREPARE_BIN_CMD = install -m755
41+
DEFAULT_PREPARE_LIB_CMD = install -m644
42+
DEFAULT_PREPARE_MAN_CMD = install -m755
43+
44+
# On windows we install from stage3, but on unix only stage2
45+
# Because of the way these rules are organized, preparing from any
46+
# stage requires all these stages to be built
47+
ifdef CFG_WINDOWSY_$(CFG_BUILD)
48+
PREPARE_STAGES=1 2 3
49+
else
50+
PREPARE_STAGES=1 2
51+
endif
52+
53+
# Create a directory
54+
# $(1) is the directory
55+
define PREPARE_DIR
56+
@$(Q)$(call E, install: $(1))
57+
$(Q)$(PREPARE_DIR_CMD) $(1)
58+
endef
59+
60+
# Copy an executable
61+
# $(1) is the filename/libname-glob
62+
define PREPARE_BIN
63+
@$(call E, install: $(PREPARE_DEST_BIN_DIR)/$(1))
64+
$(Q)$(PREPARE_BIN_CMD) $(PREPARE_SOURCE_BIN_DIR)/$(1) $(PREPARE_DEST_BIN_DIR)/$(1)
65+
endef
66+
67+
# Copy a dylib or rlib
68+
# $(1) is the filename/libname-glob
69+
#
70+
# XXX: Don't remove the $(nop) command below!
71+
# Yeah, that's right, it's voodoo. Something in the way this macro is being expanded
72+
# causes it to parse incorrectly. Throwing in that empty command seems to fix the
73+
# problem. I'm sorry, just don't remove the $(nop), alright?
74+
define PREPARE_LIB
75+
$(nop)
76+
@$(call E, install: $(PREPARE_WORKING_DEST_LIB_DIR)/$(1))
77+
$(Q)LIB_NAME="$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1))))"; \
78+
MATCHES="$(filter-out %$(notdir $(lastword $(wildcard $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1)))),\
79+
$(wildcard $(PREPARE_WORKING_DEST_LIB_DIR)/$(1)))"; \
80+
if [ -n "$$MATCHES" ]; then \
81+
echo "warning: one or libraries matching Rust library '$(1)'" && \
82+
echo " (other than '$$LIB_NAME' itself) already present" && \
83+
echo " at destination $(PREPARE_WORKING_DEST_LIB_DIR):" && \
84+
echo $$MATCHES ; \
85+
fi
86+
$(Q)$(PREPARE_LIB_CMD) `ls -drt1 $(PREPARE_WORKING_SOURCE_LIB_DIR)/$(1) | tail -1` $(PREPARE_WORKING_DEST_LIB_DIR)/
87+
endef
88+
89+
# Copy a man page
90+
# $(1) - source dir
91+
define PREPARE_MAN
92+
@$(call E, install: $(PREPARE_DEST_MAN_DIR)/$(1))
93+
$(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
94+
endef
95+
96+
97+
PREPARE_TOOLS = $(filter-out compiletest, $(TOOLS))
98+
99+
prepare-host: prepare-host-dirs prepare-host-tools
100+
101+
prepare-host-dirs:
102+
$(call PREPARE_DIR,$(PREPARE_DEST_BIN_DIR))
103+
$(call PREPARE_DIR,$(PREPARE_DEST_LIB_DIR))
104+
$(call PREPARE_DIR,$(PREPARE_DEST_MAN_DIR))
105+
106+
prepare-host-tools:\
107+
$(foreach tool, $(PREPARE_TOOLS),\
108+
$(foreach stage,$(PREPARE_STAGES),\
109+
$(foreach host,$(CFG_HOST),\
110+
prepare-host-tool-$(tool)-$(stage)-$(host))))
111+
112+
# $(1) is tool
113+
# $(2) is stage
114+
# $(3) is host
115+
define DEF_PREPARE_HOST_TOOL
116+
prepare-host-tool-$(1)-$(2)-$(3): $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)) \
117+
$$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3))
118+
$$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
119+
$$(if $$(findstring $(3), $$(PREPARE_HOST)),\
120+
$$(call PREPARE_BIN,$(1)$$(X_$$(PREPARE_HOST))),),)
121+
$$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
122+
$$(if $$(findstring $(3), $$(PREPARE_HOST)),\
123+
$$(call PREPARE_MAN,$(1).1),),)
124+
endef
125+
126+
$(foreach tool,$(PREPARE_TOOLS),\
127+
$(foreach stage,$(PREPARE_STAGES),\
128+
$(foreach host,$(CFG_HOST),\
129+
$(eval $(call DEF_PREPARE_HOST_TOOL,$(tool),$(stage),$(host))))))
130+
131+
# $(1) is tool
132+
# $(2) is stage
133+
# $(3) is host
134+
define DEF_PREPARE_HOST_LIB
135+
prepare-host-lib-$(1)-$(2)-$(3): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)
136+
prepare-host-lib-$(1)-$(2)-$(3): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)
137+
prepare-host-lib-$(1)-$(2)-$(3): $$(foreach dep,$$(RUST_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3))\
138+
$$(HLIB$(2)_H_$(3))/stamp.$(1)
139+
$$(if $$(findstring $(2), $$(PREPARE_STAGE)),\
140+
$$(if $$(findstring $(3), $$(PREPARE_HOST)),\
141+
$$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$$(PREPARE_HOST),$(1))),),)
142+
endef
143+
144+
$(foreach lib,$(CRATES),\
145+
$(foreach stage,$(PREPARE_STAGES),\
146+
$(foreach host,$(CFG_HOST),\
147+
$(eval $(call DEF_PREPARE_HOST_LIB,$(lib),$(stage),$(host))))))
148+
149+
prepare-targets:\
150+
$(foreach host,$(CFG_HOST),\
151+
$(foreach target,$(CFG_TARGET),\
152+
$(foreach stage,$(PREPARE_STAGES),\
153+
prepare-target-$(target)-host-$(host)-$(stage))))
154+
155+
# $(1) is target
156+
# $(2) is host
157+
# $(3) is stage
158+
define DEF_PREPARE_TARGET_N
159+
# Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets
160+
prepare-target-$(1)-host-$(2)-$(3): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(1)/lib
161+
prepare-target-$(1)-host-$(2)-$(3): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(1)/lib
162+
prepare-target-$(1)-host-$(2)-$(3): \
163+
$$(foreach crate,$$(TARGET_CRATES), \
164+
$$(TLIB$(3)_T_$(1)_H_$(2))/stamp.$$(crate))
165+
# Only install if this host and target combo is being prepared
166+
$$(if $$(findstring $(2), $$(PREPARE_HOST)),\
167+
$$(if $$(findstring $(1), $$(PREPARE_TARGETS)),\
168+
$$(if $$(findstring $(3), $$(PREPARE_STAGE)),\
169+
$$(call PREPARE_DIR,$$(PREPARE_WORKING_DEST_LIB_DIR))\
170+
$$(foreach crate,$$(TARGET_CRATES),\
171+
$$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(1),$$(crate))))\
172+
$$(foreach crate,$$(TARGET_CRATES),\
173+
$$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate))))\
174+
$$(call PREPARE_LIB,libmorestack.a)
175+
$$(call PREPARE_LIB,libcompiler-rt.a),),),)
176+
endef
177+
178+
$(foreach host,$(CFG_HOST),\
179+
$(foreach target,$(CFG_TARGET), \
180+
$(foreach stage,$(PREPARE_STAGES),\
181+
$(eval $(call DEF_PREPARE_TARGET_N,$(target),$(host),$(stage))))))

0 commit comments

Comments
 (0)