blob: 93e96a8a9331686cb4e00444a8550a53e119def9 [file] [log] [blame]
Dees Troy8d66f8b2013-10-08 14:04:55 +00001LOCAL_PATH:= system/core/toolbox/
Ethan Yonkerbcc502c2014-11-10 11:22:10 -06002
3
Ethan Yonker738be7a2014-12-10 11:40:43 -06004ifeq ($(PLATFORM_SDK_VERSION), 21)
Ethan Yonker75bf0412014-11-21 13:54:27 -06005
6# Rule for lollipop
Ethan Yonkerbcc502c2014-11-10 11:22:10 -06007common_cflags := \
8 -std=gnu99 \
9 -Werror -Wno-unused-parameter \
10 -I$(LOCAL_PATH)/upstream-netbsd/include/ \
11 -include bsd-compatibility.h
12
Dees Troy8d66f8b2013-10-08 14:04:55 +000013include $(CLEAR_VARS)
14
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060015OUR_TOOLS := \
Dees Troy8d66f8b2013-10-08 14:04:55 +000016 start \
17 stop \
18 getprop \
19 setprop
20
Matt Mower81742fb2014-09-01 14:40:52 -050021# If busybox does not have SELinux support, provide these tools with toolbox.
22# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Dees Troy8d66f8b2013-10-08 14:04:55 +000023ifeq ($(TWHAVE_SELINUX), true)
Matt Mower81742fb2014-09-01 14:40:52 -050024 TOOLS_FOR_SELINUX := \
Dees Troy8d66f8b2013-10-08 14:04:55 +000025 ls \
26 getenforce \
27 setenforce \
28 chcon \
29 restorecon \
30 runcon \
31 getsebool \
32 setsebool \
33 load_policy
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060034 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000035endif
36
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060037
Ethan Yonker5c933692014-04-04 11:26:32 -050038ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060039BSD_TOOLS := \
40 cat \
41 chown \
42 cp \
43 dd \
44 du \
45 grep \
46 kill \
47 ln \
48 mv \
49 printenv \
50 rm \
51 rmdir \
52 sleep \
53 sync \
54
55OUR_TOOLS += \
56 chmod \
57 clear \
58 cmp \
59 date \
60 df \
61 dmesg \
62 getevent \
63 hd \
64 id \
65 ifconfig \
66 iftop \
67 insmod \
68 ioctl \
69 ionice \
70 log \
71 lsmod \
72 lsof \
73 md5 \
74 mkdir \
75 mknod \
76 mkswap \
77 mount \
78 nandread \
79 netstat \
80 newfs_msdos \
81 nohup \
82 notify \
83 ps \
84 readlink \
85 renice \
86 rmmod \
87 route \
88 schedtop \
89 sendevent \
90 smd \
91 swapoff \
92 swapon \
93 top \
94 touch \
95 umount \
96 uptime \
97 vmstat \
98 watchprops \
99 wipe
100 ifneq ($(TWHAVE_SELINUX), true)
101 TOOLS += ls
102 endif
103 LOCAL_SHARED_LIBRARIES += libcrypto
Ethan Yonker5c933692014-04-04 11:26:32 -0500104endif
105
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600106ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
107OUR_TOOLS += r
108endif
109
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600110ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) setenforce
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600111
Dees Troy8d66f8b2013-10-08 14:04:55 +0000112LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600113 upstream-netbsd/lib/libc/gen/getbsize.c \
114 upstream-netbsd/lib/libc/gen/humanize_number.c \
115 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
116 upstream-netbsd/lib/libc/string/swab.c \
117 upstream-netbsd/lib/libutil/raise_default_signal.c \
118 dynarray.c \
119 pwcache.c \
120 $(patsubst %,%.c,$(OUR_TOOLS)) \
121 toolbox.c \
Dees Troy8d66f8b2013-10-08 14:04:55 +0000122
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600123ifeq (,$(filter $(LOCAL_SRC_FILES),setenforce.c))
124 LOCAL_SRC_FILES += setenforce.c
125endif
126
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600127LOCAL_CFLAGS += $(common_cflags)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000128
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600129LOCAL_C_INCLUDES += external/openssl/include
Dees Troybb4c0cb2013-11-02 20:25:14 +0000130
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600131LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000132
133ifeq ($(TWHAVE_SELINUX), true)
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600134 LOCAL_SHARED_LIBRARIES += libselinux
135 LOCAL_STATIC_LIBRARIES += \
136 libtoolbox_cat \
137 libtoolbox_chown \
138 libtoolbox_cp \
139 libtoolbox_dd \
140 libtoolbox_grep \
141 libtoolbox_kill \
142 libtoolbox_ln \
143 libtoolbox_mv \
144 libtoolbox_printenv \
145 libtoolbox_rm \
146 libtoolbox_rmdir \
147 libtoolbox_sleep \
148 libtoolbox_sync
Dees Troy8d66f8b2013-10-08 14:04:55 +0000149endif
150
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600151# libusbhost is only used by lsusb, and that isn't usually included in toolbox.
152# The linker strips out all the unused library code in the normal case.
153LOCAL_STATIC_LIBRARIES := \
154 libusbhost \
155
156LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
157
Dees Troy8d66f8b2013-10-08 14:04:55 +0000158LOCAL_MODULE := toolbox_recovery
159LOCAL_MODULE_STEM := toolbox
160LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600161LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
Dees Troy8d66f8b2013-10-08 14:04:55 +0000162
163# Including this will define $(intermediates).
164#
165include $(BUILD_EXECUTABLE)
166
167$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
168
169TOOLS_H := $(intermediates)/tools.h
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600170$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000171$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
172$(TOOLS_H): $(LOCAL_PATH)/Android.mk
173$(TOOLS_H):
174 $(transform-generated-source)
175
176# Make #!/system/bin/toolbox launchers for each tool.
177#
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600178SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000179$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
180$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
181 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
182 @mkdir -p $(dir $@)
183 @rm -rf $@
184 $(hide) ln -sf $(TOOLBOX_BINARY) $@
185
Matt Mower031163b2014-11-01 15:13:03 -0500186include $(CLEAR_VARS)
187LOCAL_MODULE := toolbox_symlinks
188LOCAL_MODULE_TAGS := optional
189LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
190include $(BUILD_PHONY_PACKAGE)
191SYMLINKS :=
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600192
193# We need this so that the installed files could be picked up based on the
194# local module name
195ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
196 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600197
198else
199
200# Rule for older trees
201LOCAL_PATH:= system/core/toolbox/
202include $(CLEAR_VARS)
203
204TOOLS := \
205 start \
206 stop \
207 getprop \
208 setprop
209
210# If busybox does not have SELinux support, provide these tools with toolbox.
211# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
212ifeq ($(TWHAVE_SELINUX), true)
213 TOOLS_FOR_SELINUX := \
214 ls \
215 getenforce \
216 setenforce \
217 chcon \
218 restorecon \
219 runcon \
220 getsebool \
221 setsebool \
222 load_policy
223 TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
224endif
225
226ifeq ($(TW_USE_TOOLBOX), true)
227 TOOLS += \
228 mount \
229 cat \
230 ps \
231 kill \
232 ln \
233 insmod \
234 rmmod \
235 lsmod \
236 ifconfig \
237 setconsole \
238 rm \
239 mkdir \
240 rmdir \
241 getevent \
242 sendevent \
243 date \
244 wipe \
245 sync \
246 umount \
247 notify \
248 cmp \
249 dmesg \
250 route \
251 hd \
252 dd \
253 df \
254 watchprops \
255 log \
256 sleep \
257 renice \
258 printenv \
259 smd \
260 chmod \
261 chown \
262 newfs_msdos \
263 netstat \
264 ioctl \
265 mv \
266 schedtop \
267 top \
268 iftop \
269 id \
270 uptime \
271 vmstat \
272 nandread \
273 ionice \
274 touch \
275 lsof \
276 du \
277 md5 \
278 clear \
279 swapon \
280 swapoff \
281 mkswap \
282 readlink
283 ifneq ($(TWHAVE_SELINUX), true)
284 TOOLS += ls
285 endif
286endif
287
288LOCAL_SRC_FILES := \
289 toolbox.c \
290 $(patsubst %,%.c,$(TOOLS))
291
292ifneq ($(wildcard system/core/toolbox/dynarray.c),)
293 LOCAL_SRC_FILES += dynarray.c
294endif
295
296# reboot.c was removed in 4.4 kitkat
297#TOOLS += reboot
298
299#ifeq ($(BOARD_USES_BOOTMENU),true)
300# LOCAL_SRC_FILES += ../../../external/bootmenu/libreboot/reboot.c
301#else
302# LOCAL_SRC_FILES += reboot.c
303#endif
304
305LOCAL_C_INCLUDES := bionic/libc/bionic
306
307LOCAL_SHARED_LIBRARIES := \
308 libcutils \
309 liblog \
310 libc
311
312ifeq ($(TWHAVE_SELINUX), true)
313 LOCAL_SHARED_LIBRARIES += libselinux
314endif
315
316LOCAL_MODULE := toolbox_recovery
317LOCAL_MODULE_STEM := toolbox
318LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
319LOCAL_MODULE_TAGS := optional
320
321# Including this will define $(intermediates).
322#
323include $(BUILD_EXECUTABLE)
324
325$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
326
327TOOLS_H := $(intermediates)/tools.h
328$(TOOLS_H): PRIVATE_TOOLS := $(TOOLS)
329$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
330$(TOOLS_H): $(LOCAL_PATH)/Android.mk
331$(TOOLS_H):
332 $(transform-generated-source)
333
334# Make #!/system/bin/toolbox launchers for each tool.
335#
336SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(TOOLS))
337$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
338$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
339 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
340 @mkdir -p $(dir $@)
341 @rm -rf $@
342 $(hide) ln -sf $(TOOLBOX_BINARY) $@
343
Dees Troyb47f28b2014-12-11 17:20:59 +0000344ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
345ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
346
347# We need this so that the installed files could be picked up based on the
348# local module name
349ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
350 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
351endif
352
Ethan Yonker75bf0412014-11-21 13:54:27 -0600353include $(CLEAR_VARS)
354LOCAL_MODULE := toolbox_symlinks
355LOCAL_MODULE_TAGS := optional
356LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
357include $(BUILD_PHONY_PACKAGE)
358SYMLINKS :=
359
360endif