blob: d54bfa4401a494017409d8c0e26caf2137156ed4 [file] [log] [blame]
Matt Mower92084af2015-02-19 13:19:47 -06001LOCAL_PATH := system/core/toolbox
Dees Troy8d66f8b2013-10-08 14:04:55 +00002include $(CLEAR_VARS)
3
Ethan Yonkerbcc502c2014-11-10 11:22:10 -06004OUR_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -06005 start \
6 stop \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -05007
8ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
9 OUR_TOOLS += \
10 getprop \
11 setprop
12endif
Dees Troy8d66f8b2013-10-08 14:04:55 +000013
Matt Mower81742fb2014-09-01 14:40:52 -050014# If busybox does not have SELinux support, provide these tools with toolbox.
15# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Dees Troy8d66f8b2013-10-08 14:04:55 +000016ifeq ($(TWHAVE_SELINUX), true)
Matt Mower92084af2015-02-19 13:19:47 -060017 TOOLS_FOR_SELINUX := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050018 ls
19
20 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
21 TOOLS_FOR_SELINUX += \
22 load_policy \
23 getenforce \
24 chcon \
25 restorecon \
26 runcon \
27 getsebool \
28 setsebool
29 endif
30
Matt Mower92084af2015-02-19 13:19:47 -060031 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000032
Matt Mower92084af2015-02-19 13:19:47 -060033 # toolbox setenforce is used during init, so it needs to be included here
34 # symlink is omitted at the very end if busybox already provides this
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050035 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
36 OUR_TOOLS += setenforce
37 endif
Matt Mower92084af2015-02-19 13:19:47 -060038endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060039
Ethan Yonker5c933692014-04-04 11:26:32 -050040ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050041 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
42 # These are the only toolbox tools in M. The rest are now in toybox.
Matt Mower92084af2015-02-19 13:19:47 -060043 BSD_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -060044 dd \
45 du \
Matt Mower92084af2015-02-19 13:19:47 -060046
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050047 OUR_TOOLS := \
48 df \
49 iftop \
50 ioctl \
51 ionice \
52 log \
53 ls \
54 lsof \
55 mount \
56 nandread \
57 newfs_msdos \
58 ps \
59 prlimit \
60 renice \
61 sendevent \
62 start \
63 stop \
64 top \
65 uptime \
66 watchprops \
67
68 else
69 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
70 OUR_TOOLS += \
71 mknod \
72 nohup
73 BSD_TOOLS := \
74 cat \
75 chown \
76 cp \
77 dd \
78 du \
79 grep \
80 kill \
81 ln \
82 mv \
83 printenv \
84 rm \
85 rmdir \
86 sleep \
87 sync
88 else
89 OUR_TOOLS += \
90 cat \
91 chown \
92 dd \
93 du \
94 kill \
95 ln \
96 mv \
97 printenv \
98 rm \
99 rmdir \
100 setconsole \
101 sleep \
102 sync
103 endif
104
105 OUR_TOOLS += \
106 chmod \
107 clear \
108 cmp \
109 date \
110 df \
111 dmesg \
112 getevent \
113 hd \
114 id \
115 ifconfig \
116 iftop \
117 insmod \
118 ioctl \
119 ionice \
120 log \
121 lsmod \
122 lsof \
123 md5 \
124 mkdir \
125 mkswap \
126 mount \
127 nandread \
128 netstat \
129 newfs_msdos \
130 notify \
131 ps \
132 readlink \
133 renice \
134 rmmod \
135 route \
136 schedtop \
137 sendevent \
138 smd \
139 swapoff \
140 swapon \
141 top \
142 touch \
143 umount \
144 uptime \
145 vmstat \
146 watchprops \
147 wipe
148 ifneq ($(TWHAVE_SELINUX), true)
149 OUR_TOOLS += ls
150 endif
Matt Mower92084af2015-02-19 13:19:47 -0600151 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500152endif
153
Matt Mower92084af2015-02-19 13:19:47 -0600154ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
155 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
156 OUR_TOOLS += r
157 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600158endif
159
Dees Troy8d66f8b2013-10-08 14:04:55 +0000160LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600161 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600162 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000163
Matt Mower92084af2015-02-19 13:19:47 -0600164ifneq ($(wildcard system/core/toolbox/dynarray.c),)
165 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600166endif
167
Matt Mower92084af2015-02-19 13:19:47 -0600168ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
169 LOCAL_SRC_FILES += \
170 pwcache.c \
171 upstream-netbsd/lib/libc/gen/getbsize.c \
172 upstream-netbsd/lib/libc/gen/humanize_number.c \
173 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
174 upstream-netbsd/lib/libc/string/swab.c \
175 upstream-netbsd/lib/libutil/raise_default_signal.c
176endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000177
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500178ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600179 LOCAL_CFLAGS += \
180 -std=gnu99 \
181 -Werror -Wno-unused-parameter \
182 -I$(LOCAL_PATH)/upstream-netbsd/include \
183 -include bsd-compatibility.h
184endif
185
186ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
187 LOCAL_C_INCLUDES += external/openssl/include
188else
189 LOCAL_C_INCLUDES += bionic/libc/bionic
190endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000191
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600192LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000193
Matt Mower92084af2015-02-19 13:19:47 -0600194ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
195 ifeq ($(TW_USE_TOOLBOX), true)
196 LOCAL_SHARED_LIBRARIES += libcrypto
197 endif
198else
199 LOCAL_SHARED_LIBRARIES += \
200 libc \
201 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000202endif
203
Matt Mower92084af2015-02-19 13:19:47 -0600204ifeq ($(TWHAVE_SELINUX), true)
205 LOCAL_SHARED_LIBRARIES += libselinux
206endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600207
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500208ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600209 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
210 # The linker strips out all the unused library code in the normal case.
211 LOCAL_STATIC_LIBRARIES := libusbhost
212 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
213endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600214
Dees Troy8d66f8b2013-10-08 14:04:55 +0000215LOCAL_MODULE := toolbox_recovery
216LOCAL_MODULE_STEM := toolbox
217LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600218LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000219
Matt Mower92084af2015-02-19 13:19:47 -0600220# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000221include $(BUILD_EXECUTABLE)
222
223$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
224
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500225ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600226 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
227else
228 ALL_TOOLS := $(OUR_TOOLS)
229endif
230
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100231TOOLS_H := $(intermediates)/tools.h
232$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
233$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
234$(TOOLS_H): $(LOCAL_PATH)/Android.mk
235$(TOOLS_H):
236 $(transform-generated-source)
237
Matt Mower92084af2015-02-19 13:19:47 -0600238ifeq ($(TWHAVE_SELINUX), true)
239 # toolbox setenforce is used during init in non-symlink form, so it was
240 # required to be included as part of the suite above. if busybox already
241 # provides setenforce, we can omit the toolbox symlink
242 TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
243 ALL_TOOLS := $(TEMP_TOOLS)
244endif
245
Matt Mower92084af2015-02-19 13:19:47 -0600246# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600247SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000248$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
249$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
250 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
251 @mkdir -p $(dir $@)
252 @rm -rf $@
253 $(hide) ln -sf $(TOOLBOX_BINARY) $@
254
Matt Mower031163b2014-11-01 15:13:03 -0500255include $(CLEAR_VARS)
256LOCAL_MODULE := toolbox_symlinks
257LOCAL_MODULE_TAGS := optional
258LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
259include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600260
Dees Troyb47f28b2014-12-11 17:20:59 +0000261ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600262 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
263 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
264 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
265 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000266endif
267
Ethan Yonker75bf0412014-11-21 13:54:27 -0600268SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600269ALL_TOOLS :=
270BSD_TOOLS :=
271OUR_TOOLS :=
272TEMP_TOOLS :=
273TOOLS_FOR_SELINUX :=