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