blob: 5f6edec3f2b74fc31c62ca52fab31ec97043e231 [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
Captain Throwback695baa62019-04-26 10:46:32 -0400192ifeq ($(shell test $(PLATFORM_SDK_VERSION) -eq 26; echo $$?),0)
193# Android 8.0 had some tools in different paths
194LOCAL_SRC_FILES += \
195 toys/pending/dmesg.c
196else
197LOCAL_SRC_FILES += \
198 toys/lsb/dmesg.c
199endif
200
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500201ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
202# there are some conflicts here with AOSP-7.[01] and CM-14.[01]
Hashcode57332152016-12-20 01:30:49 +0100203# the following items have been removed for compatibility
204# ifconfig, netcat, netstat, rfkill, switch_root
205LOCAL_STATIC_LIBRARIES := libcrypto_static
206
207LOCAL_C_INCLUDES += \
208 external/boringssl/include \
209 bionic/libc/dns/include
210
211LOCAL_SRC_FILES += \
212 lib/linestack.c \
213 lib/password.c \
214 toys/other/flock.c \
215 toys/other/hwclock.c \
216 toys/other/ionice.c \
217 toys/other/lspci.c \
218 toys/other/readahead.c \
219 toys/other/reset.c \
220 toys/other/uptime.c \
221 toys/other/xxd.c \
222 toys/pending/arp.c \
223 toys/pending/diff.c \
Hashcode57332152016-12-20 01:30:49 +0100224 toys/pending/lsof.c \
225 toys/pending/telnet.c \
226 toys/pending/test.c \
227 toys/pending/watch.c \
Hashcode57332152016-12-20 01:30:49 +0100228 toys/posix/ps.c \
229 toys/posix/ulimit.c
Humberto Borba84e16152018-01-05 00:51:40 -0200230ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 27; echo $$?),0)
231LOCAL_SRC_FILES += \
232 toys/pending/xzcat.c
233endif
Humberto Borba84e16152018-01-05 00:51:40 -0200234
235ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
236# Android 8.0/8.1 had some tools in different paths
237LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500238 toys/net/ftpget.c
239else
240LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500241 toys/pending/ftpget.c
242endif
243
Hashcode57332152016-12-20 01:30:49 +0100244# Account for master branch changes pulld into CM14.1
245ifneq ($(CM_BUILD),)
246LOCAL_SRC_FILES += \
247 toys/android/log.c \
248 toys/android/sendevent.c \
249 toys/android/start.c \
250 toys/net/ifconfig.c \
251 toys/net/netcat.c \
252 toys/net/netstat.c \
253 toys/net/rfkill.c \
254 toys/net/tunctl.c \
255 toys/other/setfattr.c \
256 toys/pending/chrt.c \
257 toys/pending/fdisk.c \
258 toys/pending/getfattr.c \
259 toys/pending/host.c \
260 toys/pending/resize.c \
261 toys/posix/file.c
262else
263LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500264 toys/other/switch_root.c
265ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
266# Android 8.0 had some tools in different paths
267LOCAL_SRC_FILES += \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500268 toys/android/log.c \
269 toys/android/sendevent.c \
270 toys/android/start.c \
Ethan Yonker95e80072017-08-24 21:45:50 -0500271 toys/net/ifconfig.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500272 toys/net/microcom.c \
Ethan Yonker95e80072017-08-24 21:45:50 -0500273 toys/net/netcat.c \
274 toys/net/netstat.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500275 toys/net/rfkill.c \
276 toys/net/tunctl.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500277 toys/pending/getfattr.c \
278 toys/pending/modprobe.c \
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500279 toys/posix/file.c \
280 toys/posix/uudecode.c \
281 toys/posix/uuencode.c
Humberto Borba84e16152018-01-05 00:51:40 -0200282ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 26; echo $$?),0)
283# Android 8.1 had some tools in different paths
284LOCAL_SRC_FILES += \
285 toys/other/chrt.c \
286 toys/pending/gzip.c
287else
288LOCAL_SRC_FILES += \
289 toys/pending/chrt.c
290endif
Ethan Yonker58f21322018-08-24 11:17:36 -0500291ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
292# Android 9.0
293LOCAL_SRC_FILES += \
294 toys/other/setfattr.c \
295 toys/pending/fmt.c \
296 toys/pending/stty.c
297else
298LOCAL_SRC_FILES += \
299 toys/pending/setfattr.c
300endif
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500301LOCAL_SHARED_LIBRARIES += liblog
Ethan Yonker95e80072017-08-24 21:45:50 -0500302else
303LOCAL_SRC_FILES += \
Hashcode57332152016-12-20 01:30:49 +0100304 toys/other/ifconfig.c \
305 toys/other/netcat.c \
306 toys/other/rfkill.c \
Hashcode57332152016-12-20 01:30:49 +0100307 toys/pending/netstat.c
308endif
Ethan Yonker95e80072017-08-24 21:45:50 -0500309endif
Hashcode57332152016-12-20 01:30:49 +0100310else
311LOCAL_SRC_FILES += \
312 toys/other/ifconfig.c \
313 toys/other/netcat.c \
314 toys/other/rfkill.c \
315 toys/other/switch_root.c \
316 toys/pending/hwclock.c \
317 toys/pending/netstat.c \
318 toys/pending/pgrep.c \
319 toys/pending/top.c
320endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500321
322LOCAL_CFLAGS += \
Captain Throwback695baa62019-04-26 10:46:32 -0400323 -std=c99 \
Ethan Yonker58f21322018-08-24 11:17:36 -0500324 -std=gnu11 \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500325 -Os \
326 -Wno-char-subscripts \
327 -Wno-sign-compare \
328 -Wno-string-plus-int \
329 -Wno-uninitialized \
330 -Wno-unused-parameter \
331 -funsigned-char \
332 -ffunction-sections -fdata-sections \
333 -fno-asynchronous-unwind-tables \
334
Captain Throwback695baa62019-04-26 10:46:32 -0400335ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
336 toybox_version := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null)-android
337 LOCAL_CFLAGS += -DTOYBOX_VERSION='"$(toybox_version)"'
338else
339 toybox_version := $(shell sed 's/#define.*TOYBOX_VERSION.*"\(.*\)"/\1/p;d' $(LOCAL_PATH)/main.c)
340 LOCAL_CFLAGS += -DTOYBOX_VERSION=\"$(toybox_version)\"
341endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500342
343LOCAL_CLANG := true
344
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500345LOCAL_SHARED_LIBRARIES += libcutils libselinux
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500346
Humberto Borba84e16152018-01-05 00:51:40 -0200347ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 26; echo $$?),0)
348LOCAL_CFLAGS += \
349 -Wno-gnu-variable-sized-type-not-at-end \
350 -Wno-missing-field-initializers
351
352LOCAL_SHARED_LIBRARIES += libz
353endif
354
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500355LOCAL_MODULE := toybox_recovery
356LOCAL_MODULE_STEM := toybox
357LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
358LOCAL_MODULE_TAGS := optional
359
360# dupes: dd df du ls mount renice
361# useless?: freeramdisk fsfreeze install makedevs mkfifo nbd-client
362# partprobe pivot_root pwdx rev rfkill switch_root tty vconfig
363# prefer BSD netcat instead?: nc netcat
364# prefer efs2progs instead?: blkid chattr lsattr
365
366ALL_TOOLS := \
367 acpi \
368 basename \
369 blkid \
370 blockdev \
371 bzcat \
372 cal \
373 cat \
374 chcon \
375 chgrp \
376 chmod \
377 chown \
378 chroot \
379 cksum \
380 clear \
381 comm \
382 cmp \
383 cp \
384 cpio \
385 cut \
386 date \
387 dirname \
388 dmesg \
389 dos2unix \
390 echo \
391 env \
392 expand \
393 expr \
394 fallocate \
395 false \
396 find \
397 free \
398 getenforce \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500399 groups \
400 head \
401 hostname \
402 hwclock \
403 id \
404 ifconfig \
405 inotifyd \
406 insmod \
407 kill \
408 load_policy \
409 ln \
410 logname \
411 losetup \
412 lsmod \
413 lsusb \
414 md5sum \
415 mkdir \
416 mknod \
417 mkswap \
418 mktemp \
419 modinfo \
420 more \
421 mountpoint \
422 mv \
423 netstat \
424 nice \
425 nl \
426 nohup \
427 od \
428 paste \
429 patch \
430 pgrep \
431 pidof \
432 pkill \
433 pmap \
434 printenv \
435 printf \
436 pwd \
437 readlink \
438 realpath \
439 restorecon \
440 rm \
441 rmdir \
442 rmmod \
443 route \
444 runcon \
445 sed \
446 seq \
447 setenforce \
448 setprop \
449 setsid \
450 sha1sum \
451 sleep \
452 sort \
453 split \
454 stat \
455 strings \
456 swapoff \
457 swapon \
458 sync \
459 sysctl \
460 tac \
461 tail \
462 tar \
463 taskset \
464 tee \
465 time \
466 timeout \
467 touch \
468 tr \
469 true \
470 truncate \
471 umount \
472 uname \
473 uniq \
474 unix2dos \
475 usleep \
476 vmstat \
477 wc \
478 which \
479 whoami \
480 xargs \
Hashcode57332152016-12-20 01:30:49 +0100481 yes
482
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500483ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Hashcode57332152016-12-20 01:30:49 +0100484ALL_TOOLS += \
485 arp \
486 base64 \
487 chattr \
Hashcode57332152016-12-20 01:30:49 +0100488 df \
489 diff \
Hashcode57332152016-12-20 01:30:49 +0100490 flock \
491 freeramdisk \
492 fsfreeze \
493 fstype \
494 ftpget \
495 ftpput \
Hashcode57332152016-12-20 01:30:49 +0100496 help \
497 install \
498 ionice \
499 iorenice \
500 iotop \
501 killall \
502 ls \
503 lsattr \
504 lsof \
505 lspci \
506 makedevs \
507 mkfifo \
508 mount \
509 nbd-client \
510 nc \
511 netcat \
512 nproc \
513 partprobe \
514 pivot_root \
515 ps \
516 pwdx \
517 readahead \
518 renice \
519 reset \
520 rev \
521 rfkill \
522 sha224sum \
523 sha256sum \
524 sha384sum \
525 sha512sum \
526 telnet \
527 test \
528 top \
529 traceroute \
530 traceroute6 \
531 tty \
532 tunctl \
533 ulimit \
534 uptime \
535 vconfig \
536 watch \
Humberto Borba84e16152018-01-05 00:51:40 -0200537 xxd
Captain Throwbackf0167c42019-01-18 13:17:16 -0500538ifeq ($(shell test $(PLATFORM_SDK_VERSION) -le 27; echo $$?),0)
Humberto Borba84e16152018-01-05 00:51:40 -0200539ALL_TOOLS += \
Ethan Yonker58f21322018-08-24 11:17:36 -0500540 getprop \
Hashcode57332152016-12-20 01:30:49 +0100541 xzcat
Humberto Borba84e16152018-01-05 00:51:40 -0200542endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500543ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 24; echo $$?),0)
544ALL_TOOLS += \
Humberto Borba84e16152018-01-05 00:51:40 -0200545 du \
546 gzip \
547 gunzip \
548 zcat
bigbiff bigbiff6af36a42019-04-23 20:05:28 -0400549ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
Ethan Yonker58f21322018-08-24 11:17:36 -0500550ALL_TOOLS += \
551 fmt \
552 start \
553 stop \
554 stty
555endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500556endif
Hashcode57332152016-12-20 01:30:49 +0100557# Account for master branch changes pulld into CM14.1
558ifneq ($(CM_BUILD),)
559ALL_TOOLS += \
560 chrt \
561 fdisk \
562 file \
563 getfattr \
564 host \
565 log \
566 resize \
567 setfattr
568endif
569endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500570
571# Install the symlinks.
572LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
573
574include $(BUILD_EXECUTABLE)
575
576# Make /sbin/toolbox launchers for each tool
577SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
578$(SYMLINKS): TOYBOX_BINARY := $(LOCAL_MODULE_STEM)
579$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
580 @echo "Symlink: $@ -> $(TOYBOX_BINARY)"
581 @mkdir -p $(dir $@)
582 @rm -rf $@
583 $(hide) ln -sf $(TOYBOX_BINARY) $@
584
585include $(CLEAR_VARS)
586LOCAL_MODULE := toybox_symlinks
587LOCAL_MODULE_TAGS := optional
Ethan Yonkerae7ff3b2019-05-24 16:31:09 -0500588LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500589include $(BUILD_PHONY_PACKAGE)
590
591endif
592
593endif