blob: dc4252da709424ac3d3516e5fa35d84d8186c78e [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 Yonkerbcc502c2014-11-10 11:22:10 -06005OUR_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -06006 start \
7 stop \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -05008
9ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
10 OUR_TOOLS += \
11 getprop \
12 setprop
13endif
Dees Troy8d66f8b2013-10-08 14:04:55 +000014
Matt Mower81742fb2014-09-01 14:40:52 -050015# If busybox does not have SELinux support, provide these tools with toolbox.
16# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Dees Troy8d66f8b2013-10-08 14:04:55 +000017ifeq ($(TWHAVE_SELINUX), true)
Matt Mower92084af2015-02-19 13:19:47 -060018 TOOLS_FOR_SELINUX := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050019 ls
20
21 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
22 TOOLS_FOR_SELINUX += \
23 load_policy \
24 getenforce \
25 chcon \
26 restorecon \
27 runcon \
28 getsebool \
29 setsebool
30 endif
31
Matt Mower92084af2015-02-19 13:19:47 -060032 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000033
Matt Mower92084af2015-02-19 13:19:47 -060034 # toolbox setenforce is used during init, so it needs to be included here
35 # symlink is omitted at the very end if busybox already provides this
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050036 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
37 OUR_TOOLS += setenforce
38 endif
Matt Mower92084af2015-02-19 13:19:47 -060039endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060040
Ethan Yonker5c933692014-04-04 11:26:32 -050041ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050042 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
43 # These are the only toolbox tools in M. The rest are now in toybox.
Matt Mower92084af2015-02-19 13:19:47 -060044 BSD_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -060045 dd \
46 du \
Matt Mower92084af2015-02-19 13:19:47 -060047
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050048 OUR_TOOLS := \
49 df \
50 iftop \
51 ioctl \
52 ionice \
53 log \
54 ls \
55 lsof \
56 mount \
57 nandread \
58 newfs_msdos \
59 ps \
60 prlimit \
61 renice \
62 sendevent \
63 start \
64 stop \
65 top \
66 uptime \
67 watchprops \
68
69 else
70 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
71 OUR_TOOLS += \
72 mknod \
73 nohup
74 BSD_TOOLS := \
75 cat \
76 chown \
77 cp \
78 dd \
79 du \
80 grep \
81 kill \
82 ln \
83 mv \
84 printenv \
85 rm \
86 rmdir \
87 sleep \
88 sync
89 else
90 OUR_TOOLS += \
91 cat \
92 chown \
93 dd \
94 du \
95 kill \
96 ln \
97 mv \
98 printenv \
99 rm \
100 rmdir \
101 setconsole \
102 sleep \
103 sync
104 endif
105
106 OUR_TOOLS += \
107 chmod \
108 clear \
109 cmp \
110 date \
111 df \
112 dmesg \
113 getevent \
114 hd \
115 id \
116 ifconfig \
117 iftop \
118 insmod \
119 ioctl \
120 ionice \
121 log \
122 lsmod \
123 lsof \
124 md5 \
125 mkdir \
126 mkswap \
127 mount \
128 nandread \
129 netstat \
130 newfs_msdos \
131 notify \
132 ps \
133 readlink \
134 renice \
135 rmmod \
136 route \
137 schedtop \
138 sendevent \
139 smd \
140 swapoff \
141 swapon \
142 top \
143 touch \
144 umount \
145 uptime \
146 vmstat \
147 watchprops \
148 wipe
149 ifneq ($(TWHAVE_SELINUX), true)
150 OUR_TOOLS += ls
151 endif
Matt Mower92084af2015-02-19 13:19:47 -0600152 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500153endif
154
Matt Mower92084af2015-02-19 13:19:47 -0600155ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
156 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
157 OUR_TOOLS += r
158 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600159endif
160
Dees Troy8d66f8b2013-10-08 14:04:55 +0000161LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600162 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600163 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000164
Matt Mower92084af2015-02-19 13:19:47 -0600165ifneq ($(wildcard system/core/toolbox/dynarray.c),)
166 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600167endif
168
Matt Mower92084af2015-02-19 13:19:47 -0600169ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
170 LOCAL_SRC_FILES += \
171 pwcache.c \
172 upstream-netbsd/lib/libc/gen/getbsize.c \
173 upstream-netbsd/lib/libc/gen/humanize_number.c \
174 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
175 upstream-netbsd/lib/libc/string/swab.c \
176 upstream-netbsd/lib/libutil/raise_default_signal.c
177endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000178
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500179ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600180 LOCAL_CFLAGS += \
181 -std=gnu99 \
182 -Werror -Wno-unused-parameter \
183 -I$(LOCAL_PATH)/upstream-netbsd/include \
184 -include bsd-compatibility.h
185endif
186
187ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
188 LOCAL_C_INCLUDES += external/openssl/include
189else
190 LOCAL_C_INCLUDES += bionic/libc/bionic
191endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000192
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600193LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000194
Matt Mower92084af2015-02-19 13:19:47 -0600195ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
196 ifeq ($(TW_USE_TOOLBOX), true)
197 LOCAL_SHARED_LIBRARIES += libcrypto
198 endif
199else
200 LOCAL_SHARED_LIBRARIES += \
201 libc \
202 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000203endif
204
Matt Mower92084af2015-02-19 13:19:47 -0600205ifeq ($(TWHAVE_SELINUX), true)
206 LOCAL_SHARED_LIBRARIES += libselinux
207endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600208
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500209ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600210 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
211 # The linker strips out all the unused library code in the normal case.
212 LOCAL_STATIC_LIBRARIES := libusbhost
213 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
214endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600215
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600216ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
217 # Rule to make getprop and setprop in M trees where toybox normally
218 # provides these tools. Toybox does not allow for easy dynamic
219 # configuration, so we would have to include the entire toybox binary
220 # which takes up more space than is necessary so long as we are still
221 # including busybox.
222 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600223 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
224 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c
225 OUR_TOOLS += getprop setprop
Ethan Yonker916cae82016-01-22 11:32:57 -0600226 ifneq ($(TW_USE_TOOLBOX), true)
227 LOCAL_SRC_FILES += ls.c
228 endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600229endif
230
Dees Troy8d66f8b2013-10-08 14:04:55 +0000231LOCAL_MODULE := toolbox_recovery
232LOCAL_MODULE_STEM := toolbox
233LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600234LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000235
Matt Mower92084af2015-02-19 13:19:47 -0600236# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000237include $(BUILD_EXECUTABLE)
238
239$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
240
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500241ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600242 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
243else
244 ALL_TOOLS := $(OUR_TOOLS)
245endif
246
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100247TOOLS_H := $(intermediates)/tools.h
248$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
249$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
250$(TOOLS_H): $(LOCAL_PATH)/Android.mk
251$(TOOLS_H):
252 $(transform-generated-source)
253
Matt Mower92084af2015-02-19 13:19:47 -0600254ifeq ($(TWHAVE_SELINUX), true)
255 # toolbox setenforce is used during init in non-symlink form, so it was
256 # required to be included as part of the suite above. if busybox already
257 # provides setenforce, we can omit the toolbox symlink
258 TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
259 ALL_TOOLS := $(TEMP_TOOLS)
260endif
261
Matt Mower92084af2015-02-19 13:19:47 -0600262# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600263SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000264$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
265$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
266 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
267 @mkdir -p $(dir $@)
268 @rm -rf $@
269 $(hide) ln -sf $(TOOLBOX_BINARY) $@
270
Matt Mower031163b2014-11-01 15:13:03 -0500271include $(CLEAR_VARS)
272LOCAL_MODULE := toolbox_symlinks
273LOCAL_MODULE_TAGS := optional
274LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
275include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600276
Dees Troyb47f28b2014-12-11 17:20:59 +0000277ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600278 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
279 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
280 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
281 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000282endif
283
Ethan Yonker75bf0412014-11-21 13:54:27 -0600284SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600285ALL_TOOLS :=
286BSD_TOOLS :=
287OUR_TOOLS :=
288TEMP_TOOLS :=
289TOOLS_FOR_SELINUX :=