• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2   --- To sync with upstream:
3
4    # Update source and regenerate generated files.
5    git remote add toybox https://github.com/landley/toybox.git
6    git fetch toybox && git merge toybox/master && ./regenerate.sh
7
8    # Make any necessary Android.bp changes and rebuild.
9    mm -j32
10
11    # Run all the tests.
12    ./run-tests-on-android.sh
13    # Run a single test.
14    ./run-tests-on-android.sh wc
15
16    # Upload changes.
17    git commit -a --amend
18    git push aosp HEAD:refs/for/master  # Push to gerrit for review.
19    git push aosp HEAD:master           # Push directly, avoiding gerrit.
20
21
22   --- To add a toy:
23
24    # Edit the three .config-* files to enable the toy you want for the targets
25    # you want it on, and regenerate the generated files:
26    ./regenerate.sh
27
28    # Edit the relevant `srcs` below, depending on where the toy should be
29    # available.
30
31    # If you just want to use the toy via "toybox x" rather than "x", you can
32    # stop now. If you want this toy to have a symbolic link in /system/bin,
33    # add the toy to symlinks.
34
35*/
36
37package {
38    default_applicable_licenses: ["external_toybox_license"],
39}
40
41license {
42    name: "external_toybox_license",
43    visibility: [":__subpackages__"],
44    license_kinds: [
45        "SPDX-license-identifier-0BSD",
46        "SPDX-license-identifier-CC0-1.0",
47        "SPDX-license-identifier-Unlicense",
48        "legacy_unencumbered",
49    ],
50    license_text: [
51        "LICENSE",
52    ],
53}
54
55all_srcs = [
56    "lib/args.c",
57    "lib/commas.c",
58    "lib/dirtree.c",
59    "lib/env.c",
60    "lib/lib.c",
61    "lib/llist.c",
62    "lib/net.c",
63    "lib/portability.c",
64    "lib/tty.c",
65    "lib/utf8.c",
66    "lib/xwrap.c",
67    "main.c",
68    "toys/lsb/gzip.c",
69    "toys/lsb/hostname.c",
70    "toys/lsb/md5sum.c",
71    "toys/lsb/mktemp.c",
72    "toys/lsb/seq.c",
73    "toys/net/microcom.c",
74    "toys/other/dos2unix.c",
75    "toys/other/readlink.c",
76    "toys/other/setsid.c",
77    "toys/other/stat.c",
78    "toys/other/timeout.c",
79    "toys/other/truncate.c",
80    "toys/other/which.c",
81    "toys/other/xxd.c",
82    "toys/other/yes.c",
83    "toys/pending/dd.c",
84    "toys/pending/diff.c",
85    "toys/pending/expr.c",
86    "toys/pending/getopt.c",
87    "toys/pending/tr.c",
88    "toys/posix/basename.c",
89    "toys/posix/cat.c",
90    "toys/posix/chmod.c",
91    "toys/posix/cmp.c",
92    "toys/posix/comm.c",
93    "toys/posix/cp.c",
94    "toys/posix/cpio.c",
95    "toys/posix/cut.c",
96    "toys/posix/date.c",
97    "toys/posix/dirname.c",
98    "toys/posix/du.c",
99    "toys/posix/echo.c",
100    "toys/posix/env.c",
101    "toys/posix/find.c",
102    "toys/posix/getconf.c",
103    "toys/posix/grep.c",
104    "toys/posix/head.c",
105    "toys/posix/id.c",
106    "toys/posix/ln.c",
107    "toys/posix/ls.c",
108    "toys/posix/mkdir.c",
109    "toys/posix/nl.c",
110    "toys/posix/od.c",
111    "toys/posix/paste.c",
112    "toys/posix/patch.c",
113    "toys/posix/printf.c",
114    "toys/posix/pwd.c",
115    "toys/posix/rm.c",
116    "toys/posix/rmdir.c",
117    "toys/posix/sed.c",
118    "toys/posix/sleep.c",
119    "toys/posix/sort.c",
120    "toys/posix/tail.c",
121    "toys/posix/tar.c",
122    "toys/posix/tee.c",
123    "toys/posix/test.c",
124    "toys/posix/touch.c",
125    "toys/posix/true.c",
126    "toys/posix/uname.c",
127    "toys/posix/uniq.c",
128    "toys/posix/wc.c",
129    "toys/posix/xargs.c",
130]
131
132linux_srcs = [
133    "toys/posix/ps.c",
134    "toys/other/taskset.c",
135]
136
137device_srcs = [
138    "toys/android/getenforce.c",
139    "toys/android/load_policy.c",
140    "toys/android/log.c",
141    "toys/android/restorecon.c",
142    "toys/android/runcon.c",
143    "toys/android/sendevent.c",
144    "toys/android/setenforce.c",
145    "toys/lsb/dmesg.c",
146    "toys/lsb/killall.c",
147    "toys/lsb/mknod.c",
148    "toys/lsb/mount.c",
149    "toys/lsb/pidof.c",
150    "toys/lsb/sync.c",
151    "toys/lsb/umount.c",
152    "toys/net/ifconfig.c",
153    "toys/net/netcat.c",
154    "toys/net/netstat.c",
155    "toys/net/ping.c",
156    "toys/net/rfkill.c",
157    "toys/net/tunctl.c",
158    "toys/other/acpi.c",
159    "toys/other/base64.c",
160    "toys/other/blkdiscard.c",
161    "toys/other/blkid.c",
162    "toys/other/blockdev.c",
163    "toys/other/chcon.c",
164    "toys/other/chroot.c",
165    "toys/other/chrt.c",
166    "toys/other/clear.c",
167    "toys/other/devmem.c",
168    "toys/other/fallocate.c",
169    "toys/other/flock.c",
170    "toys/other/fmt.c",
171    "toys/other/free.c",
172    "toys/other/freeramdisk.c",
173    "toys/other/fsfreeze.c",
174    "toys/other/fsync.c",
175    "toys/other/help.c",
176    "toys/other/hwclock.c",
177    "toys/other/i2ctools.c",
178    "toys/other/inotifyd.c",
179    "toys/other/insmod.c",
180    "toys/other/ionice.c",
181    "toys/other/losetup.c",
182    "toys/other/lsattr.c",
183    "toys/other/lsmod.c",
184    "toys/other/lsusb.c",
185    "toys/other/makedevs.c",
186    "toys/other/mkswap.c",
187    "toys/other/modinfo.c",
188    "toys/other/mountpoint.c",
189    "toys/other/nbd_client.c",
190    "toys/other/nsenter.c",
191    "toys/other/partprobe.c",
192    "toys/other/pivot_root.c",
193    "toys/other/pmap.c",
194    "toys/other/printenv.c",
195    "toys/other/pwdx.c",
196    "toys/other/readelf.c",
197    "toys/other/rev.c",
198    "toys/other/rmmod.c",
199    "toys/other/rtcwake.c",
200    "toys/other/setfattr.c",
201    "toys/other/swapoff.c",
202    "toys/other/swapon.c",
203    "toys/other/sysctl.c",
204    "toys/other/tac.c",
205    "toys/other/uclampset.c",
206    "toys/other/uptime.c",
207    "toys/other/usleep.c",
208    "toys/other/uuidgen.c",
209    "toys/other/vconfig.c",
210    "toys/other/vmstat.c",
211    "toys/other/watch.c",
212    "toys/pending/getfattr.c",
213    "toys/pending/lsof.c",
214    "toys/pending/modprobe.c",
215    "toys/pending/more.c",
216    "toys/pending/stty.c",
217    "toys/pending/traceroute.c",
218    "toys/pending/vi.c",
219    "toys/posix/cal.c",
220    "toys/posix/chgrp.c",
221    "toys/posix/cksum.c",
222    "toys/posix/df.c",
223    "toys/posix/expand.c",
224    "toys/posix/false.c",
225    "toys/posix/file.c",
226    "toys/posix/iconv.c",
227    "toys/posix/kill.c",
228    "toys/posix/mkfifo.c",
229    "toys/posix/nice.c",
230    "toys/posix/nohup.c",
231    "toys/posix/renice.c",
232    "toys/posix/split.c",
233    "toys/posix/strings.c",
234    "toys/posix/time.c",
235    "toys/posix/tty.c",
236    "toys/posix/ulimit.c",
237    "toys/posix/unlink.c",
238    "toys/posix/uudecode.c",
239    "toys/posix/uuencode.c",
240]
241
242toybox_symlinks = [
243    "[",
244    "acpi",
245    "base64",
246    "basename",
247    "blockdev",
248    "cal",
249    "cat",
250    "chattr",
251    "chcon",
252    "chgrp",
253    "chmod",
254    "chown",
255    "chroot",
256    "chrt",
257    "cksum",
258    "clear",
259    "comm",
260    "cmp",
261    "cp",
262    "cpio",
263    "cut",
264    "date",
265    "dd",
266    "devmem",
267    "df",
268    "diff",
269    "dirname",
270    "dmesg",
271    "dos2unix",
272    "du",
273    "echo",
274    "egrep",
275    "env",
276    "expand",
277    "expr",
278    "fallocate",
279    "false",
280    "fgrep",
281    "file",
282    "find",
283    "flock",
284    "fmt",
285    "free",
286    "fsync",
287    "getconf",
288    "getenforce",
289    "grep",
290    "groups",
291    "gunzip",
292    "gzip",
293    "head",
294    "hostname",
295    "hwclock",
296    "i2cdetect",
297    "i2cdump",
298    "i2cget",
299    "i2cset",
300    "iconv",
301    "id",
302    "ifconfig",
303    "inotifyd",
304    "insmod",
305    "install",
306    "ionice",
307    "iorenice",
308    "kill",
309    "killall",
310    "load_policy",
311    "ln",
312    "log",
313    "logname",
314    "losetup",
315    "ls",
316    "lsattr",
317    "lsmod",
318    "lsof",
319    "lspci",
320    "lsusb",
321    "md5sum",
322    "mkdir",
323    "mkfifo",
324    "mknod",
325    "mkswap",
326    "mktemp",
327    "microcom",
328    "modinfo",
329    "more",
330    "mount",
331    "mountpoint",
332    "mv",
333    "nc",
334    "netcat",
335    "netstat",
336    "nice",
337    "nl",
338    "nohup",
339    "nproc",
340    "nsenter",
341    "od",
342    "paste",
343    "patch",
344    "pgrep",
345    "pidof",
346    "pkill",
347    "pmap",
348    "printenv",
349    "printf",
350    "ps",
351    "pwd",
352    "readelf",
353    "readlink",
354    "realpath",
355    "renice",
356    "restorecon",
357    "rm",
358    "rmdir",
359    "rmmod",
360    "rtcwake",
361    "runcon",
362    "sed",
363    "sendevent",
364    "seq",
365    "setenforce",
366    "setsid",
367    "sha1sum",
368    "sha224sum",
369    "sha256sum",
370    "sha384sum",
371    "sha512sum",
372    "sleep",
373    "sort",
374    "split",
375    "stat",
376    "strings",
377    "stty",
378    "swapoff",
379    "swapon",
380    "sync",
381    "sysctl",
382    "tac",
383    "tail",
384    "tar",
385    "taskset",
386    "tee",
387    "test",
388    "time",
389    "timeout",
390    "top",
391    "touch",
392    "tr",
393    "true",
394    "truncate",
395    "tty",
396    "uclampset",
397    "ulimit",
398    "umount",
399    "uname",
400    "uniq",
401    "unix2dos",
402    "unlink",
403    "unshare",
404    "uptime",
405    "usleep",
406    "uudecode",
407    "uuencode",
408    "uuidgen",
409    "vmstat",
410    "watch",
411    "wc",
412    "which",
413    "whoami",
414    "xargs",
415    "xxd",
416    "yes",
417    "zcat",
418]
419
420cc_defaults {
421    name: "toybox-defaults",
422    srcs: all_srcs,
423
424    cflags: [
425        "-Os",
426        "-Wall",
427        "-Werror",
428        "-Wno-char-subscripts",
429        "-Wno-deprecated-declarations",
430        "-Wno-missing-field-initializers",
431        "-Wno-pointer-arith",
432        "-Wno-sign-compare",
433        "-Wno-string-plus-int",
434        "-Wno-unused-parameter",
435        "-Wno-unused-variable",
436        "-funsigned-char",
437        "-ffunction-sections",
438        "-fdata-sections",
439        "-fno-asynchronous-unwind-tables",
440        "-DTOYBOX_VENDOR=\"-android\"",
441    ],
442
443    target: {
444        host_linux: {
445            local_include_dirs: ["android/linux"],
446        },
447
448        darwin: {
449            local_include_dirs: ["android/mac"],
450            cflags: [
451                // You can't have toybox cp(1) on macOS before 10.13.
452                "-mmacosx-version-min=10.13",
453                "-UMACOSX_DEPLOYMENT_TARGET",
454                "-DMACOSX_DEPLOYMENT_TARGET=10.13",
455                // macOS' getgroups(3) signature differs.
456                "-Wno-pointer-sign",
457                // diff.c defines MIN and MAX which (only on macOS) we're
458                // also getting from <sys/param.h>.
459                "-Wno-macro-redefined",
460            ],
461            ldflags: [
462                "-Wl,-dead_strip",
463            ],
464        },
465
466        linux: {
467            srcs: linux_srcs,
468        },
469
470        android: {
471            local_include_dirs: ["android/device"],
472            srcs: device_srcs,
473        },
474    },
475}
476
477//###########################################
478// toybox for /system, /vendor, and /recovery
479//###########################################
480
481cc_defaults {
482    name: "toybox-shared-defaults",
483    defaults: ["toybox-defaults"],
484
485    // This doesn't actually prevent us from dragging in libc++ at runtime
486    // on the device because libnetd_client.so is C++, but it improves host
487    // startup time.
488    stl: "none",
489
490    shared_libs: [
491        "libcrypto",
492        "libz",
493    ],
494
495    target: {
496        android: {
497            shared_libs: [
498                "liblog",
499                "libprocessgroup",
500                "libselinux",
501            ],
502            symlinks: toybox_symlinks,
503        },
504    },
505}
506
507cc_binary {
508    name: "toybox",
509    defaults: ["toybox-shared-defaults"],
510    host_supported: true,
511    recovery_available: true,
512    vendor_ramdisk_available: true,
513}
514
515cc_binary {
516    name: "toybox_vendor",
517    defaults: ["toybox-shared-defaults"],
518    vendor: true,
519}
520
521//###########################################
522// Static toybox binaries for legacy devices
523//###########################################
524
525cc_binary {
526    name: "toybox-static",
527    defaults: ["toybox-defaults"],
528    static_executable: true,
529    compile_multilib: "both",
530    multilib: {
531        lib32: { suffix: "32", },
532        lib64: { suffix: "64", },
533    },
534    stl: "libc++_static",
535    static_libs: [
536        "libc",
537        "libm",
538        "libz",
539        "libbase",
540        "libcgrouprc",
541        "libcgrouprc_format",
542        "libcrypto_static",
543        "liblog",
544        "libprocessgroup",
545        "libselinux",
546    ],
547    dist: {
548        targets: [
549            "sdk",
550        ],
551    },
552}
553
554//###########################################
555// Running the toybox tests
556//###########################################
557
558sh_test {
559    name: "toybox-tests",
560    src: "run-tests-on-android.sh",
561    filename: "run-tests-on-android.sh",
562    test_suites: ["general-tests"],
563    host_supported: true,
564    device_supported: false,
565    require_root:true,
566    data: [
567        "tests/**/*",
568        "scripts/runtest.sh",
569    ],
570}
571