xref: /aosp_15_r20/external/toybox/Android.bp (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
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    ./post_update.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` below.
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/elf.c",
60    "lib/env.c",
61    "lib/hash.c",
62    "lib/lib.c",
63    "lib/llist.c",
64    "lib/net.c",
65    "lib/portability.c",
66    "lib/tty.c",
67    "lib/utf8.c",
68    "lib/xwrap.c",
69    "main.c",
70    "toys/lsb/gzip.c",
71    "toys/lsb/hostname.c",
72    "toys/lsb/md5sum.c",
73    "toys/lsb/mktemp.c",
74    "toys/lsb/seq.c",
75    "toys/net/microcom.c",
76    "toys/other/dos2unix.c",
77    "toys/other/getopt.c",
78    "toys/other/readlink.c",
79    "toys/other/setsid.c",
80    "toys/other/stat.c",
81    "toys/other/timeout.c",
82    "toys/other/truncate.c",
83    "toys/other/which.c",
84    "toys/other/xxd.c",
85    "toys/other/yes.c",
86    "toys/pending/diff.c",
87    "toys/pending/expr.c",
88    "toys/pending/tr.c",
89    "toys/posix/basename.c",
90    "toys/posix/cat.c",
91    "toys/posix/chmod.c",
92    "toys/posix/cmp.c",
93    "toys/posix/comm.c",
94    "toys/posix/cp.c",
95    "toys/posix/cpio.c",
96    "toys/posix/cut.c",
97    "toys/posix/date.c",
98    "toys/posix/dd.c",
99    "toys/posix/dirname.c",
100    "toys/posix/du.c",
101    "toys/posix/echo.c",
102    "toys/posix/env.c",
103    "toys/posix/file.c",
104    "toys/posix/find.c",
105    "toys/posix/getconf.c",
106    "toys/posix/grep.c",
107    "toys/posix/head.c",
108    "toys/posix/id.c",
109    "toys/posix/ln.c",
110    "toys/posix/ls.c",
111    "toys/posix/mkdir.c",
112    "toys/posix/nl.c",
113    "toys/posix/od.c",
114    "toys/posix/paste.c",
115    "toys/posix/patch.c",
116    "toys/posix/printf.c",
117    "toys/posix/pwd.c",
118    "toys/posix/rm.c",
119    "toys/posix/rmdir.c",
120    "toys/posix/sed.c",
121    "toys/posix/sleep.c",
122    "toys/posix/sort.c",
123    "toys/posix/tail.c",
124    "toys/posix/tar.c",
125    "toys/posix/tee.c",
126    "toys/posix/test.c",
127    "toys/posix/touch.c",
128    "toys/posix/true.c",
129    "toys/posix/uname.c",
130    "toys/posix/uniq.c",
131    "toys/posix/wc.c",
132    "toys/posix/xargs.c",
133]
134
135linux_srcs = [
136    "toys/lsb/mount.c",
137    "toys/lsb/umount.c",
138    "toys/posix/ps.c",
139    "toys/other/flock.c",
140    "toys/other/nsenter.c",
141    "toys/other/taskset.c",
142]
143
144device_srcs = [
145    "toys/android/getenforce.c",
146    "toys/android/load_policy.c",
147    "toys/android/log.c",
148    "toys/android/restorecon.c",
149    "toys/android/runcon.c",
150    "toys/android/sendevent.c",
151    "toys/android/setenforce.c",
152    "toys/lsb/dmesg.c",
153    "toys/lsb/killall.c",
154    "toys/lsb/mknod.c",
155    "toys/lsb/pidof.c",
156    "toys/lsb/sync.c",
157    "toys/net/ifconfig.c",
158    "toys/net/netcat.c",
159    "toys/net/netstat.c",
160    "toys/net/ping.c",
161    "toys/net/rfkill.c",
162    "toys/net/tunctl.c",
163    "toys/other/acpi.c",
164    "toys/other/base64.c",
165    "toys/other/blkdiscard.c",
166    "toys/other/blkid.c",
167    "toys/other/blockdev.c",
168    "toys/other/chcon.c",
169    "toys/other/chroot.c",
170    "toys/other/chrt.c",
171    "toys/other/clear.c",
172    "toys/other/devmem.c",
173    "toys/other/fallocate.c",
174    "toys/other/fmt.c",
175    "toys/other/free.c",
176    "toys/other/freeramdisk.c",
177    "toys/other/fsfreeze.c",
178    "toys/other/fsync.c",
179    "toys/other/gpiod.c",
180    "toys/other/help.c",
181    "toys/other/hwclock.c",
182    "toys/other/i2ctools.c",
183    "toys/other/inotifyd.c",
184    "toys/other/insmod.c",
185    "toys/other/ionice.c",
186    "toys/other/losetup.c",
187    "toys/other/lsattr.c",
188    "toys/other/lsmod.c",
189    "toys/other/lsusb.c",
190    "toys/other/makedevs.c",
191    "toys/other/memeater.c",
192    "toys/other/mkswap.c",
193    "toys/other/modinfo.c",
194    "toys/other/mountpoint.c",
195    "toys/other/nbd_client.c",
196    "toys/other/partprobe.c",
197    "toys/other/pivot_root.c",
198    "toys/other/pmap.c",
199    "toys/other/printenv.c",
200    "toys/other/pwdx.c",
201    "toys/other/readelf.c",
202    "toys/other/rev.c",
203    "toys/other/rmmod.c",
204    "toys/other/rtcwake.c",
205    "toys/other/setfattr.c",
206    "toys/other/swapoff.c",
207    "toys/other/swapon.c",
208    "toys/other/sysctl.c",
209    "toys/other/tac.c",
210    "toys/other/uclampset.c",
211    "toys/other/uptime.c",
212    "toys/other/usleep.c",
213    "toys/other/uuidgen.c",
214    "toys/other/vconfig.c",
215    "toys/other/vmstat.c",
216    "toys/other/watch.c",
217    "toys/pending/brctl.c",
218    "toys/pending/getfattr.c",
219    "toys/pending/lsof.c",
220    "toys/pending/modprobe.c",
221    "toys/pending/more.c",
222    "toys/pending/stty.c",
223    "toys/pending/traceroute.c",
224    "toys/pending/vi.c",
225    "toys/posix/cal.c",
226    "toys/posix/chgrp.c",
227    "toys/posix/cksum.c",
228    "toys/posix/df.c",
229    "toys/posix/expand.c",
230    "toys/posix/false.c",
231    "toys/posix/iconv.c",
232    "toys/posix/kill.c",
233    "toys/posix/logger.c",
234    "toys/posix/mkfifo.c",
235    "toys/posix/nice.c",
236    "toys/posix/nohup.c",
237    "toys/posix/renice.c",
238    "toys/posix/split.c",
239    "toys/posix/strings.c",
240    "toys/posix/time.c",
241    "toys/posix/tty.c",
242    "toys/posix/ulimit.c",
243    "toys/posix/unlink.c",
244    "toys/posix/uudecode.c",
245    "toys/posix/uuencode.c",
246]
247
248toybox_symlinks = [
249    "[",
250    "acpi",
251    "base64",
252    "basename",
253    "blkdiscard",
254    "blockdev",
255    "brctl",
256    "cal",
257    "cat",
258    "chattr",
259    "chcon",
260    "chgrp",
261    "chmod",
262    "chown",
263    "chroot",
264    "chrt",
265    "cksum",
266    "clear",
267    "comm",
268    "cmp",
269    "cp",
270    "cpio",
271    "cut",
272    "date",
273    "dd",
274    "devmem",
275    "df",
276    "diff",
277    "dirname",
278    "dmesg",
279    "dos2unix",
280    "du",
281    "echo",
282    "egrep",
283    "env",
284    "expand",
285    "expr",
286    "fallocate",
287    "false",
288    "fgrep",
289    "file",
290    "find",
291    "flock",
292    "fmt",
293    "free",
294    "fsync",
295    "getconf",
296    "getenforce",
297    "getfattr",
298    "getopt",
299    "gpiodetect",
300    "gpiofind",
301    "gpioget",
302    "gpioinfo",
303    "gpioset",
304    "grep",
305    "groups",
306    "gunzip",
307    "gzip",
308    "head",
309    "hostname",
310    "hwclock",
311    "i2cdetect",
312    "i2cdump",
313    "i2cget",
314    "i2cset",
315    "i2ctransfer",
316    "iconv",
317    "id",
318    "ifconfig",
319    "inotifyd",
320    "insmod",
321    "install",
322    "ionice",
323    "iorenice",
324    "kill",
325    "killall",
326    "load_policy",
327    "ln",
328    "log",
329    "logger",
330    "logname",
331    "losetup",
332    "ls",
333    "lsattr",
334    "lsmod",
335    "lsof",
336    "lspci",
337    "lsusb",
338    "md5sum",
339    "memeater",
340    "mkdir",
341    "mkfifo",
342    "mknod",
343    "mkswap",
344    "mktemp",
345    "microcom",
346    "modinfo",
347    "more",
348    "mount",
349    "mountpoint",
350    "mv",
351    "nc",
352    "netcat",
353    "netstat",
354    "nice",
355    "nl",
356    "nohup",
357    "nproc",
358    "nsenter",
359    "od",
360    "paste",
361    "patch",
362    "pgrep",
363    "pidof",
364    "pkill",
365    "pmap",
366    "printenv",
367    "printf",
368    "ps",
369    "pwd",
370    "readelf",
371    "readlink",
372    "realpath",
373    "renice",
374    "restorecon",
375    "rm",
376    "rmdir",
377    "rmmod",
378    "rtcwake",
379    "runcon",
380    "sed",
381    "sendevent",
382    "seq",
383    "setenforce",
384    "setfattr",
385    "setsid",
386    "sha1sum",
387    "sha224sum",
388    "sha256sum",
389    "sha384sum",
390    "sha512sum",
391    "sleep",
392    "sort",
393    "split",
394    "stat",
395    "strings",
396    "stty",
397    "swapoff",
398    "swapon",
399    "sync",
400    "sysctl",
401    "tac",
402    "tail",
403    "tar",
404    "taskset",
405    "tee",
406    "test",
407    "time",
408    "timeout",
409    "top",
410    "touch",
411    "tr",
412    "true",
413    "truncate",
414    "tty",
415    "uclampset",
416    "ulimit",
417    "umount",
418    "uname",
419    "uniq",
420    "unix2dos",
421    "unlink",
422    "unshare",
423    "uptime",
424    "usleep",
425    "uudecode",
426    "uuencode",
427    "uuidgen",
428    "vi",
429    "vmstat",
430    "watch",
431    "wc",
432    "which",
433    "whoami",
434    "xargs",
435    "xxd",
436    "yes",
437    "zcat",
438]
439
440cc_defaults {
441    name: "toybox-defaults",
442    srcs: all_srcs,
443
444    cflags: [
445        "-Os",
446        "-Wall",
447        "-Werror",
448        "-Wno-char-subscripts",
449        "-Wno-deprecated-declarations",
450        "-Wno-invalid-source-encoding",
451        "-Wno-missing-field-initializers",
452        "-Wno-pointer-arith",
453        "-Wno-sign-compare",
454        "-Wno-string-plus-int",
455        "-Wno-unused-parameter",
456        "-Wno-unused-variable",
457        "-funsigned-char",
458        "-ffunction-sections",
459        "-fdata-sections",
460        "-fno-asynchronous-unwind-tables",
461        "-DTOYBOX_VENDOR=\"-android\"",
462    ],
463
464    target: {
465        host_linux: {
466            local_include_dirs: ["android/linux"],
467        },
468
469        darwin: {
470            local_include_dirs: ["android/mac"],
471            cflags: [
472                // macOS' getgroups(3) signature differs.
473                "-Wno-pointer-sign",
474                // diff.c defines MIN and MAX which (only on macOS) we're
475                // also getting from <sys/param.h>.
476                "-Wno-macro-redefined",
477            ],
478            ldflags: [
479                "-Wl,-dead_strip",
480            ],
481        },
482
483        linux: {
484            srcs: linux_srcs,
485        },
486
487        android: {
488            local_include_dirs: ["android/device"],
489            srcs: device_srcs,
490        },
491    },
492}
493
494//###########################################
495// toybox for /system, /vendor, and /recovery
496//###########################################
497
498cc_defaults {
499    name: "toybox-shared-defaults",
500    defaults: ["toybox-defaults"],
501
502    // This doesn't actually prevent us from dragging in libc++ at runtime
503    // on the device because libnetd_client.so is C++, but it improves host
504    // startup time.
505    stl: "none",
506
507    target: {
508        android: {
509            shared_libs: [
510                "libcrypto",
511                "liblog",
512                "libselinux",
513                "libz",
514            ],
515            symlinks: toybox_symlinks,
516        },
517        host: {
518            static_libs: [
519                "libcrypto",
520                "libz",
521            ],
522        },
523    },
524}
525
526cc_binary {
527    name: "toybox",
528    defaults: ["toybox-shared-defaults"],
529    host_supported: true,
530    vendor_ramdisk_available: true,
531}
532
533cc_binary {
534    name: "toybox_vendor",
535    defaults: ["toybox-shared-defaults"],
536    vendor: true,
537}
538
539cc_binary {
540    name: "toybox_recovery",
541    defaults: ["toybox-shared-defaults"],
542    recovery: true,
543    stem: "toybox",
544}
545
546//###########################################
547// Static toybox binaries for legacy devices
548//###########################################
549
550cc_binary {
551    name: "toybox-static",
552    defaults: ["toybox-defaults"],
553    static_executable: true,
554    compile_multilib: "both",
555    multilib: {
556        lib32: {
557            suffix: "32",
558        },
559        lib64: {
560            suffix: "64",
561        },
562    },
563    stl: "libc++_static",
564    static_libs: [
565        "libc",
566        "libm",
567        "libz",
568        "libbase",
569        "libcrypto_static",
570        "liblog",
571        "libselinux",
572    ],
573    dist: {
574        targets: [
575            "sdk",
576        ],
577    },
578}
579
580//###########################################
581// Running the toybox tests
582//###########################################
583
584sh_test {
585    name: "toybox-tests",
586    src: "run-tests-on-android.sh",
587    filename: "run-tests-on-android.sh",
588    test_suites: ["general-tests"],
589    host_supported: true,
590    device_supported: false,
591    require_root: true,
592    data: [
593        "tests/**/*",
594        "scripts/runtest.sh",
595    ],
596}
597
598cc_test {
599    name: "toybox-gtests",
600    compile_multilib: "first",
601    srcs: [
602        "toybox-gtests.cpp",
603    ],
604    static_libs: [
605        "libbase",
606        "liblog",
607    ],
608    test_suites: ["device-tests"],
609    require_root: true,
610    data: [
611        "tests/**/*",
612        "scripts/runtest.sh",
613    ],
614}
615