|
| 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