blob: ad2e24c5cc826f818fa4abc4d9f23f77d95ff40c [file] [log] [blame]
Dees Troy8d66f8b2013-10-08 14:04:55 +00001LOCAL_PATH:= system/core/toolbox/
Ethan Yonkerbcc502c2014-11-10 11:22:10 -06002
3
4common_cflags := \
5 -std=gnu99 \
6 -Werror -Wno-unused-parameter \
7 -I$(LOCAL_PATH)/upstream-netbsd/include/ \
8 -include bsd-compatibility.h
9
Dees Troy8d66f8b2013-10-08 14:04:55 +000010include $(CLEAR_VARS)
11
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060012OUR_TOOLS := \
Dees Troy8d66f8b2013-10-08 14:04:55 +000013 start \
14 stop \
15 getprop \
16 setprop
17
Matt Mower81742fb2014-09-01 14:40:52 -050018# 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 Troy8d66f8b2013-10-08 14:04:55 +000020ifeq ($(TWHAVE_SELINUX), true)
Matt Mower81742fb2014-09-01 14:40:52 -050021 TOOLS_FOR_SELINUX := \
Dees Troy8d66f8b2013-10-08 14:04:55 +000022 ls \
23 getenforce \
24 setenforce \
25 chcon \
26 restorecon \
27 runcon \
28 getsebool \
29 setsebool \
30 load_policy
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060031 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000032endif
33
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060034
Ethan Yonker5c933692014-04-04 11:26:32 -050035ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060036BSD_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
52OUR_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 Yonker5c933692014-04-04 11:26:32 -0500101endif
102
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600103ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
104OUR_TOOLS += r
105endif
106
107ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)
108
Dees Troy8d66f8b2013-10-08 14:04:55 +0000109LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600110 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 Troy8d66f8b2013-10-08 14:04:55 +0000119
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600120LOCAL_CFLAGS += $(common_cflags)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000121
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600122LOCAL_C_INCLUDES += external/openssl/include
Dees Troybb4c0cb2013-11-02 20:25:14 +0000123
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600124LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000125
126ifeq ($(TWHAVE_SELINUX), true)
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600127 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 Troy8d66f8b2013-10-08 14:04:55 +0000142endif
143
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600144# 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.
146LOCAL_STATIC_LIBRARIES := \
147 libusbhost \
148
149LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
150
Dees Troy8d66f8b2013-10-08 14:04:55 +0000151LOCAL_MODULE := toolbox_recovery
152LOCAL_MODULE_STEM := toolbox
153LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600154LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
Dees Troy8d66f8b2013-10-08 14:04:55 +0000155
156# Including this will define $(intermediates).
157#
158include $(BUILD_EXECUTABLE)
159
160$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
161
162TOOLS_H := $(intermediates)/tools.h
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600163$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000164$(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 Yonkerbcc502c2014-11-10 11:22:10 -0600171SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000172$(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 Mower031163b2014-11-01 15:13:03 -0500179include $(CLEAR_VARS)
180LOCAL_MODULE := toolbox_symlinks
181LOCAL_MODULE_TAGS := optional
182LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
183include $(BUILD_PHONY_PACKAGE)
184SYMLINKS :=
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600185
186# We need this so that the installed files could be picked up based on the
187# local module name
188ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
189 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)