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