]> git.lizzy.rs Git - rust.git/blob - mk/install.mk
auto merge of #13152 : huonw/rust/wtf-are-things-in-spans, r=alexcrichton
[rust.git] / mk / install.mk
1 # Copyright 2012 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 # FIXME: Docs are currently not installed from the stageN dirs.
12 # For consistency it might be desirable for stageN to be an exact
13 # mirror of the installation directory structure.
14
15 # The stage we install from
16 ISTAGE = $(PREPARE_STAGE)
17
18 $(eval $(call DEF_PREPARE,mkfile-install))
19
20 install: PREPARE_HOST=$(CFG_BUILD)
21 install: PREPARE_TARGETS=$(CFG_TARGET)
22 install: PREPARE_DIR_CMD=$(DEFAULT_PREPARE_DIR_CMD)
23 install: PREPARE_BIN_CMD=$(DEFAULT_PREPARE_BIN_CMD)
24 install: PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD)
25 install: PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
26 install: PREPARE_SOURCE_DIR=$(PREPARE_HOST)/stage$(PREPARE_STAGE)
27 install: PREPARE_SOURCE_BIN_DIR=$(PREPARE_SOURCE_DIR)/bin
28 install: PREPARE_SOURCE_LIB_DIR=$(PREPARE_SOURCE_DIR)/$(CFG_LIBDIR_RELATIVE)
29 install: PREPARE_SOURCE_MAN_DIR=$(S)/man
30 install: PREPARE_DEST_BIN_DIR=$(DESTDIR)$(CFG_PREFIX)/bin
31 install: PREPARE_DEST_LIB_DIR=$(DESTDIR)$(CFG_LIBDIR)
32 install: PREPARE_DEST_MAN_DIR=$(DESTDIR)$(CFG_MANDIR)/man1
33 install: prepare-everything-mkfile-install
34
35
36 # Uninstall code
37
38 PREFIX_ROOT = $(CFG_PREFIX)
39 PREFIX_BIN = $(PREFIX_ROOT)/bin
40 PREFIX_LIB = $(CFG_LIBDIR)
41
42 INSTALL_TOOLS := $(PREPARE_TOOLS)
43
44 # Shorthand for build/stageN/bin
45 HB = $(HBIN$(ISTAGE)_H_$(CFG_BUILD))
46 HB2 = $(HBIN2_H_$(CFG_BUILD))
47 # Shorthand for build/stageN/lib
48 HL = $(HLIB$(ISTAGE)_H_$(CFG_BUILD))
49 # Shorthand for the prefix bin directory
50 PHB = $(PREFIX_BIN)
51 # Shorthand for the prefix bin directory
52 PHL = $(PREFIX_LIB)
53
54 HOST_LIB_FROM_HL_GLOB = \
55   $(patsubst $(HL)/%,$(PHL)/%,$(wildcard $(HL)/$(1)))
56
57 uninstall: $(foreach tool,$(INSTALL_TOOLS),uninstall-tool-$(tool))
58         $(Q)rm -Rf $(PHL)/$(CFG_RUSTLIBDIR)
59
60 define UNINSTALL_TOOL
61 uninstall-tool-$(1): $$(foreach dep,$$(TOOL_DEPS_$(1)),uninstall-lib-$$(dep))
62         $$(Q)rm -f $$(PHB)/$(1)$$(X_$$(CFG_BUILD))
63         $$(Q)rm -f $$(CFG_MANDIR)/man1/$(1).1
64 endef
65
66 $(foreach tool,$(INSTALL_TOOLS),$(eval $(call UNINSTALL_TOOL,$(tool))))
67
68 define UNINSTALL_LIB
69 uninstall-lib-$(1): $$(foreach dep,$$(RUST_DEPS_$(1)),uninstall-lib-$$(dep))
70         $$(Q)rm -f $$(call HOST_LIB_FROM_HL_GLOB,$$(call CFG_LIB_GLOB_$$(CFG_BUILD),$(1)))
71 endef
72
73 $(foreach lib,$(CRATES),$(eval $(call UNINSTALL_LIB,$(lib))))
74
75
76 # Android runtime setup
77 # FIXME: This probably belongs somewhere else
78
79 # target platform specific variables
80 # for arm-linux-androidabi
81 define DEF_ADB_DEVICE_STATUS
82 CFG_ADB_DEVICE_STATUS=$(1)
83 endef
84
85 $(foreach target,$(CFG_TARGET), \
86   $(if $(findstring $(target),"arm-linux-androideabi"), \
87     $(if $(findstring adb,$(CFG_ADB)), \
88       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
89         $(info install: install-runtime-target for $(target) enabled \
90           $(info install: android device attached) \
91           $(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
92         $(info install: install-runtime-target for $(target) disabled \
93           $(info install: android device not attached) \
94           $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
95       ), \
96       $(info install: install-runtime-target for $(target) disabled \
97         $(info install: adb not found) \
98         $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
99     ), \
100   ) \
101 )
102
103 ifeq (install-runtime-target,$(firstword $(MAKECMDGOALS)))
104 $(eval $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):;@:)
105 L_TOKEN := $(word 2,$(MAKECMDGOALS))
106 ifeq ($(L_TOKEN),)
107 CFG_RUNTIME_PUSH_DIR=/system/lib
108 else
109 CFG_RUNTIME_PUSH_DIR=$(L_TOKEN)
110 endif
111
112 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
113 ifdef VERBOSE
114  ADB = adb $(1)
115  ADB_PUSH = adb push $(1) $(2)
116  ADB_SHELL = adb shell $(1) $(2)
117 else
118  ADB = $(Q)$(call E, adb $(1)) && adb $(1) 1>/dev/null
119  ADB_PUSH = $(Q)$(call E, adb push $(1)) && adb push $(1) $(2) 1>/dev/null
120  ADB_SHELL = $(Q)$(call E, adb shell $(1) $(2)) && adb shell $(1) $(2) 1>/dev/null
121 endif
122
123 define INSTALL_RUNTIME_TARGET_N
124 install-runtime-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
125         $$(Q)$$(call ADB_SHELL,mkdir,$(CFG_RUNTIME_PUSH_DIR))
126         $$(Q)$$(foreach crate,$$(TARGET_CRATES),\
127             $$(call ADB_PUSH,$$(TL$(1)$(2))/$$(call CFG_LIB_GLOB_$(1),$$(crate)),\
128                         $$(CFG_RUNTIME_PUSH_DIR));)
129 endef
130
131 define INSTALL_RUNTIME_TARGET_CLEANUP_N
132 install-runtime-target-$(1)-cleanup:
133         $$(Q)$$(call ADB,remount)
134         $$(Q)$$(foreach crate,$$(TARGET_CRATES),\
135             $$(call ADB_SHELL,rm,$$(CFG_RUNTIME_PUSH_DIR)/$$(call CFG_LIB_GLOB_$(1),$$(crate)));)
136 endef
137
138 $(eval $(call INSTALL_RUNTIME_TARGET_N,arm-linux-androideabi,$(CFG_BUILD)))
139 $(eval $(call INSTALL_RUNTIME_TARGET_CLEANUP_N,arm-linux-androideabi))
140
141 install-runtime-target: \
142         install-runtime-target-arm-linux-androideabi-cleanup \
143         install-runtime-target-arm-linux-androideabi-host-$(CFG_BUILD)
144 else
145 install-runtime-target:
146         @echo "No device to install runtime library"
147         @echo
148 endif
149 endif