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 | |
| 4 | common_cflags := \ |
| 5 | -std=gnu99 \ |
| 6 | -Werror -Wno-unused-parameter \ |
| 7 | -I$(LOCAL_PATH)/upstream-netbsd/include/ \ |
| 8 | -include bsd-compatibility.h |
| 9 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 10 | include $(CLEAR_VARS) |
| 11 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 12 | OUR_TOOLS := \ |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 13 | start \ |
| 14 | stop \ |
| 15 | getprop \ |
| 16 | setprop |
| 17 | |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 18 | # If busybox does not have SELinux support, provide these tools with toolbox. |
| 19 | # 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] | 20 | ifeq ($(TWHAVE_SELINUX), true) |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 21 | TOOLS_FOR_SELINUX := \ |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 22 | ls \ |
| 23 | getenforce \ |
| 24 | setenforce \ |
| 25 | chcon \ |
| 26 | restorecon \ |
| 27 | runcon \ |
| 28 | getsebool \ |
| 29 | setsebool \ |
| 30 | load_policy |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 31 | OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 32 | endif |
| 33 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 34 | |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 35 | ifeq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 36 | BSD_TOOLS := \ |
| 37 | cat \ |
| 38 | chown \ |
| 39 | cp \ |
| 40 | dd \ |
| 41 | du \ |
| 42 | grep \ |
| 43 | kill \ |
| 44 | ln \ |
| 45 | mv \ |
| 46 | printenv \ |
| 47 | rm \ |
| 48 | rmdir \ |
| 49 | sleep \ |
| 50 | sync \ |
| 51 | |
| 52 | OUR_TOOLS += \ |
| 53 | chmod \ |
| 54 | clear \ |
| 55 | cmp \ |
| 56 | date \ |
| 57 | df \ |
| 58 | dmesg \ |
| 59 | getevent \ |
| 60 | hd \ |
| 61 | id \ |
| 62 | ifconfig \ |
| 63 | iftop \ |
| 64 | insmod \ |
| 65 | ioctl \ |
| 66 | ionice \ |
| 67 | log \ |
| 68 | lsmod \ |
| 69 | lsof \ |
| 70 | md5 \ |
| 71 | mkdir \ |
| 72 | mknod \ |
| 73 | mkswap \ |
| 74 | mount \ |
| 75 | nandread \ |
| 76 | netstat \ |
| 77 | newfs_msdos \ |
| 78 | nohup \ |
| 79 | notify \ |
| 80 | ps \ |
| 81 | readlink \ |
| 82 | renice \ |
| 83 | rmmod \ |
| 84 | route \ |
| 85 | schedtop \ |
| 86 | sendevent \ |
| 87 | smd \ |
| 88 | swapoff \ |
| 89 | swapon \ |
| 90 | top \ |
| 91 | touch \ |
| 92 | umount \ |
| 93 | uptime \ |
| 94 | vmstat \ |
| 95 | watchprops \ |
| 96 | wipe |
| 97 | ifneq ($(TWHAVE_SELINUX), true) |
| 98 | TOOLS += ls |
| 99 | endif |
| 100 | LOCAL_SHARED_LIBRARIES += libcrypto |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 101 | endif |
| 102 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 103 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 104 | OUR_TOOLS += r |
| 105 | endif |
| 106 | |
| 107 | ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) |
| 108 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 109 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 110 | upstream-netbsd/lib/libc/gen/getbsize.c \ |
| 111 | upstream-netbsd/lib/libc/gen/humanize_number.c \ |
| 112 | upstream-netbsd/lib/libc/stdlib/strsuftoll.c \ |
| 113 | upstream-netbsd/lib/libc/string/swab.c \ |
| 114 | upstream-netbsd/lib/libutil/raise_default_signal.c \ |
| 115 | dynarray.c \ |
| 116 | pwcache.c \ |
| 117 | $(patsubst %,%.c,$(OUR_TOOLS)) \ |
| 118 | toolbox.c \ |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 119 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 120 | LOCAL_CFLAGS += $(common_cflags) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 121 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 122 | LOCAL_C_INCLUDES += external/openssl/include |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 123 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 124 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 125 | |
| 126 | ifeq ($(TWHAVE_SELINUX), true) |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 127 | LOCAL_SHARED_LIBRARIES += libselinux |
| 128 | LOCAL_STATIC_LIBRARIES += \ |
| 129 | libtoolbox_cat \ |
| 130 | libtoolbox_chown \ |
| 131 | libtoolbox_cp \ |
| 132 | libtoolbox_dd \ |
| 133 | libtoolbox_grep \ |
| 134 | libtoolbox_kill \ |
| 135 | libtoolbox_ln \ |
| 136 | libtoolbox_mv \ |
| 137 | libtoolbox_printenv \ |
| 138 | libtoolbox_rm \ |
| 139 | libtoolbox_rmdir \ |
| 140 | libtoolbox_sleep \ |
| 141 | libtoolbox_sync |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 142 | endif |
| 143 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 144 | # libusbhost is only used by lsusb, and that isn't usually included in toolbox. |
| 145 | # The linker strips out all the unused library code in the normal case. |
| 146 | LOCAL_STATIC_LIBRARIES := \ |
| 147 | libusbhost \ |
| 148 | |
| 149 | LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS)) |
| 150 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 151 | LOCAL_MODULE := toolbox_recovery |
| 152 | LOCAL_MODULE_STEM := toolbox |
| 153 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 154 | LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 155 | |
| 156 | # Including this will define $(intermediates). |
| 157 | # |
| 158 | include $(BUILD_EXECUTABLE) |
| 159 | |
| 160 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 161 | |
| 162 | TOOLS_H := $(intermediates)/tools.h |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 163 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 164 | $(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done |
| 165 | $(TOOLS_H): $(LOCAL_PATH)/Android.mk |
| 166 | $(TOOLS_H): |
| 167 | $(transform-generated-source) |
| 168 | |
| 169 | # Make #!/system/bin/toolbox launchers for each tool. |
| 170 | # |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 171 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 172 | $(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM) |
| 173 | $(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk |
| 174 | @echo "Symlink: $@ -> $(TOOLBOX_BINARY)" |
| 175 | @mkdir -p $(dir $@) |
| 176 | @rm -rf $@ |
| 177 | $(hide) ln -sf $(TOOLBOX_BINARY) $@ |
| 178 | |
Matt Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 179 | include $(CLEAR_VARS) |
| 180 | LOCAL_MODULE := toolbox_symlinks |
| 181 | LOCAL_MODULE_TAGS := optional |
| 182 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 183 | include $(BUILD_PHONY_PACKAGE) |
| 184 | SYMLINKS := |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 185 | |
| 186 | # We need this so that the installed files could be picked up based on the |
| 187 | # local module name |
| 188 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 189 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |