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