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/dhcp.c", 219 "toys/pending/getfattr.c", 220 "toys/pending/lsof.c", 221 "toys/pending/modprobe.c", 222 "toys/pending/more.c", 223 "toys/pending/stty.c", 224 "toys/pending/traceroute.c", 225 "toys/pending/vi.c", 226 "toys/posix/cal.c", 227 "toys/posix/chgrp.c", 228 "toys/posix/cksum.c", 229 "toys/posix/df.c", 230 "toys/posix/expand.c", 231 "toys/posix/false.c", 232 "toys/posix/iconv.c", 233 "toys/posix/kill.c", 234 "toys/posix/logger.c", 235 "toys/posix/mkfifo.c", 236 "toys/posix/nice.c", 237 "toys/posix/nohup.c", 238 "toys/posix/renice.c", 239 "toys/posix/split.c", 240 "toys/posix/strings.c", 241 "toys/posix/time.c", 242 "toys/posix/tty.c", 243 "toys/posix/ulimit.c", 244 "toys/posix/unlink.c", 245 "toys/posix/uudecode.c", 246 "toys/posix/uuencode.c", 247] 248 249toybox_symlinks = [ 250 "[", 251 "acpi", 252 "base64", 253 "basename", 254 "blkdiscard", 255 "blockdev", 256 "brctl", 257 "cal", 258 "cat", 259 "chattr", 260 "chcon", 261 "chgrp", 262 "chmod", 263 "chown", 264 "chroot", 265 "chrt", 266 "cksum", 267 "clear", 268 "comm", 269 "cmp", 270 "cp", 271 "cpio", 272 "cut", 273 "date", 274 "dd", 275 "devmem", 276 "df", 277 "diff", 278 "dirname", 279 "dmesg", 280 "dos2unix", 281 "du", 282 "echo", 283 "egrep", 284 "env", 285 "expand", 286 "expr", 287 "fallocate", 288 "false", 289 "fgrep", 290 "file", 291 "find", 292 "flock", 293 "fmt", 294 "free", 295 "fsync", 296 "getconf", 297 "getenforce", 298 "getfattr", 299 "getopt", 300 "gpiodetect", 301 "gpiofind", 302 "gpioget", 303 "gpioinfo", 304 "gpioset", 305 "grep", 306 "groups", 307 "gunzip", 308 "gzip", 309 "head", 310 "hostname", 311 "hwclock", 312 "i2cdetect", 313 "i2cdump", 314 "i2cget", 315 "i2cset", 316 "i2ctransfer", 317 "iconv", 318 "id", 319 "ifconfig", 320 "inotifyd", 321 "insmod", 322 "install", 323 "ionice", 324 "iorenice", 325 "kill", 326 "killall", 327 "load_policy", 328 "ln", 329 "log", 330 "logger", 331 "logname", 332 "losetup", 333 "ls", 334 "lsattr", 335 "lsmod", 336 "lsof", 337 "lspci", 338 "lsusb", 339 "md5sum", 340 "memeater", 341 "mkdir", 342 "mkfifo", 343 "mknod", 344 "mkswap", 345 "mktemp", 346 "microcom", 347 "modinfo", 348 "more", 349 "mount", 350 "mountpoint", 351 "mv", 352 "nc", 353 "netcat", 354 "netstat", 355 "nice", 356 "nl", 357 "nohup", 358 "nproc", 359 "nsenter", 360 "od", 361 "paste", 362 "patch", 363 "pgrep", 364 "pidof", 365 "pkill", 366 "pmap", 367 "printenv", 368 "printf", 369 "ps", 370 "pwd", 371 "readelf", 372 "readlink", 373 "realpath", 374 "renice", 375 "restorecon", 376 "rm", 377 "rmdir", 378 "rmmod", 379 "rtcwake", 380 "runcon", 381 "sed", 382 "sendevent", 383 "seq", 384 "setenforce", 385 "setfattr", 386 "setsid", 387 "sha1sum", 388 "sha224sum", 389 "sha256sum", 390 "sha384sum", 391 "sha512sum", 392 "sleep", 393 "sort", 394 "split", 395 "stat", 396 "strings", 397 "stty", 398 "swapoff", 399 "swapon", 400 "sync", 401 "sysctl", 402 "tac", 403 "tail", 404 "tar", 405 "taskset", 406 "tee", 407 "test", 408 "time", 409 "timeout", 410 "top", 411 "touch", 412 "tr", 413 "true", 414 "truncate", 415 "tty", 416 "uclampset", 417 "ulimit", 418 "umount", 419 "uname", 420 "uniq", 421 "unix2dos", 422 "unlink", 423 "unshare", 424 "uptime", 425 "usleep", 426 "uudecode", 427 "uuencode", 428 "uuidgen", 429 "vi", 430 "vmstat", 431 "watch", 432 "wc", 433 "which", 434 "whoami", 435 "xargs", 436 "xxd", 437 "yes", 438 "zcat", 439] 440 441cc_defaults { 442 name: "toybox-defaults", 443 srcs: all_srcs, 444 445 cflags: [ 446 "-Os", 447 "-Wall", 448 "-Werror", 449 "-Wno-char-subscripts", 450 "-Wno-deprecated-declarations", 451 "-Wno-invalid-source-encoding", 452 "-Wno-missing-field-initializers", 453 "-Wno-pointer-arith", 454 "-Wno-sign-compare", 455 "-Wno-string-plus-int", 456 "-Wno-unused-parameter", 457 "-Wno-unused-variable", 458 "-funsigned-char", 459 "-ffunction-sections", 460 "-fdata-sections", 461 "-fno-asynchronous-unwind-tables", 462 "-DTOYBOX_VENDOR=\"-android\"", 463 ], 464 465 target: { 466 host_linux: { 467 local_include_dirs: ["android/linux"], 468 }, 469 470 darwin: { 471 local_include_dirs: ["android/mac"], 472 cflags: [ 473 // macOS' getgroups(3) signature differs. 474 "-Wno-pointer-sign", 475 // diff.c defines MIN and MAX which (only on macOS) we're 476 // also getting from <sys/param.h>. 477 "-Wno-macro-redefined", 478 ], 479 ldflags: [ 480 "-Wl,-dead_strip", 481 ], 482 }, 483 484 linux: { 485 srcs: linux_srcs, 486 }, 487 488 android: { 489 local_include_dirs: ["android/device"], 490 srcs: device_srcs, 491 }, 492 }, 493} 494 495//########################################### 496// toybox for /system, /vendor, and /recovery 497//########################################### 498 499cc_defaults { 500 name: "toybox-shared-defaults", 501 defaults: ["toybox-defaults"], 502 503 // This doesn't actually prevent us from dragging in libc++ at runtime 504 // on the device because libnetd_client.so is C++, but it improves host 505 // startup time. 506 stl: "none", 507 508 target: { 509 android: { 510 shared_libs: [ 511 "libcrypto", 512 "liblog", 513 "libselinux", 514 "libz", 515 ], 516 symlinks: toybox_symlinks, 517 }, 518 host: { 519 static_libs: [ 520 "libcrypto", 521 "libz", 522 ], 523 }, 524 }, 525} 526 527cc_binary { 528 name: "toybox", 529 defaults: ["toybox-shared-defaults"], 530 host_supported: true, 531 vendor_ramdisk_available: true, 532} 533 534cc_binary { 535 name: "toybox_vendor", 536 defaults: ["toybox-shared-defaults"], 537 vendor: true, 538} 539 540cc_binary { 541 name: "toybox_recovery", 542 defaults: ["toybox-shared-defaults"], 543 recovery: true, 544 stem: "toybox", 545} 546 547//########################################### 548// Static toybox binaries for legacy devices 549//########################################### 550 551cc_binary { 552 name: "toybox-static", 553 defaults: ["toybox-defaults"], 554 static_executable: true, 555 compile_multilib: "both", 556 multilib: { 557 lib32: { 558 suffix: "32", 559 }, 560 lib64: { 561 suffix: "64", 562 }, 563 }, 564 stl: "libc++_static", 565 static_libs: [ 566 "libc", 567 "libm", 568 "libz", 569 "libbase", 570 "libcrypto_static", 571 "liblog", 572 "libselinux", 573 ], 574 dist: { 575 targets: [ 576 "sdk", 577 ], 578 }, 579} 580 581//########################################### 582// Running the toybox tests 583//########################################### 584 585sh_test { 586 name: "toybox-tests", 587 src: "run-tests-on-android.sh", 588 filename: "run-tests-on-android.sh", 589 test_suites: ["general-tests"], 590 host_supported: true, 591 device_supported: false, 592 require_root: true, 593 data: [ 594 "tests/**/*", 595 "scripts/runtest.sh", 596 ], 597} 598 599cc_test { 600 name: "toybox-gtests", 601 compile_multilib: "first", 602 srcs: [ 603 "toybox-gtests.cpp", 604 ], 605 static_libs: [ 606 "libbase", 607 "liblog", 608 ], 609 test_suites: ["device-tests"], 610 require_root: true, 611 data: [ 612 "tests/**/*", 613 "scripts/runtest.sh", 614 ], 615} 616