]> git.lizzy.rs Git - rust.git/blob - mk/install.mk
Rollup merge of #38299 - achanda:ctrl-c, r=brson
[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 RUN_INSTALLER = cd tmp/empty_dir && \
12         sh ../../tmp/dist/$(1)/install.sh \
13                 --prefix="$(DESTDIR)$(CFG_PREFIX)" \
14                 --libdir="$(DESTDIR)$(CFG_LIBDIR)" \
15                 --mandir="$(DESTDIR)$(CFG_MANDIR)" \
16                 --docdir="$(DESTDIR)$(CFG_DOCDIR)"
17
18 install:
19 ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
20 # Build the dist as the original user
21         $(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_install
22 else
23         $(Q)$(MAKE) prepare_install
24 endif
25 ifeq ($(CFG_DISABLE_DOCS),)
26         $(Q)$(call RUN_INSTALLER,$(DOC_PKG_NAME)-$(CFG_BUILD)) --disable-ldconfig
27 endif
28         $(Q)$(foreach target,$(CFG_TARGET),\
29           ($(call RUN_INSTALLER,$(STD_PKG_NAME)-$(target)) --disable-ldconfig);)
30         $(Q)$(call RUN_INSTALLER,$(PKG_NAME)-$(CFG_BUILD))
31 # Remove tmp files because it's a decent amount of disk space
32         $(Q)rm -R tmp/dist
33
34 prepare_install: dist-tar-bins | tmp/empty_dir
35
36 uninstall:
37 ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
38 # Build the dist as the original user
39         $(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_uninstall
40 else
41         $(Q)$(MAKE) prepare_uninstall
42 endif
43 ifeq ($(CFG_DISABLE_DOCS),)
44         $(Q)$(call RUN_INSTALLER,$(DOC_PKG_NAME)-$(CFG_BUILD)) --uninstall
45 endif
46         $(Q)$(call RUN_INSTALLER,$(PKG_NAME)-$(CFG_BUILD)) --uninstall
47         $(Q)$(foreach target,$(CFG_TARGET),\
48           ($(call RUN_INSTALLER,$(STD_PKG_NAME)-$(target)) --uninstall);)
49 # Remove tmp files because it's a decent amount of disk space
50         $(Q)rm -R tmp/dist
51
52 prepare_uninstall: dist-tar-bins | tmp/empty_dir
53
54 .PHONY: install prepare_install uninstall prepare_uninstall
55
56 tmp/empty_dir:
57         mkdir -p $@
58
59 ######################################################################
60 # Android remote installation
61 ######################################################################
62
63 # Android runtime setup
64 # FIXME: This probably belongs somewhere else
65
66 # target platform specific variables for android
67 define DEF_ADB_DEVICE_STATUS
68 CFG_ADB_DEVICE_STATUS=$(1)
69 endef
70
71 $(foreach target,$(CFG_TARGET), \
72   $(if $(findstring android, $(target)), \
73     $(if $(findstring adb,$(CFG_ADB)), \
74       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
75         $(info install: install-runtime-target for $(target) enabled \
76           $(info install: android device attached) \
77           $(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
78         $(info install: install-runtime-target for $(target) disabled \
79           $(info install: android device not attached) \
80           $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
81       ), \
82       $(info install: install-runtime-target for $(target) disabled \
83         $(info install: adb not found) \
84         $(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
85     ), \
86   ) \
87 )
88
89 ifeq (install-runtime-target,$(firstword $(MAKECMDGOALS)))
90 $(eval $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):;@:)
91 L_TOKEN := $(word 2,$(MAKECMDGOALS))
92 ifeq ($(L_TOKEN),)
93 CFG_RUNTIME_PUSH_DIR=/system/lib
94 else
95 CFG_RUNTIME_PUSH_DIR=$(L_TOKEN)
96 endif
97
98 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
99 ifdef VERBOSE
100  ADB = adb $(1)
101  ADB_PUSH = adb push $(1) $(2)
102  ADB_SHELL = adb shell $(1) $(2)
103 else
104  ADB = $(Q)$(call E, adb $(1)) && adb $(1) 1>/dev/null
105  ADB_PUSH = $(Q)$(call E, adb push $(1)) && adb push $(1) $(2) 1>/dev/null
106  ADB_SHELL = $(Q)$(call E, adb shell $(1) $(2)) && adb shell $(1) $(2) 1>/dev/null
107 endif
108
109 define INSTALL_RUNTIME_TARGET_N
110 install-runtime-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
111         $$(Q)$$(call ADB_SHELL,mkdir,$(CFG_RUNTIME_PUSH_DIR))
112         $$(Q)$$(foreach crate,$$(TARGET_CRATES_$(1)), \
113             $$(call ADB_PUSH,$$(TL$(1)$(2))/$$(call CFG_LIB_GLOB_$(1),$$(crate)), \
114                         $$(CFG_RUNTIME_PUSH_DIR));)
115 endef
116
117 define INSTALL_RUNTIME_TARGET_CLEANUP_N
118 install-runtime-target-$(1)-cleanup:
119         $$(Q)$$(call ADB,remount)
120         $$(Q)$$(foreach crate,$$(TARGET_CRATES_$(1)), \
121             $$(call ADB_SHELL,rm,$$(CFG_RUNTIME_PUSH_DIR)/$$(call CFG_LIB_GLOB_$(1),$$(crate)));)
122 endef
123
124 $(foreach target,$(CFG_TARGET), \
125  $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
126   $(eval $(call INSTALL_RUNTIME_TARGET_N,$(taget),$(CFG_BUILD))) \
127   $(eval $(call INSTALL_RUNTIME_TARGET_CLEANUP_N,$(target))) \
128   ))
129
130 install-runtime-target: \
131         install-runtime-target-arm-linux-androideabi-cleanup \
132         install-runtime-target-arm-linux-androideabi-host-$(CFG_BUILD)
133 else
134 install-runtime-target:
135         @echo "No device to install runtime library"
136         @echo
137 endif
138 endif