blob: c4f0395f77018c6aaac44141f58cbe852dd730e0 [file] [log] [blame]
Ethan Yonkerc798c9c2015-10-09 11:15:26 -05001#
2# Copyright (C) 2014 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17ifneq ($(wildcard external/toybox/Android.mk),)
18
19ifeq ($(TW_USE_TOOLBOX), true)
20
21LOCAL_PATH := external/toybox
22
23#
24# To update:
25#
26
27# git remote add toybox https://github.com/landley/toybox.git
28# git fetch toybox
29# git merge toybox/master
30# mm -j32
31# # (Make any necessary Android.mk changes and test the new toybox.)
32# git push aosp HEAD:master # Push directly, avoiding gerrit.
33# git push aosp HEAD:refs/for/master # Push to gerrit.
34#
35# # Now commit any necessary Android.mk changes like normal:
36# repo start post-sync .
37# git commit -a
38
39
40#
41# To add a toy:
42#
43
44# make menuconfig
45# # (Select the toy you want to add.)
46# make clean && make # Regenerate the generated files.
47# # Edit LOCAL_SRC_FILES below to add the toy.
48# # If you just want to use it as "toybox x" rather than "x", you can stop now.
49# # If you want this toy to have a symbolic link in /system/bin, add the toy to ALL_TOOLS.
50
51include $(CLEAR_VARS)
52
53LOCAL_SRC_FILES := \
54 lib/args.c \
55 lib/dirtree.c \
56 lib/getmountlist.c \
57 lib/help.c \
58 lib/interestingtimes.c \
59 lib/lib.c \
60 lib/llist.c \
61 lib/net.c \
62 lib/portability.c \
63 lib/xwrap.c \
64 main.c \
65 toys/android/getenforce.c \
66 toys/android/getprop.c \
67 toys/android/load_policy.c \
68 toys/android/restorecon.c \
69 toys/android/runcon.c \
70 toys/android/setenforce.c \
71 toys/android/setprop.c \
72 toys/lsb/dmesg.c \
73 toys/lsb/hostname.c \
74 toys/lsb/killall.c \
75 toys/lsb/md5sum.c \
76 toys/lsb/mknod.c \
77 toys/lsb/mktemp.c \
78 toys/lsb/mount.c \
79 toys/lsb/pidof.c \
80 toys/lsb/seq.c \
81 toys/lsb/sync.c \
82 toys/lsb/umount.c \
83 toys/other/acpi.c \
84 toys/other/base64.c \
85 toys/other/blkid.c \
86 toys/other/blockdev.c \
87 toys/other/bzcat.c \
88 toys/other/chcon.c \
89 toys/other/chroot.c \
90 toys/other/clear.c \
91 toys/other/dos2unix.c \
92 toys/other/fallocate.c \
93 toys/other/free.c \
94 toys/other/freeramdisk.c \
95 toys/other/fsfreeze.c \
96 toys/other/help.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050097 toys/other/inotifyd.c \
98 toys/other/insmod.c \
99 toys/other/losetup.c \
100 toys/other/lsattr.c \
101 toys/other/lsmod.c \
102 toys/other/lsusb.c \
103 toys/other/makedevs.c \
104 toys/other/mkswap.c \
105 toys/other/modinfo.c \
106 toys/other/mountpoint.c \
107 toys/other/nbd_client.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500108 toys/other/partprobe.c \
109 toys/other/pivot_root.c \
110 toys/other/pmap.c \
111 toys/other/printenv.c \
112 toys/other/pwdx.c \
113 toys/other/readlink.c \
114 toys/other/realpath.c \
115 toys/other/rev.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500116 toys/other/rmmod.c \
117 toys/other/setsid.c \
118 toys/other/stat.c \
119 toys/other/swapoff.c \
120 toys/other/swapon.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500121 toys/other/sysctl.c \
122 toys/other/tac.c \
123 toys/other/taskset.c \
124 toys/other/timeout.c \
125 toys/other/truncate.c \
126 toys/other/usleep.c \
127 toys/other/vconfig.c \
128 toys/other/vmstat.c \
129 toys/other/which.c \
130 toys/other/yes.c \
131 toys/pending/dd.c \
132 toys/pending/expr.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500133 toys/pending/more.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500134 toys/pending/route.c \
135 toys/pending/tar.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500136 toys/pending/tr.c \
137 toys/pending/traceroute.c \
138 toys/posix/basename.c \
139 toys/posix/cal.c \
140 toys/posix/cat.c \
141 toys/posix/chgrp.c \
142 toys/posix/chmod.c \
143 toys/posix/cksum.c \
144 toys/posix/cmp.c \
145 toys/posix/comm.c \
146 toys/posix/cp.c \
147 toys/posix/cpio.c \
148 toys/posix/cut.c \
149 toys/posix/date.c \
150 toys/posix/df.c \
151 toys/posix/dirname.c \
152 toys/posix/du.c \
153 toys/posix/echo.c \
154 toys/posix/env.c \
155 toys/posix/expand.c \
156 toys/posix/false.c \
157 toys/posix/find.c \
158 toys/posix/grep.c \
159 toys/posix/head.c \
160 toys/posix/id.c \
161 toys/posix/kill.c \
162 toys/posix/ln.c \
163 toys/posix/ls.c \
164 toys/posix/mkdir.c \
165 toys/posix/mkfifo.c \
166 toys/posix/nice.c \
167 toys/posix/nl.c \
168 toys/posix/nohup.c \
169 toys/posix/od.c \
170 toys/posix/paste.c \
171 toys/posix/patch.c \
172 toys/posix/printf.c \
173 toys/posix/pwd.c \
174 toys/posix/renice.c \
175 toys/posix/rm.c \
176 toys/posix/rmdir.c \
177 toys/posix/sed.c \
178 toys/posix/sleep.c \
179 toys/posix/sort.c \
180 toys/posix/split.c \
181 toys/posix/strings.c \
182 toys/posix/tail.c \
183 toys/posix/tee.c \
184 toys/posix/time.c \
185 toys/posix/touch.c \
186 toys/posix/true.c \
187 toys/posix/tty.c \
188 toys/posix/uname.c \
189 toys/posix/uniq.c \
190 toys/posix/wc.c \
Hashcode57332152016-12-20 01:30:49 +0100191 toys/posix/xargs.c
192
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500193ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
194# there are some conflicts here with AOSP-7.[01] and CM-14.[01]
Hashcode57332152016-12-20 01:30:49 +0100195# the following items have been removed for compatibility
196# ifconfig, netcat, netstat, rfkill, switch_root
197LOCAL_STATIC_LIBRARIES := libcrypto_static
198
199LOCAL_C_INCLUDES += \
200 external/boringssl/include \
201 bionic/libc/dns/include
202
203LOCAL_SRC_FILES += \
204 lib/linestack.c \
205 lib/password.c \
206 toys/other/flock.c \
207 toys/other/hwclock.c \
208 toys/other/ionice.c \
209 toys/other/lspci.c \
210 toys/other/readahead.c \
211 toys/other/reset.c \
212 toys/other/uptime.c \
213 toys/other/xxd.c \
214 toys/pending/arp.c \
215 toys/pending/diff.c \
216 toys/pending/ftpget.c \
217 toys/pending/lsof.c \
218 toys/pending/telnet.c \
219 toys/pending/test.c \
220 toys/pending/watch.c \
221 toys/pending/xzcat.c \
222 toys/posix/ps.c \
223 toys/posix/ulimit.c
224
225# Account for master branch changes pulld into CM14.1
226ifneq ($(CM_BUILD),)
227LOCAL_SRC_FILES += \
228 toys/android/log.c \
229 toys/android/sendevent.c \
230 toys/android/start.c \
231 toys/net/ifconfig.c \
232 toys/net/netcat.c \
233 toys/net/netstat.c \
234 toys/net/rfkill.c \
235 toys/net/tunctl.c \
236 toys/other/setfattr.c \
237 toys/pending/chrt.c \
238 toys/pending/fdisk.c \
239 toys/pending/getfattr.c \
240 toys/pending/host.c \
241 toys/pending/resize.c \
242 toys/posix/file.c
243else
244LOCAL_SRC_FILES += \
245 toys/other/ifconfig.c \
246 toys/other/netcat.c \
247 toys/other/rfkill.c \
248 toys/other/switch_root.c \
249 toys/pending/netstat.c
250endif
251else
252LOCAL_SRC_FILES += \
253 toys/other/ifconfig.c \
254 toys/other/netcat.c \
255 toys/other/rfkill.c \
256 toys/other/switch_root.c \
257 toys/pending/hwclock.c \
258 toys/pending/netstat.c \
259 toys/pending/pgrep.c \
260 toys/pending/top.c
261endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500262
263LOCAL_CFLAGS += \
264 -std=c99 \
265 -Os \
266 -Wno-char-subscripts \
267 -Wno-sign-compare \
268 -Wno-string-plus-int \
269 -Wno-uninitialized \
270 -Wno-unused-parameter \
271 -funsigned-char \
272 -ffunction-sections -fdata-sections \
273 -fno-asynchronous-unwind-tables \
274
275toybox_version := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null)-android
276LOCAL_CFLAGS += -DTOYBOX_VERSION='"$(toybox_version)"'
277
278LOCAL_CLANG := true
279
280LOCAL_SHARED_LIBRARIES := libcutils libselinux
281
282LOCAL_MODULE := toybox_recovery
283LOCAL_MODULE_STEM := toybox
284LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
285LOCAL_MODULE_TAGS := optional
286
287# dupes: dd df du ls mount renice
288# useless?: freeramdisk fsfreeze install makedevs mkfifo nbd-client
289# partprobe pivot_root pwdx rev rfkill switch_root tty vconfig
290# prefer BSD netcat instead?: nc netcat
291# prefer efs2progs instead?: blkid chattr lsattr
292
293ALL_TOOLS := \
294 acpi \
295 basename \
296 blkid \
297 blockdev \
298 bzcat \
299 cal \
300 cat \
301 chcon \
302 chgrp \
303 chmod \
304 chown \
305 chroot \
306 cksum \
307 clear \
308 comm \
309 cmp \
310 cp \
311 cpio \
312 cut \
313 date \
314 dirname \
315 dmesg \
316 dos2unix \
317 echo \
318 env \
319 expand \
320 expr \
321 fallocate \
322 false \
323 find \
324 free \
325 getenforce \
326 getprop \
327 groups \
328 head \
329 hostname \
330 hwclock \
331 id \
332 ifconfig \
333 inotifyd \
334 insmod \
335 kill \
336 load_policy \
337 ln \
338 logname \
339 losetup \
340 lsmod \
341 lsusb \
342 md5sum \
343 mkdir \
344 mknod \
345 mkswap \
346 mktemp \
347 modinfo \
348 more \
349 mountpoint \
350 mv \
351 netstat \
352 nice \
353 nl \
354 nohup \
355 od \
356 paste \
357 patch \
358 pgrep \
359 pidof \
360 pkill \
361 pmap \
362 printenv \
363 printf \
364 pwd \
365 readlink \
366 realpath \
367 restorecon \
368 rm \
369 rmdir \
370 rmmod \
371 route \
372 runcon \
373 sed \
374 seq \
375 setenforce \
376 setprop \
377 setsid \
378 sha1sum \
379 sleep \
380 sort \
381 split \
382 stat \
383 strings \
384 swapoff \
385 swapon \
386 sync \
387 sysctl \
388 tac \
389 tail \
390 tar \
391 taskset \
392 tee \
393 time \
394 timeout \
395 touch \
396 tr \
397 true \
398 truncate \
399 umount \
400 uname \
401 uniq \
402 unix2dos \
403 usleep \
404 vmstat \
405 wc \
406 which \
407 whoami \
408 xargs \
Hashcode57332152016-12-20 01:30:49 +0100409 yes
410
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500411ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Hashcode57332152016-12-20 01:30:49 +0100412ALL_TOOLS += \
413 arp \
414 base64 \
415 chattr \
416 dd \
417 df \
418 diff \
Hashcode57332152016-12-20 01:30:49 +0100419 egrep \
420 fgrep \
421 flock \
422 freeramdisk \
423 fsfreeze \
424 fstype \
425 ftpget \
426 ftpput \
427 grep \
428 help \
429 install \
430 ionice \
431 iorenice \
432 iotop \
433 killall \
434 ls \
435 lsattr \
436 lsof \
437 lspci \
438 makedevs \
439 mkfifo \
440 mount \
441 nbd-client \
442 nc \
443 netcat \
444 nproc \
445 partprobe \
446 pivot_root \
447 ps \
448 pwdx \
449 readahead \
450 renice \
451 reset \
452 rev \
453 rfkill \
454 sha224sum \
455 sha256sum \
456 sha384sum \
457 sha512sum \
458 telnet \
459 test \
460 top \
461 traceroute \
462 traceroute6 \
463 tty \
464 tunctl \
465 ulimit \
466 uptime \
467 vconfig \
468 watch \
469 xxd \
470 xzcat
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500471ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 24; echo $$?),0)
472ALL_TOOLS += \
473 du
474endif
Hashcode57332152016-12-20 01:30:49 +0100475# Account for master branch changes pulld into CM14.1
476ifneq ($(CM_BUILD),)
477ALL_TOOLS += \
478 chrt \
479 fdisk \
480 file \
481 getfattr \
482 host \
483 log \
484 resize \
485 setfattr
486endif
487endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500488
489# Install the symlinks.
490LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
491
492include $(BUILD_EXECUTABLE)
493
494# Make /sbin/toolbox launchers for each tool
495SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
496$(SYMLINKS): TOYBOX_BINARY := $(LOCAL_MODULE_STEM)
497$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
498 @echo "Symlink: $@ -> $(TOYBOX_BINARY)"
499 @mkdir -p $(dir $@)
500 @rm -rf $@
501 $(hide) ln -sf $(TOYBOX_BINARY) $@
502
503include $(CLEAR_VARS)
504LOCAL_MODULE := toybox_symlinks
505LOCAL_MODULE_TAGS := optional
506LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
507include $(BUILD_PHONY_PACKAGE)
508
509endif
510
511endif