1LOCAL_PATH:= $(call my-dir)
2include $(CLEAR_VARS)
3
4TOOLS := \
5	ls \
6	mount \
7	cat \
8	ps \
9	kill \
10	ln \
11	insmod \
12	rmmod \
13	lsmod \
14	ifconfig \
15	setconsole \
16	rm \
17	mkdir \
18	rmdir \
19	getevent \
20	sendevent \
21	date \
22	wipe \
23	sync \
24	umount \
25	start \
26	stop \
27	notify \
28	cmp \
29	dmesg \
30	route \
31	hd \
32	dd \
33	df \
34	getprop \
35	setprop \
36	watchprops \
37	log \
38	sleep \
39	renice \
40	printenv \
41	smd \
42	chmod \
43	chown \
44	newfs_msdos \
45	netstat \
46	ioctl \
47	mv \
48	schedtop \
49	top \
50	iftop \
51	id \
52	uptime \
53	vmstat \
54	nandread \
55	ionice \
56	touch \
57	lsof \
58	du \
59	md5 \
60	clear \
61	getenforce \
62	setenforce \
63	chcon \
64	restorecon \
65	runcon \
66	getsebool \
67	setsebool \
68	load_policy \
69	swapon \
70	swapoff \
71	mkswap \
72	readlink
73
74ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
75TOOLS += r
76endif
77
78ALL_TOOLS = $(TOOLS)
79ALL_TOOLS += \
80	cp \
81	grep
82
83LOCAL_SRC_FILES := \
84	dynarray.c \
85	toolbox.c \
86	$(patsubst %,%.c,$(TOOLS)) \
87	cp/cp.c cp/utils.c \
88	grep/grep.c grep/fastgrep.c grep/file.c grep/queue.c grep/util.c
89
90LOCAL_C_INCLUDES := bionic/libc/bionic
91
92LOCAL_SHARED_LIBRARIES := \
93	libcutils \
94	liblog \
95	libc \
96	libusbhost \
97	libselinux
98
99LOCAL_MODULE := toolbox
100
101# Including this will define $(intermediates).
102#
103include $(BUILD_EXECUTABLE)
104
105$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
106
107TOOLS_H := $(intermediates)/tools.h
108$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
109$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
110$(TOOLS_H): $(LOCAL_PATH)/Android.mk
111$(TOOLS_H):
112	$(transform-generated-source)
113
114# Make #!/system/bin/toolbox launchers for each tool.
115#
116SYMLINKS := $(addprefix $(TARGET_OUT)/bin/,$(ALL_TOOLS))
117$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE)
118$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
119	@echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
120	@mkdir -p $(dir $@)
121	@rm -rf $@
122	$(hide) ln -sf $(TOOLBOX_BINARY) $@
123
124ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
125
126# We need this so that the installed files could be picked up based on the
127# local module name
128ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
129    $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
130