blob: 9e7bbc4e60d55c5bc043ab6e8ffd105458cb6ebb [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 \
7 getprop \
8 setprop
Dees Troy8d66f8b2013-10-08 14:04:55 +00009
Matt Mower81742fb2014-09-01 14:40:52 -050010# If busybox does not have SELinux support, provide these tools with toolbox.
11# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Dees Troy8d66f8b2013-10-08 14:04:55 +000012ifeq ($(TWHAVE_SELINUX), true)
Matt Mower92084af2015-02-19 13:19:47 -060013 TOOLS_FOR_SELINUX := \
14 ls \
15 getenforce \
16 chcon \
17 restorecon \
18 runcon \
19 getsebool \
20 setsebool \
21 load_policy
22 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000023
Matt Mower92084af2015-02-19 13:19:47 -060024 # toolbox setenforce is used during init, so it needs to be included here
25 # symlink is omitted at the very end if busybox already provides this
26 OUR_TOOLS += setenforce
27endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060028
Ethan Yonker5c933692014-04-04 11:26:32 -050029ifeq ($(TW_USE_TOOLBOX), true)
Matt Mower92084af2015-02-19 13:19:47 -060030 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
31 OUR_TOOLS += \
32 mknod \
33 nohup
34 BSD_TOOLS := \
35 cat \
36 chown \
37 cp \
38 dd \
39 du \
40 grep \
41 kill \
42 ln \
43 mv \
44 printenv \
45 rm \
46 rmdir \
47 sleep \
48 sync
49 else
50 OUR_TOOLS += \
51 cat \
52 chown \
53 dd \
54 du \
55 kill \
56 ln \
57 mv \
58 printenv \
59 rm \
60 rmdir \
61 setconsole \
62 sleep \
63 sync
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060064 endif
Matt Mower92084af2015-02-19 13:19:47 -060065
66 OUR_TOOLS += \
67 chmod \
68 clear \
69 cmp \
70 date \
71 df \
72 dmesg \
73 getevent \
74 hd \
75 id \
76 ifconfig \
77 iftop \
78 insmod \
79 ioctl \
80 ionice \
81 log \
82 lsmod \
83 lsof \
84 md5 \
85 mkdir \
86 mkswap \
87 mount \
88 nandread \
89 netstat \
90 newfs_msdos \
91 notify \
92 ps \
93 readlink \
94 renice \
95 rmmod \
96 route \
97 schedtop \
98 sendevent \
99 smd \
100 swapoff \
101 swapon \
102 top \
103 touch \
104 umount \
105 uptime \
106 vmstat \
107 watchprops \
108 wipe
109 ifneq ($(TWHAVE_SELINUX), true)
110 OUR_TOOLS += ls
111 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500112endif
113
Matt Mower92084af2015-02-19 13:19:47 -0600114ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
115 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
116 OUR_TOOLS += r
117 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600118endif
119
Dees Troy8d66f8b2013-10-08 14:04:55 +0000120LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600121 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600122 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000123
Matt Mower92084af2015-02-19 13:19:47 -0600124ifneq ($(wildcard system/core/toolbox/dynarray.c),)
125 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600126endif
127
Matt Mower92084af2015-02-19 13:19:47 -0600128ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
129 LOCAL_SRC_FILES += \
130 pwcache.c \
131 upstream-netbsd/lib/libc/gen/getbsize.c \
132 upstream-netbsd/lib/libc/gen/humanize_number.c \
133 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
134 upstream-netbsd/lib/libc/string/swab.c \
135 upstream-netbsd/lib/libutil/raise_default_signal.c
136endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000137
Matt Mower92084af2015-02-19 13:19:47 -0600138ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
139 LOCAL_CFLAGS += \
140 -std=gnu99 \
141 -Werror -Wno-unused-parameter \
142 -I$(LOCAL_PATH)/upstream-netbsd/include \
143 -include bsd-compatibility.h
144endif
145
146ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
147 LOCAL_C_INCLUDES += external/openssl/include
148else
149 LOCAL_C_INCLUDES += bionic/libc/bionic
150endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000151
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600152LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000153
Matt Mower92084af2015-02-19 13:19:47 -0600154ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
155 ifeq ($(TW_USE_TOOLBOX), true)
156 LOCAL_SHARED_LIBRARIES += libcrypto
157 endif
158else
159 LOCAL_SHARED_LIBRARIES += \
160 libc \
161 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000162endif
163
Matt Mower92084af2015-02-19 13:19:47 -0600164ifeq ($(TWHAVE_SELINUX), true)
165 LOCAL_SHARED_LIBRARIES += libselinux
166endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600167
Matt Mower92084af2015-02-19 13:19:47 -0600168ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
169 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
170 # The linker strips out all the unused library code in the normal case.
171 LOCAL_STATIC_LIBRARIES := libusbhost
172 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
173endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600174
Dees Troy8d66f8b2013-10-08 14:04:55 +0000175LOCAL_MODULE := toolbox_recovery
176LOCAL_MODULE_STEM := toolbox
177LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600178LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000179
Matt Mower92084af2015-02-19 13:19:47 -0600180# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000181include $(BUILD_EXECUTABLE)
182
183$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
184
Matt Mower92084af2015-02-19 13:19:47 -0600185ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
186 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
187else
188 ALL_TOOLS := $(OUR_TOOLS)
189endif
190
191ifeq ($(TWHAVE_SELINUX), true)
192 # toolbox setenforce is used during init in non-symlink form, so it was
193 # required to be included as part of the suite above. if busybox already
194 # provides setenforce, we can omit the toolbox symlink
195 TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
196 ALL_TOOLS := $(TEMP_TOOLS)
197endif
198
Dees Troy8d66f8b2013-10-08 14:04:55 +0000199TOOLS_H := $(intermediates)/tools.h
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600200$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000201$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
202$(TOOLS_H): $(LOCAL_PATH)/Android.mk
203$(TOOLS_H):
204 $(transform-generated-source)
205
Matt Mower92084af2015-02-19 13:19:47 -0600206# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600207SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000208$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
209$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
210 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
211 @mkdir -p $(dir $@)
212 @rm -rf $@
213 $(hide) ln -sf $(TOOLBOX_BINARY) $@
214
Matt Mower031163b2014-11-01 15:13:03 -0500215include $(CLEAR_VARS)
216LOCAL_MODULE := toolbox_symlinks
217LOCAL_MODULE_TAGS := optional
218LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
219include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600220
Dees Troyb47f28b2014-12-11 17:20:59 +0000221ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600222 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
223 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
224 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
225 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000226endif
227
Ethan Yonker75bf0412014-11-21 13:54:27 -0600228SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600229ALL_TOOLS :=
230BSD_TOOLS :=
231OUR_TOOLS :=
232TEMP_TOOLS :=
233TOOLS_FOR_SELINUX :=