blob: 4c3e433c21ced6dfd8abdc8340f36b27bf5a6118 [file] [log] [blame]
Ethan Yonker6bb26b52016-01-10 22:26:51 -06001TWRP_TOOLBOX_PATH := $(call my-dir)
Matt Mower92084af2015-02-19 13:19:47 -06002LOCAL_PATH := system/core/toolbox
Dees Troy8d66f8b2013-10-08 14:04:55 +00003include $(CLEAR_VARS)
4
Ethan Yonkerf1179622016-08-25 15:32:21 -05005OUR_TOOLS :=
6
7ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
8 OUR_TOOLS := \
9 start \
10 stop
11endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050012
13ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
14 OUR_TOOLS += \
15 getprop \
16 setprop
17endif
Dees Troy8d66f8b2013-10-08 14:04:55 +000018
Matt Mower81742fb2014-09-01 14:40:52 -050019# If busybox does not have SELinux support, provide these tools with toolbox.
20# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Dees Troy8d66f8b2013-10-08 14:04:55 +000021ifeq ($(TWHAVE_SELINUX), true)
Matt Mower92084af2015-02-19 13:19:47 -060022 TOOLS_FOR_SELINUX := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050023 ls
24
25 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
26 TOOLS_FOR_SELINUX += \
27 load_policy \
28 getenforce \
29 chcon \
30 restorecon \
31 runcon \
32 getsebool \
33 setsebool
34 endif
35
Matt Mower92084af2015-02-19 13:19:47 -060036 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000037
Matt Mower92084af2015-02-19 13:19:47 -060038 # toolbox setenforce is used during init, so it needs to be included here
39 # symlink is omitted at the very end if busybox already provides this
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050040 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
41 OUR_TOOLS += setenforce
42 endif
Matt Mower92084af2015-02-19 13:19:47 -060043endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060044
Ethan Yonker5c933692014-04-04 11:26:32 -050045ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050046 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
47 # These are the only toolbox tools in M. The rest are now in toybox.
Matt Mower92084af2015-02-19 13:19:47 -060048 BSD_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -060049 dd \
50 du \
Matt Mower92084af2015-02-19 13:19:47 -060051
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050052 OUR_TOOLS := \
53 df \
54 iftop \
55 ioctl \
56 ionice \
57 log \
58 ls \
59 lsof \
60 mount \
61 nandread \
62 newfs_msdos \
63 ps \
64 prlimit \
65 renice \
66 sendevent \
67 start \
68 stop \
69 top \
70 uptime \
71 watchprops \
72
73 else
74 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
75 OUR_TOOLS += \
76 mknod \
77 nohup
78 BSD_TOOLS := \
79 cat \
80 chown \
81 cp \
82 dd \
83 du \
84 grep \
85 kill \
86 ln \
87 mv \
88 printenv \
89 rm \
90 rmdir \
91 sleep \
92 sync
93 else
94 OUR_TOOLS += \
95 cat \
96 chown \
97 dd \
98 du \
99 kill \
100 ln \
101 mv \
102 printenv \
103 rm \
104 rmdir \
105 setconsole \
106 sleep \
107 sync
108 endif
109
110 OUR_TOOLS += \
111 chmod \
112 clear \
113 cmp \
114 date \
115 df \
116 dmesg \
117 getevent \
118 hd \
119 id \
120 ifconfig \
121 iftop \
122 insmod \
123 ioctl \
124 ionice \
125 log \
126 lsmod \
127 lsof \
128 md5 \
129 mkdir \
130 mkswap \
131 mount \
132 nandread \
133 netstat \
134 newfs_msdos \
135 notify \
136 ps \
137 readlink \
138 renice \
139 rmmod \
140 route \
141 schedtop \
142 sendevent \
143 smd \
144 swapoff \
145 swapon \
146 top \
147 touch \
148 umount \
149 uptime \
150 vmstat \
151 watchprops \
152 wipe
153 ifneq ($(TWHAVE_SELINUX), true)
154 OUR_TOOLS += ls
155 endif
Matt Mower92084af2015-02-19 13:19:47 -0600156 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500157endif
158
Matt Mower92084af2015-02-19 13:19:47 -0600159ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
160 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
161 OUR_TOOLS += r
162 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600163endif
164
Dees Troy8d66f8b2013-10-08 14:04:55 +0000165LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600166 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600167 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000168
Matt Mower92084af2015-02-19 13:19:47 -0600169ifneq ($(wildcard system/core/toolbox/dynarray.c),)
170 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600171endif
172
Matt Mower92084af2015-02-19 13:19:47 -0600173ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
174 LOCAL_SRC_FILES += \
175 pwcache.c \
176 upstream-netbsd/lib/libc/gen/getbsize.c \
177 upstream-netbsd/lib/libc/gen/humanize_number.c \
178 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
179 upstream-netbsd/lib/libc/string/swab.c \
180 upstream-netbsd/lib/libutil/raise_default_signal.c
181endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000182
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500183ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600184 LOCAL_CFLAGS += \
185 -std=gnu99 \
186 -Werror -Wno-unused-parameter \
187 -I$(LOCAL_PATH)/upstream-netbsd/include \
188 -include bsd-compatibility.h
189endif
190
191ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
192 LOCAL_C_INCLUDES += external/openssl/include
193else
194 LOCAL_C_INCLUDES += bionic/libc/bionic
195endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000196
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600197LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000198
Matt Mower92084af2015-02-19 13:19:47 -0600199ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
200 ifeq ($(TW_USE_TOOLBOX), true)
201 LOCAL_SHARED_LIBRARIES += libcrypto
202 endif
203else
204 LOCAL_SHARED_LIBRARIES += \
205 libc \
206 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000207endif
208
Matt Mower92084af2015-02-19 13:19:47 -0600209ifeq ($(TWHAVE_SELINUX), true)
210 LOCAL_SHARED_LIBRARIES += libselinux
211endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600212
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500213ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600214 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
215 # The linker strips out all the unused library code in the normal case.
216 LOCAL_STATIC_LIBRARIES := libusbhost
217 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
218endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600219
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600220ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
221 # Rule to make getprop and setprop in M trees where toybox normally
222 # provides these tools. Toybox does not allow for easy dynamic
223 # configuration, so we would have to include the entire toybox binary
224 # which takes up more space than is necessary so long as we are still
225 # including busybox.
226 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600227 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
228 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c
229 OUR_TOOLS += getprop setprop
Ethan Yonker916cae82016-01-22 11:32:57 -0600230 ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker34ae4832016-08-24 15:32:18 -0500231 LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker916cae82016-01-22 11:32:57 -0600232 endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600233endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500234ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
235 # Rule for making start and stop in N trees
236 LOCAL_SRC_FILES += \
237 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
238 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
239 OUR_TOOLS += start stop
240endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600241
Dees Troy8d66f8b2013-10-08 14:04:55 +0000242LOCAL_MODULE := toolbox_recovery
243LOCAL_MODULE_STEM := toolbox
244LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600245LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000246
Matt Mower92084af2015-02-19 13:19:47 -0600247# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000248include $(BUILD_EXECUTABLE)
249
250$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
251
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500252ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600253 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
254else
255 ALL_TOOLS := $(OUR_TOOLS)
256endif
257
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100258TOOLS_H := $(intermediates)/tools.h
259$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
260$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
261$(TOOLS_H): $(LOCAL_PATH)/Android.mk
262$(TOOLS_H):
263 $(transform-generated-source)
264
Matt Mower92084af2015-02-19 13:19:47 -0600265ifeq ($(TWHAVE_SELINUX), true)
266 # toolbox setenforce is used during init in non-symlink form, so it was
267 # required to be included as part of the suite above. if busybox already
268 # provides setenforce, we can omit the toolbox symlink
269 TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
270 ALL_TOOLS := $(TEMP_TOOLS)
271endif
272
Matt Mower92084af2015-02-19 13:19:47 -0600273# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600274SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000275$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
276$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
277 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
278 @mkdir -p $(dir $@)
279 @rm -rf $@
280 $(hide) ln -sf $(TOOLBOX_BINARY) $@
281
Matt Mower031163b2014-11-01 15:13:03 -0500282include $(CLEAR_VARS)
283LOCAL_MODULE := toolbox_symlinks
284LOCAL_MODULE_TAGS := optional
285LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
286include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600287
Dees Troyb47f28b2014-12-11 17:20:59 +0000288ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600289 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
290 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
291 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
292 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000293endif
294
Ethan Yonker75bf0412014-11-21 13:54:27 -0600295SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600296ALL_TOOLS :=
297BSD_TOOLS :=
298OUR_TOOLS :=
299TEMP_TOOLS :=
300TOOLS_FOR_SELINUX :=