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