Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 1 | LOCAL_PATH:= system/core/toolbox/ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 2 | |
| 3 | |
Ethan Yonker | 738be7a | 2014-12-10 11:40:43 -0600 | [diff] [blame] | 4 | ifeq ($(PLATFORM_SDK_VERSION), 21) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 5 | |
| 6 | # Rule for lollipop |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 7 | common_cflags := \ |
| 8 | -std=gnu99 \ |
| 9 | -Werror -Wno-unused-parameter \ |
| 10 | -I$(LOCAL_PATH)/upstream-netbsd/include/ \ |
| 11 | -include bsd-compatibility.h |
| 12 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 13 | include $(CLEAR_VARS) |
| 14 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 15 | OUR_TOOLS := \ |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 16 | start \ |
| 17 | stop \ |
| 18 | getprop \ |
| 19 | setprop |
| 20 | |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 21 | # 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 Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 23 | ifeq ($(TWHAVE_SELINUX), true) |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 24 | TOOLS_FOR_SELINUX := \ |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 25 | ls \ |
| 26 | getenforce \ |
| 27 | setenforce \ |
| 28 | chcon \ |
| 29 | restorecon \ |
| 30 | runcon \ |
| 31 | getsebool \ |
| 32 | setsebool \ |
| 33 | load_policy |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 34 | OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 35 | endif |
| 36 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 37 | |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 38 | ifeq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 39 | BSD_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 | |
| 55 | OUR_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 Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 104 | endif |
| 105 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 106 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 107 | OUR_TOOLS += r |
| 108 | endif |
| 109 | |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 110 | ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) setenforce |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 111 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 112 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 113 | 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 Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 122 | |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 123 | ifeq (,$(filter $(LOCAL_SRC_FILES),setenforce.c)) |
| 124 | LOCAL_SRC_FILES += setenforce.c |
| 125 | endif |
| 126 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 127 | LOCAL_CFLAGS += $(common_cflags) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 128 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 129 | LOCAL_C_INCLUDES += external/openssl/include |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 130 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 131 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 132 | |
| 133 | ifeq ($(TWHAVE_SELINUX), true) |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 134 | 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 Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 149 | endif |
| 150 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 151 | # 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. |
| 153 | LOCAL_STATIC_LIBRARIES := \ |
| 154 | libusbhost \ |
| 155 | |
| 156 | LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS)) |
| 157 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 158 | LOCAL_MODULE := toolbox_recovery |
| 159 | LOCAL_MODULE_STEM := toolbox |
| 160 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 161 | LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 162 | |
| 163 | # Including this will define $(intermediates). |
| 164 | # |
| 165 | include $(BUILD_EXECUTABLE) |
| 166 | |
| 167 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 168 | |
| 169 | TOOLS_H := $(intermediates)/tools.h |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 170 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 171 | $(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 Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 178 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 179 | $(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 Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 186 | include $(CLEAR_VARS) |
| 187 | LOCAL_MODULE := toolbox_symlinks |
| 188 | LOCAL_MODULE_TAGS := optional |
| 189 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 190 | include $(BUILD_PHONY_PACKAGE) |
| 191 | SYMLINKS := |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 192 | |
| 193 | # We need this so that the installed files could be picked up based on the |
| 194 | # local module name |
| 195 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 196 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 197 | |
| 198 | else |
| 199 | |
| 200 | # Rule for older trees |
| 201 | LOCAL_PATH:= system/core/toolbox/ |
| 202 | include $(CLEAR_VARS) |
| 203 | |
| 204 | TOOLS := \ |
| 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. |
| 212 | ifeq ($(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)) |
| 224 | endif |
| 225 | |
| 226 | ifeq ($(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 |
| 286 | endif |
| 287 | |
| 288 | LOCAL_SRC_FILES := \ |
| 289 | toolbox.c \ |
| 290 | $(patsubst %,%.c,$(TOOLS)) |
| 291 | |
| 292 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 293 | LOCAL_SRC_FILES += dynarray.c |
| 294 | endif |
| 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 | |
| 305 | LOCAL_C_INCLUDES := bionic/libc/bionic |
| 306 | |
| 307 | LOCAL_SHARED_LIBRARIES := \ |
| 308 | libcutils \ |
| 309 | liblog \ |
| 310 | libc |
| 311 | |
| 312 | ifeq ($(TWHAVE_SELINUX), true) |
| 313 | LOCAL_SHARED_LIBRARIES += libselinux |
| 314 | endif |
| 315 | |
| 316 | LOCAL_MODULE := toolbox_recovery |
| 317 | LOCAL_MODULE_STEM := toolbox |
| 318 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
| 319 | LOCAL_MODULE_TAGS := optional |
| 320 | |
| 321 | # Including this will define $(intermediates). |
| 322 | # |
| 323 | include $(BUILD_EXECUTABLE) |
| 324 | |
| 325 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 326 | |
| 327 | TOOLS_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 | # |
| 336 | SYMLINKS := $(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 Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 344 | ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18)) |
| 345 | ALL_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 |
| 349 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 350 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |
| 351 | endif |
| 352 | |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 353 | include $(CLEAR_VARS) |
| 354 | LOCAL_MODULE := toolbox_symlinks |
| 355 | LOCAL_MODULE_TAGS := optional |
| 356 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 357 | include $(BUILD_PHONY_PACKAGE) |
| 358 | SYMLINKS := |
| 359 | |
| 360 | endif |