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 | |
erikcas | 1db013b | 2014-12-03 15:41:38 +0100 | [diff] [blame] | 4 | ifeq ($(PLATFORM_VERSION), 5.0.1) |
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 | |
| 110 | ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) |
| 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 | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 123 | LOCAL_CFLAGS += $(common_cflags) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 124 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 125 | LOCAL_C_INCLUDES += external/openssl/include |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 126 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 127 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 128 | |
| 129 | ifeq ($(TWHAVE_SELINUX), true) |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 130 | 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 Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 145 | endif |
| 146 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 147 | # 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. |
| 149 | LOCAL_STATIC_LIBRARIES := \ |
| 150 | libusbhost \ |
| 151 | |
| 152 | LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS)) |
| 153 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 154 | LOCAL_MODULE := toolbox_recovery |
| 155 | LOCAL_MODULE_STEM := toolbox |
| 156 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 157 | LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 158 | |
| 159 | # Including this will define $(intermediates). |
| 160 | # |
| 161 | include $(BUILD_EXECUTABLE) |
| 162 | |
| 163 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 164 | |
| 165 | TOOLS_H := $(intermediates)/tools.h |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 166 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 167 | $(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 Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 174 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 175 | $(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 Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 182 | include $(CLEAR_VARS) |
| 183 | LOCAL_MODULE := toolbox_symlinks |
| 184 | LOCAL_MODULE_TAGS := optional |
| 185 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 186 | include $(BUILD_PHONY_PACKAGE) |
| 187 | SYMLINKS := |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 188 | |
| 189 | # We need this so that the installed files could be picked up based on the |
| 190 | # local module name |
| 191 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 192 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 193 | |
| 194 | else |
| 195 | |
| 196 | # Rule for older trees |
| 197 | LOCAL_PATH:= system/core/toolbox/ |
| 198 | include $(CLEAR_VARS) |
| 199 | |
| 200 | TOOLS := \ |
| 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. |
| 208 | ifeq ($(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)) |
| 220 | endif |
| 221 | |
| 222 | ifeq ($(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 |
| 282 | endif |
| 283 | |
| 284 | LOCAL_SRC_FILES := \ |
| 285 | toolbox.c \ |
| 286 | $(patsubst %,%.c,$(TOOLS)) |
| 287 | |
| 288 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 289 | LOCAL_SRC_FILES += dynarray.c |
| 290 | endif |
| 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 | |
| 301 | LOCAL_C_INCLUDES := bionic/libc/bionic |
| 302 | |
| 303 | LOCAL_SHARED_LIBRARIES := \ |
| 304 | libcutils \ |
| 305 | liblog \ |
| 306 | libc |
| 307 | |
| 308 | ifeq ($(TWHAVE_SELINUX), true) |
| 309 | LOCAL_SHARED_LIBRARIES += libselinux |
| 310 | endif |
| 311 | |
| 312 | LOCAL_MODULE := toolbox_recovery |
| 313 | LOCAL_MODULE_STEM := toolbox |
| 314 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
| 315 | LOCAL_MODULE_TAGS := optional |
| 316 | |
| 317 | # Including this will define $(intermediates). |
| 318 | # |
| 319 | include $(BUILD_EXECUTABLE) |
| 320 | |
| 321 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 322 | |
| 323 | TOOLS_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 | # |
| 332 | SYMLINKS := $(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 | |
| 340 | include $(CLEAR_VARS) |
| 341 | LOCAL_MODULE := toolbox_symlinks |
| 342 | LOCAL_MODULE_TAGS := optional |
| 343 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 344 | include $(BUILD_PHONY_PACKAGE) |
| 345 | SYMLINKS := |
| 346 | |
| 347 | endif |