blob: 5699aa5c8432d05d52c33220b7b73c67bf623c60 [file] [log] [blame]
Dees Troy8d66f8b2013-10-08 14:04:55 +00001LOCAL_PATH:= system/core/toolbox/
Ethan Yonkerbcc502c2014-11-10 11:22:10 -06002
3
erikcas1db013b2014-12-03 15:41:38 +01004ifeq ($(PLATFORM_VERSION), 5.0.1)
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
110ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)
111
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 Yonkerbcc502c2014-11-10 11:22:10 -0600123LOCAL_CFLAGS += $(common_cflags)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000124
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600125LOCAL_C_INCLUDES += external/openssl/include
Dees Troybb4c0cb2013-11-02 20:25:14 +0000126
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600127LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000128
129ifeq ($(TWHAVE_SELINUX), true)
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600130 LOCAL_SHARED_LIBRARIES += libselinux
131 LOCAL_STATIC_LIBRARIES += \
132 libtoolbox_cat \
133 libtoolbox_chown \
134 libtoolbox_cp \
135 libtoolbox_dd \
136 libtoolbox_grep \
137 libtoolbox_kill \
138 libtoolbox_ln \
139 libtoolbox_mv \
140 libtoolbox_printenv \
141 libtoolbox_rm \
142 libtoolbox_rmdir \
143 libtoolbox_sleep \
144 libtoolbox_sync
Dees Troy8d66f8b2013-10-08 14:04:55 +0000145endif
146
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600147# libusbhost is only used by lsusb, and that isn't usually included in toolbox.
148# The linker strips out all the unused library code in the normal case.
149LOCAL_STATIC_LIBRARIES := \
150 libusbhost \
151
152LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
153
Dees Troy8d66f8b2013-10-08 14:04:55 +0000154LOCAL_MODULE := toolbox_recovery
155LOCAL_MODULE_STEM := toolbox
156LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600157LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
Dees Troy8d66f8b2013-10-08 14:04:55 +0000158
159# Including this will define $(intermediates).
160#
161include $(BUILD_EXECUTABLE)
162
163$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
164
165TOOLS_H := $(intermediates)/tools.h
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600166$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000167$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
168$(TOOLS_H): $(LOCAL_PATH)/Android.mk
169$(TOOLS_H):
170 $(transform-generated-source)
171
172# Make #!/system/bin/toolbox launchers for each tool.
173#
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600174SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000175$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
176$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
177 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
178 @mkdir -p $(dir $@)
179 @rm -rf $@
180 $(hide) ln -sf $(TOOLBOX_BINARY) $@
181
Matt Mower031163b2014-11-01 15:13:03 -0500182include $(CLEAR_VARS)
183LOCAL_MODULE := toolbox_symlinks
184LOCAL_MODULE_TAGS := optional
185LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
186include $(BUILD_PHONY_PACKAGE)
187SYMLINKS :=
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600188
189# We need this so that the installed files could be picked up based on the
190# local module name
191ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
192 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600193
194else
195
196# Rule for older trees
197LOCAL_PATH:= system/core/toolbox/
198include $(CLEAR_VARS)
199
200TOOLS := \
201 start \
202 stop \
203 getprop \
204 setprop
205
206# If busybox does not have SELinux support, provide these tools with toolbox.
207# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
208ifeq ($(TWHAVE_SELINUX), true)
209 TOOLS_FOR_SELINUX := \
210 ls \
211 getenforce \
212 setenforce \
213 chcon \
214 restorecon \
215 runcon \
216 getsebool \
217 setsebool \
218 load_policy
219 TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
220endif
221
222ifeq ($(TW_USE_TOOLBOX), true)
223 TOOLS += \
224 mount \
225 cat \
226 ps \
227 kill \
228 ln \
229 insmod \
230 rmmod \
231 lsmod \
232 ifconfig \
233 setconsole \
234 rm \
235 mkdir \
236 rmdir \
237 getevent \
238 sendevent \
239 date \
240 wipe \
241 sync \
242 umount \
243 notify \
244 cmp \
245 dmesg \
246 route \
247 hd \
248 dd \
249 df \
250 watchprops \
251 log \
252 sleep \
253 renice \
254 printenv \
255 smd \
256 chmod \
257 chown \
258 newfs_msdos \
259 netstat \
260 ioctl \
261 mv \
262 schedtop \
263 top \
264 iftop \
265 id \
266 uptime \
267 vmstat \
268 nandread \
269 ionice \
270 touch \
271 lsof \
272 du \
273 md5 \
274 clear \
275 swapon \
276 swapoff \
277 mkswap \
278 readlink
279 ifneq ($(TWHAVE_SELINUX), true)
280 TOOLS += ls
281 endif
282endif
283
284LOCAL_SRC_FILES := \
285 toolbox.c \
286 $(patsubst %,%.c,$(TOOLS))
287
288ifneq ($(wildcard system/core/toolbox/dynarray.c),)
289 LOCAL_SRC_FILES += dynarray.c
290endif
291
292# reboot.c was removed in 4.4 kitkat
293#TOOLS += reboot
294
295#ifeq ($(BOARD_USES_BOOTMENU),true)
296# LOCAL_SRC_FILES += ../../../external/bootmenu/libreboot/reboot.c
297#else
298# LOCAL_SRC_FILES += reboot.c
299#endif
300
301LOCAL_C_INCLUDES := bionic/libc/bionic
302
303LOCAL_SHARED_LIBRARIES := \
304 libcutils \
305 liblog \
306 libc
307
308ifeq ($(TWHAVE_SELINUX), true)
309 LOCAL_SHARED_LIBRARIES += libselinux
310endif
311
312LOCAL_MODULE := toolbox_recovery
313LOCAL_MODULE_STEM := toolbox
314LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
315LOCAL_MODULE_TAGS := optional
316
317# Including this will define $(intermediates).
318#
319include $(BUILD_EXECUTABLE)
320
321$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
322
323TOOLS_H := $(intermediates)/tools.h
324$(TOOLS_H): PRIVATE_TOOLS := $(TOOLS)
325$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
326$(TOOLS_H): $(LOCAL_PATH)/Android.mk
327$(TOOLS_H):
328 $(transform-generated-source)
329
330# Make #!/system/bin/toolbox launchers for each tool.
331#
332SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(TOOLS))
333$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
334$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
335 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
336 @mkdir -p $(dir $@)
337 @rm -rf $@
338 $(hide) ln -sf $(TOOLBOX_BINARY) $@
339
340include $(CLEAR_VARS)
341LOCAL_MODULE := toolbox_symlinks
342LOCAL_MODULE_TAGS := optional
343LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
344include $(BUILD_PHONY_PACKAGE)
345SYMLINKS :=
346
347endif