blob: 5b2f32fd718a60628483095f4fa01fdfae435e76 [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 \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050072 toys/lsb/hostname.c \
73 toys/lsb/killall.c \
74 toys/lsb/md5sum.c \
75 toys/lsb/mknod.c \
76 toys/lsb/mktemp.c \
77 toys/lsb/mount.c \
78 toys/lsb/pidof.c \
79 toys/lsb/seq.c \
80 toys/lsb/sync.c \
81 toys/lsb/umount.c \
82 toys/other/acpi.c \
83 toys/other/base64.c \
84 toys/other/blkid.c \
85 toys/other/blockdev.c \
86 toys/other/bzcat.c \
87 toys/other/chcon.c \
88 toys/other/chroot.c \
89 toys/other/clear.c \
90 toys/other/dos2unix.c \
91 toys/other/fallocate.c \
92 toys/other/free.c \
93 toys/other/freeramdisk.c \
94 toys/other/fsfreeze.c \
95 toys/other/help.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050096 toys/other/inotifyd.c \
97 toys/other/insmod.c \
98 toys/other/losetup.c \
99 toys/other/lsattr.c \
100 toys/other/lsmod.c \
101 toys/other/lsusb.c \
102 toys/other/makedevs.c \
103 toys/other/mkswap.c \
104 toys/other/modinfo.c \
105 toys/other/mountpoint.c \
106 toys/other/nbd_client.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500107 toys/other/partprobe.c \
108 toys/other/pivot_root.c \
109 toys/other/pmap.c \
110 toys/other/printenv.c \
111 toys/other/pwdx.c \
112 toys/other/readlink.c \
113 toys/other/realpath.c \
114 toys/other/rev.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500115 toys/other/rmmod.c \
116 toys/other/setsid.c \
117 toys/other/stat.c \
118 toys/other/swapoff.c \
119 toys/other/swapon.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500120 toys/other/sysctl.c \
121 toys/other/tac.c \
122 toys/other/taskset.c \
123 toys/other/timeout.c \
124 toys/other/truncate.c \
125 toys/other/usleep.c \
126 toys/other/vconfig.c \
127 toys/other/vmstat.c \
128 toys/other/which.c \
129 toys/other/yes.c \
130 toys/pending/dd.c \
131 toys/pending/expr.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500132 toys/pending/more.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500133 toys/pending/route.c \
134 toys/pending/tar.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500135 toys/pending/tr.c \
136 toys/pending/traceroute.c \
137 toys/posix/basename.c \
138 toys/posix/cal.c \
139 toys/posix/cat.c \
140 toys/posix/chgrp.c \
141 toys/posix/chmod.c \
142 toys/posix/cksum.c \
143 toys/posix/cmp.c \
144 toys/posix/comm.c \
145 toys/posix/cp.c \
146 toys/posix/cpio.c \
147 toys/posix/cut.c \
148 toys/posix/date.c \
149 toys/posix/df.c \
150 toys/posix/dirname.c \
151 toys/posix/du.c \
152 toys/posix/echo.c \
153 toys/posix/env.c \
154 toys/posix/expand.c \
155 toys/posix/false.c \
156 toys/posix/find.c \
157 toys/posix/grep.c \
158 toys/posix/head.c \
159 toys/posix/id.c \
160 toys/posix/kill.c \
161 toys/posix/ln.c \
162 toys/posix/ls.c \
163 toys/posix/mkdir.c \
164 toys/posix/mkfifo.c \
165 toys/posix/nice.c \
166 toys/posix/nl.c \
167 toys/posix/nohup.c \
168 toys/posix/od.c \
169 toys/posix/paste.c \
170 toys/posix/patch.c \
171 toys/posix/printf.c \
172 toys/posix/pwd.c \
173 toys/posix/renice.c \
174 toys/posix/rm.c \
175 toys/posix/rmdir.c \
176 toys/posix/sed.c \
177 toys/posix/sleep.c \
178 toys/posix/sort.c \
179 toys/posix/split.c \
180 toys/posix/strings.c \
181 toys/posix/tail.c \
182 toys/posix/tee.c \
183 toys/posix/time.c \
184 toys/posix/touch.c \
185 toys/posix/true.c \
186 toys/posix/tty.c \
187 toys/posix/uname.c \
188 toys/posix/uniq.c \
189 toys/posix/wc.c \
Hashcode57332152016-12-20 01:30:49 +0100190 toys/posix/xargs.c
191
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500192ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
193# there are some conflicts here with AOSP-7.[01] and CM-14.[01]
Hashcode57332152016-12-20 01:30:49 +0100194# the following items have been removed for compatibility
195# ifconfig, netcat, netstat, rfkill, switch_root
196LOCAL_STATIC_LIBRARIES := libcrypto_static
197
198LOCAL_C_INCLUDES += \
199 external/boringssl/include \
200 bionic/libc/dns/include
201
202LOCAL_SRC_FILES += \
203 lib/linestack.c \
204 lib/password.c \
205 toys/other/flock.c \
206 toys/other/hwclock.c \
207 toys/other/ionice.c \
208 toys/other/lspci.c \
209 toys/other/readahead.c \
210 toys/other/reset.c \
211 toys/other/uptime.c \
212 toys/other/xxd.c \
213 toys/pending/arp.c \
214 toys/pending/diff.c \
Hashcode57332152016-12-20 01:30:49 +0100215 toys/pending/lsof.c \
216 toys/pending/telnet.c \
217 toys/pending/test.c \
218 toys/pending/watch.c \
Hashcode57332152016-12-20 01:30:49 +0100219 toys/posix/ps.c \
220 toys/posix/ulimit.c
Humberto Borba84e16152018-01-05 00:51:40 -0200221ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 27; echo $$?),0)
222LOCAL_SRC_FILES += \
223 toys/pending/xzcat.c
224endif
225ifeq ($(shell test $(PLATFORM_SDK_VERSION) -eq 26; echo $$?),0)
Ethan Yonker95e80072017-08-24 21:45:50 -0500226# Android 8.0 had some tools in different paths
227LOCAL_SRC_FILES += \
Humberto Borba84e16152018-01-05 00:51:40 -0200228 toys/pending/dmesg.c
229else
230LOCAL_SRC_FILES += \
231 toys/lsb/dmesg.c
232endif
233
234ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
235# Android 8.0/8.1 had some tools in different paths
236LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500237 toys/net/ftpget.c
238else
239LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500240 toys/pending/ftpget.c
241endif
242
Hashcode57332152016-12-20 01:30:49 +0100243# Account for master branch changes pulld into CM14.1
244ifneq ($(CM_BUILD),)
245LOCAL_SRC_FILES += \
246 toys/android/log.c \
247 toys/android/sendevent.c \
248 toys/android/start.c \
249 toys/net/ifconfig.c \
250 toys/net/netcat.c \
251 toys/net/netstat.c \
252 toys/net/rfkill.c \
253 toys/net/tunctl.c \
254 toys/other/setfattr.c \
255 toys/pending/chrt.c \
256 toys/pending/fdisk.c \
257 toys/pending/getfattr.c \
258 toys/pending/host.c \
259 toys/pending/resize.c \
260 toys/posix/file.c
261else
262LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500263 toys/other/switch_root.c
264ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
265# Android 8.0 had some tools in different paths
266LOCAL_SRC_FILES += \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500267 toys/android/log.c \
268 toys/android/sendevent.c \
269 toys/android/start.c \
Ethan Yonker95e80072017-08-24 21:45:50 -0500270 toys/net/ifconfig.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500271 toys/net/microcom.c \
Ethan Yonker95e80072017-08-24 21:45:50 -0500272 toys/net/netcat.c \
273 toys/net/netstat.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500274 toys/net/rfkill.c \
275 toys/net/tunctl.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500276 toys/pending/getfattr.c \
277 toys/pending/modprobe.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500278 toys/posix/file.c \
279 toys/posix/uudecode.c \
280 toys/posix/uuencode.c
Humberto Borba84e16152018-01-05 00:51:40 -0200281ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 26; echo $$?),0)
282# Android 8.1 had some tools in different paths
283LOCAL_SRC_FILES += \
284 toys/other/chrt.c \
285 toys/pending/gzip.c
286else
287LOCAL_SRC_FILES += \
288 toys/pending/chrt.c
289endif
Ethan Yonker58f21322018-08-24 11:17:36 -0500290ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
291# Android 9.0
292LOCAL_SRC_FILES += \
293 toys/other/setfattr.c \
294 toys/pending/fmt.c \
295 toys/pending/stty.c
296else
297LOCAL_SRC_FILES += \
298 toys/pending/setfattr.c
299endif
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500300LOCAL_SHARED_LIBRARIES += liblog
Ethan Yonker95e80072017-08-24 21:45:50 -0500301else
302LOCAL_SRC_FILES += \
Hashcode57332152016-12-20 01:30:49 +0100303 toys/other/ifconfig.c \
304 toys/other/netcat.c \
305 toys/other/rfkill.c \
Hashcode57332152016-12-20 01:30:49 +0100306 toys/pending/netstat.c
307endif
Ethan Yonker95e80072017-08-24 21:45:50 -0500308endif
Hashcode57332152016-12-20 01:30:49 +0100309else
310LOCAL_SRC_FILES += \
311 toys/other/ifconfig.c \
312 toys/other/netcat.c \
313 toys/other/rfkill.c \
314 toys/other/switch_root.c \
315 toys/pending/hwclock.c \
316 toys/pending/netstat.c \
317 toys/pending/pgrep.c \
318 toys/pending/top.c
319endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500320
321LOCAL_CFLAGS += \
Ethan Yonker58f21322018-08-24 11:17:36 -0500322 -std=gnu11 \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500323 -Os \
324 -Wno-char-subscripts \
325 -Wno-sign-compare \
326 -Wno-string-plus-int \
327 -Wno-uninitialized \
328 -Wno-unused-parameter \
329 -funsigned-char \
330 -ffunction-sections -fdata-sections \
331 -fno-asynchronous-unwind-tables \
332
Humberto Borba84e16152018-01-05 00:51:40 -0200333toybox_version := $(shell sed 's/#define.*TOYBOX_VERSION.*"\(.*\)"/\1/p;d' $(LOCAL_PATH)/main.c)
334LOCAL_CFLAGS += -DTOYBOX_VERSION=\"$(toybox_version)\"
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500335
336LOCAL_CLANG := true
337
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500338LOCAL_SHARED_LIBRARIES += libcutils libselinux
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500339
Humberto Borba84e16152018-01-05 00:51:40 -0200340ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 26; echo $$?),0)
341LOCAL_CFLAGS += \
342 -Wno-gnu-variable-sized-type-not-at-end \
343 -Wno-missing-field-initializers
344
345LOCAL_SHARED_LIBRARIES += libz
346endif
347
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500348LOCAL_MODULE := toybox_recovery
349LOCAL_MODULE_STEM := toybox
350LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
351LOCAL_MODULE_TAGS := optional
352
353# dupes: dd df du ls mount renice
354# useless?: freeramdisk fsfreeze install makedevs mkfifo nbd-client
355# partprobe pivot_root pwdx rev rfkill switch_root tty vconfig
356# prefer BSD netcat instead?: nc netcat
357# prefer efs2progs instead?: blkid chattr lsattr
358
359ALL_TOOLS := \
360 acpi \
361 basename \
362 blkid \
363 blockdev \
364 bzcat \
365 cal \
366 cat \
367 chcon \
368 chgrp \
369 chmod \
370 chown \
371 chroot \
372 cksum \
373 clear \
374 comm \
375 cmp \
376 cp \
377 cpio \
378 cut \
379 date \
380 dirname \
381 dmesg \
382 dos2unix \
383 echo \
384 env \
385 expand \
386 expr \
387 fallocate \
388 false \
389 find \
390 free \
391 getenforce \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500392 groups \
393 head \
394 hostname \
395 hwclock \
396 id \
397 ifconfig \
398 inotifyd \
399 insmod \
400 kill \
401 load_policy \
402 ln \
403 logname \
404 losetup \
405 lsmod \
406 lsusb \
407 md5sum \
408 mkdir \
409 mknod \
410 mkswap \
411 mktemp \
412 modinfo \
413 more \
414 mountpoint \
415 mv \
416 netstat \
417 nice \
418 nl \
419 nohup \
420 od \
421 paste \
422 patch \
423 pgrep \
424 pidof \
425 pkill \
426 pmap \
427 printenv \
428 printf \
429 pwd \
430 readlink \
431 realpath \
432 restorecon \
433 rm \
434 rmdir \
435 rmmod \
436 route \
437 runcon \
438 sed \
439 seq \
440 setenforce \
441 setprop \
442 setsid \
443 sha1sum \
444 sleep \
445 sort \
446 split \
447 stat \
448 strings \
449 swapoff \
450 swapon \
451 sync \
452 sysctl \
453 tac \
454 tail \
455 tar \
456 taskset \
457 tee \
458 time \
459 timeout \
460 touch \
461 tr \
462 true \
463 truncate \
464 umount \
465 uname \
466 uniq \
467 unix2dos \
468 usleep \
469 vmstat \
470 wc \
471 which \
472 whoami \
473 xargs \
Hashcode57332152016-12-20 01:30:49 +0100474 yes
475
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500476ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Hashcode57332152016-12-20 01:30:49 +0100477ALL_TOOLS += \
478 arp \
479 base64 \
480 chattr \
481 dd \
482 df \
483 diff \
Hashcode57332152016-12-20 01:30:49 +0100484 egrep \
485 fgrep \
486 flock \
487 freeramdisk \
488 fsfreeze \
489 fstype \
490 ftpget \
491 ftpput \
492 grep \
493 help \
494 install \
495 ionice \
496 iorenice \
497 iotop \
498 killall \
499 ls \
500 lsattr \
501 lsof \
502 lspci \
503 makedevs \
504 mkfifo \
505 mount \
506 nbd-client \
507 nc \
508 netcat \
509 nproc \
510 partprobe \
511 pivot_root \
512 ps \
513 pwdx \
514 readahead \
515 renice \
516 reset \
517 rev \
518 rfkill \
519 sha224sum \
520 sha256sum \
521 sha384sum \
522 sha512sum \
523 telnet \
524 test \
525 top \
526 traceroute \
527 traceroute6 \
528 tty \
529 tunctl \
530 ulimit \
531 uptime \
532 vconfig \
533 watch \
Humberto Borba84e16152018-01-05 00:51:40 -0200534 xxd
535ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 27; echo $$?),0)
536ALL_TOOLS += \
Ethan Yonker58f21322018-08-24 11:17:36 -0500537 getprop \
Hashcode57332152016-12-20 01:30:49 +0100538 xzcat
Humberto Borba84e16152018-01-05 00:51:40 -0200539endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500540ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 24; echo $$?),0)
541ALL_TOOLS += \
Humberto Borba84e16152018-01-05 00:51:40 -0200542 du \
543 gzip \
544 gunzip \
545 zcat
Ethan Yonker58f21322018-08-24 11:17:36 -0500546ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
547ALL_TOOLS += \
548 fmt \
549 start \
550 stop \
551 stty
552endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500553endif
Hashcode57332152016-12-20 01:30:49 +0100554# Account for master branch changes pulld into CM14.1
555ifneq ($(CM_BUILD),)
556ALL_TOOLS += \
557 chrt \
558 fdisk \
559 file \
560 getfattr \
561 host \
562 log \
563 resize \
564 setfattr
565endif
566endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500567
568# Install the symlinks.
569LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
570
571include $(BUILD_EXECUTABLE)
572
573# Make /sbin/toolbox launchers for each tool
574SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
575$(SYMLINKS): TOYBOX_BINARY := $(LOCAL_MODULE_STEM)
576$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
577 @echo "Symlink: $@ -> $(TOYBOX_BINARY)"
578 @mkdir -p $(dir $@)
579 @rm -rf $@
580 $(hide) ln -sf $(TOYBOX_BINARY) $@
581
582include $(CLEAR_VARS)
583LOCAL_MODULE := toybox_symlinks
584LOCAL_MODULE_TAGS := optional
585LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
586include $(BUILD_PHONY_PACKAGE)
587
588endif
589
590endif