install.mk 9.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

B
Brian Anderson 已提交
11 12 13 14 15
# FIXME: Docs are currently not installed from the stageN dirs.
# For consistency it might be desirable for stageN to be an exact
# mirror of the installation directory structure.

# Installation macro. Call with source directory as arg 1,
16
# destination directory as arg 2, and filename/libname-glob as arg 3
17
ifdef VERBOSE
18
 INSTALL = install -m755 $(1)/$(3) $(2)/$(3)
G
Graydon Hoare 已提交
19
 INSTALL_LIB = install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
20
else
21
 INSTALL = $(Q)$(call E, install: $(2)/$(3)) && install -m755 $(1)/$(3) $(2)/$(3)
22
 INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) &&                    \
G
Graydon Hoare 已提交
23
	       install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
24 25
endif

26
# The stage we install from
27
ISTAGE = 2
28 29 30

PREFIX_ROOT = $(CFG_PREFIX)
PREFIX_BIN = $(PREFIX_ROOT)/bin
31
PREFIX_LIB = $(PREFIX_ROOT)/$(CFG_LIBDIR)
32

33
define INSTALL_PREPARE_N
N
Niko Matsakis 已提交
34 35
  # $(1) is the target triple
  # $(2) is the host triple
36

N
Niko Matsakis 已提交
37
# T{B,L} == Target {Bin, Lib} for stage ${ISTAGE}
38 39
TB$(1)$(2) = $$(TBIN$$(ISTAGE)_T_$(1)_H_$(2))
TL$(1)$(2) = $$(TLIB$$(ISTAGE)_T_$(1)_H_$(2))
40

N
Niko Matsakis 已提交
41
# PT{R,B,L} == Prefix Target {Root, Bin, Lib}
42 43
PTR$(1)$(2) = $$(PREFIX_LIB)/rustc/$(1)
PTB$(1)$(2) = $$(PTR$(1)$(2))/bin
44
PTL$(1)$(2) = $$(PTR$(1)$(2))/$(CFG_LIBDIR)
45

46 47 48 49 50 51 52 53
endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
 $(eval $(call INSTALL_PREPARE_N,$(target),$(CFG_BUILD_TRIPLE))))

define INSTALL_TARGET_N
install-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
	$$(Q)mkdir -p $$(PTL$(1)$(2))
54
	$$(Q)$$(call INSTALL_LIB,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_RUNTIME_$(1)))
55 56 57 58
	$$(Q)$$(call INSTALL_LIB, \
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CORELIB_GLOB_$(1)))
	$$(Q)$$(call INSTALL_LIB, \
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(STDLIB_GLOB_$(1)))
59
	$$(Q)$$(call INSTALL_LIB,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),libmorestack.a)
60 61 62 63

endef

define INSTALL_HOST_N
64
install-target-$(1)-host-$(2): $$(CSREQ$$(ISTAGE)_T_$(1)_H_$(2))
65
	$$(Q)mkdir -p $$(PTL$(1)$(2))
66
	$$(Q)$$(call INSTALL_LIB,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_RUNTIME_$(1)))
67
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
68
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CORELIB_GLOB_$(1)))
69
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
70
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(STDLIB_GLOB_$(1)))
71
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
72
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBRUSTC_GLOB_$(1)))
73
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
74
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBSYNTAX_GLOB_$(1)))
75
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
76
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBRUSTPKG_GLOB_$(1)))
77
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
78
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBRUSTDOC_GLOB_$(1)))
79
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
80
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBRUSTI_GLOB_$(1)))
81
	$$(Q)$$(call INSTALL_LIB, \
B
Brian Anderson 已提交
82
		$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(LIBRUST_GLOB_$(1)))
83
	$$(Q)$$(call INSTALL_LIB,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),libmorestack.a)
84

85 86 87
endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
88 89 90
 $(if $(findstring $(target), $(CFG_BUILD_TRIPLE)), \
  $(eval $(call INSTALL_HOST_N,$(target),$(CFG_BUILD_TRIPLE))), \
  $(eval $(call INSTALL_TARGET_N,$(target),$(CFG_BUILD_TRIPLE)))))
91 92

INSTALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
93
 install-target-$(target)-host-$(CFG_BUILD_TRIPLE))
94

95
install: all install-host install-targets
96

N
Niko Matsakis 已提交
97
# Shorthand for build/stageN/bin
98 99
HB = $(HBIN$(ISTAGE)_H_$(CFG_BUILD_TRIPLE))
HB2 = $(HBIN2_H_$(CFG_BUILD_TRIPLE))
N
Niko Matsakis 已提交
100
# Shorthand for build/stageN/lib
101
HL = $(HLIB$(ISTAGE)_H_$(CFG_BUILD_TRIPLE))
N
Niko Matsakis 已提交
102 103 104 105 106
# Shorthand for the prefix bin directory
PHB = $(PREFIX_BIN)
# Shorthand for the prefix bin directory
PHL = $(PREFIX_LIB)

107
install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_TRIPLE)_H_$(CFG_BUILD_TRIPLE))
108 109
	$(Q)mkdir -p $(PREFIX_BIN)
	$(Q)mkdir -p $(PREFIX_LIB)
E
Elly Jones 已提交
110
	$(Q)mkdir -p $(PREFIX_ROOT)/share/man/man1
111 112 113 114 115
	$(Q)$(call INSTALL,$(HB2),$(PHB),rustc$(X_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL,$(HB2),$(PHB),rustpkg$(X_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL,$(HB2),$(PHB),rustdoc$(X_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL,$(HB2),$(PHB),rusti$(X_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL,$(HB2),$(PHB),rust$(X_$(CFG_BUILD_TRIPLE)))
B
Brian Anderson 已提交
116 117 118 119 120 121
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(CORELIB_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(STDLIB_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTC_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBSYNTAX_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTI_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUST_GLOB_$(CFG_BUILD_TRIPLE)))
122 123
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTPKG_GLOB_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTDOC_GLOB_$(CFG_BUILD_TRIPLE)))
B
Brian Anderson 已提交
124 125
	$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE)))
	$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE)))
B
Brian Anderson 已提交
126 127
	$(Q)$(call INSTALL,$(S)/man, \
	     $(PREFIX_ROOT)/share/man/man1,rustc.1)
128 129

install-targets: $(INSTALL_TARGET_RULES)
130 131 132


HOST_LIB_FROM_HL_GLOB = \
133
  $(patsubst $(HL)/%,$(PHL)/%,$(wildcard $(HL)/$(1)))
134 135

uninstall:
136 137 138 139 140
	$(Q)rm -f $(PHB)/rustc$(X_$(CFG_BUILD_TRIPLE))
	$(Q)rm -f $(PHB)/rustpkg$(X_$(CFG_BUILD_TRIPLE))
	$(Q)rm -f $(PHB)/rusti$(X_$(CFG_BUILD_TRIPLE))
	$(Q)rm -f $(PHB)/rust$(X_$(CFG_BUILD_TRIPLE))
	$(Q)rm -f $(PHB)/rustdoc$(X_$(CFG_BUILD_TRIPLE))
B
Brian Anderson 已提交
141 142
	$(Q)rm -f $(PHL)/$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE))
	$(Q)rm -f $(PHL)/$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE))
143
	$(Q)for i in \
B
Brian Anderson 已提交
144 145 146 147 148 149 150 151
          $(call HOST_LIB_FROM_HL_GLOB,$(CORELIB_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(STDLIB_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTC_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBSYNTAX_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTPKG_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTDOC_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTI_GLOB_$(CFG_BUILD_TRIPLE))) \
          $(call HOST_LIB_FROM_HL_GLOB,$(LIBRUST_GLOB_$(CFG_BUILD_TRIPLE))) \
152 153 154 155 156
        ; \
        do rm -f $$i ; \
        done
	$(Q)rm -Rf $(PHL)/rustc
	$(Q)rm -f $(PREFIX_ROOT)/share/man/man1/rustc.1
157 158 159

# target platform specific variables
# for arm-linux-androidabi
160 161
define DEF_ADB_DEVICE_STATUS
CFG_ADB_DEVICE_STATUS=$(1)
162 163 164 165
endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
  $(if $(findstring $(target),"arm-linux-androideabi"), \
166 167 168
    $(if $(findstring adb,$(CFG_ADB)), \
      $(if $(findstring device,$(shell adb devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
        $(info install: install-runtime-target for $(target) enabled \
169
          $(info install: android device attached) \
170 171
          $(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
        $(info install: install-runtime-target for $(target) disabled \
172
          $(info install: android device not attached) \
173
          $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
174
      ), \
175
      $(info install: install-runtime-target for $(target) disabled \
176
        $(info install: adb not found) \
177
        $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
178 179 180 181
    ), \
  ) \
)

182 183 184 185
ifeq (install-runtime-target,$(firstword $(MAKECMDGOALS)))
$(eval $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):;@:)
L_TOKEN := $(word 2,$(MAKECMDGOALS))
ifeq ($(L_TOKEN),)
186
CFG_RUNTIME_PUSH_DIR=/system/lib
187 188 189
else
CFG_RUNTIME_PUSH_DIR=$(L_TOKEN)
endif
190

191
ifeq ($(CFG_ADB_DEVICE_STATUS),true)
192 193 194 195 196
ifdef VERBOSE
 ADB = adb $(1)
 ADB_PUSH = adb push $(1) $(2)
 ADB_SHELL = adb shell $(1) $(2) 
else
197 198 199
 ADB = $(Q)$(call E, adb $(1)) && adb $(1) 1>/dev/null 
 ADB_PUSH = $(Q)$(call E, adb push $(1)) && adb push $(1) $(2) 1>/dev/null
 ADB_SHELL = $(Q)$(call E, adb shell $(1) $(2)) && adb shell $(1) $(2) 1>/dev/null
200 201 202 203
endif

define INSTALL_RUNTIME_TARGET_N
install-runtime-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
204 205 206 207
	$(Q)$(call ADB_SHELL,mkdir,$(CFG_RUNTIME_PUSH_DIR))
	$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(CFG_RUNTIME_$(1)),$(CFG_RUNTIME_PUSH_DIR))
	$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(CORELIB_GLOB_$(1)),$(CFG_RUNTIME_PUSH_DIR))
	$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(STDLIB_GLOB_$(1)),$(CFG_RUNTIME_PUSH_DIR))
208 209 210 211 212
endef

define INSTALL_RUNTIME_TARGET_CLEANUP_N
install-runtime-target-$(1)-cleanup:
	$(Q)$(call ADB,remount)
213 214 215
	$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(CFG_RUNTIME_$(1)))
	$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(CORELIB_GLOB_$(1)))
	$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(STDLIB_GLOB_$(1)))
216 217 218 219 220 221 222 223 224 225
endef

$(eval $(call INSTALL_RUNTIME_TARGET_N,arm-linux-androideabi,$(CFG_BUILD_TRIPLE)))
$(eval $(call INSTALL_RUNTIME_TARGET_CLEANUP_N,arm-linux-androideabi))

install-runtime-target: \
	install-runtime-target-arm-linux-androideabi-cleanup \
	install-runtime-target-arm-linux-androideabi-host-$(CFG_BUILD_TRIPLE)
else
install-runtime-target: 
226 227 228
	@echo "No device to install runtime library"
	@echo 
endif
229
endif