blob: ca8fe46ccb9dafae7a7e54d74b0584682b5d7708 [file] [log] [blame]
Ethan Yonkerc798c9c2015-10-09 11:15:26 -05001#
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
17ifneq ($(wildcard external/toybox/Android.mk),)
18
19ifeq ($(TW_USE_TOOLBOX), true)
20
21LOCAL_PATH := external/toybox
22
23#
24# To update:
25#
26
27# git remote add toybox https://github.com/landley/toybox.git
28# git fetch toybox
29# git merge toybox/master
30# mm -j32
31# # (Make any necessary Android.mk changes and test the new toybox.)
32# git push aosp HEAD:master # Push directly, avoiding gerrit.
33# git push aosp HEAD:refs/for/master # Push to gerrit.
34#
35# # Now commit any necessary Android.mk changes like normal:
36# repo start post-sync .
37# git commit -a
38
39
40#
41# To add a toy:
42#
43
44# make menuconfig
45# # (Select the toy you want to add.)
46# make clean && make # Regenerate the generated files.
47# # Edit LOCAL_SRC_FILES below to add the toy.
48# # If you just want to use it as "toybox x" rather than "x", you can stop now.
49# # If you want this toy to have a symbolic link in /system/bin, add the toy to ALL_TOOLS.
50
51include $(CLEAR_VARS)
52
53LOCAL_SRC_FILES := \
54 lib/args.c \
55 lib/dirtree.c \
56 lib/getmountlist.c \
57 lib/help.c \
58 lib/interestingtimes.c \
59 lib/lib.c \
60 lib/llist.c \
61 lib/net.c \
62 lib/portability.c \
63 lib/xwrap.c \
64 main.c \
65 toys/android/getenforce.c \
66 toys/android/getprop.c \
67 toys/android/load_policy.c \
68 toys/android/restorecon.c \
69 toys/android/runcon.c \
70 toys/android/setenforce.c \
71 toys/android/setprop.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050072 toys/lsb/hostname.c \
73 toys/lsb/killall.c \
74 toys/lsb/md5sum.c \
75 toys/lsb/mknod.c \
76 toys/lsb/mktemp.c \
77 toys/lsb/mount.c \
78 toys/lsb/pidof.c \
79 toys/lsb/seq.c \
80 toys/lsb/sync.c \
81 toys/lsb/umount.c \
82 toys/other/acpi.c \
83 toys/other/base64.c \
84 toys/other/blkid.c \
85 toys/other/blockdev.c \
86 toys/other/bzcat.c \
87 toys/other/chcon.c \
88 toys/other/chroot.c \
89 toys/other/clear.c \
90 toys/other/dos2unix.c \
91 toys/other/fallocate.c \
92 toys/other/free.c \
93 toys/other/freeramdisk.c \
94 toys/other/fsfreeze.c \
95 toys/other/help.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050096 toys/other/inotifyd.c \
97 toys/other/insmod.c \
98 toys/other/losetup.c \
99 toys/other/lsattr.c \
100 toys/other/lsmod.c \
101 toys/other/lsusb.c \
102 toys/other/makedevs.c \
103 toys/other/mkswap.c \
104 toys/other/modinfo.c \
105 toys/other/mountpoint.c \
106 toys/other/nbd_client.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500107 toys/other/partprobe.c \
108 toys/other/pivot_root.c \
109 toys/other/pmap.c \
110 toys/other/printenv.c \
111 toys/other/pwdx.c \
112 toys/other/readlink.c \
113 toys/other/realpath.c \
114 toys/other/rev.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500115 toys/other/rmmod.c \
116 toys/other/setsid.c \
117 toys/other/stat.c \
118 toys/other/swapoff.c \
119 toys/other/swapon.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500120 toys/other/sysctl.c \
121 toys/other/tac.c \
122 toys/other/taskset.c \
123 toys/other/timeout.c \
124 toys/other/truncate.c \
125 toys/other/usleep.c \
126 toys/other/vconfig.c \
127 toys/other/vmstat.c \
128 toys/other/which.c \
129 toys/other/yes.c \
130 toys/pending/dd.c \
131 toys/pending/expr.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500132 toys/pending/more.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500133 toys/pending/route.c \
134 toys/pending/tar.c \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500135 toys/pending/tr.c \
136 toys/pending/traceroute.c \
137 toys/posix/basename.c \
138 toys/posix/cal.c \
139 toys/posix/cat.c \
140 toys/posix/chgrp.c \
141 toys/posix/chmod.c \
142 toys/posix/cksum.c \
143 toys/posix/cmp.c \
144 toys/posix/comm.c \
145 toys/posix/cp.c \
146 toys/posix/cpio.c \
147 toys/posix/cut.c \
148 toys/posix/date.c \
149 toys/posix/df.c \
150 toys/posix/dirname.c \
151 toys/posix/du.c \
152 toys/posix/echo.c \
153 toys/posix/env.c \
154 toys/posix/expand.c \
155 toys/posix/false.c \
156 toys/posix/find.c \
157 toys/posix/grep.c \
158 toys/posix/head.c \
159 toys/posix/id.c \
160 toys/posix/kill.c \
161 toys/posix/ln.c \
162 toys/posix/ls.c \
163 toys/posix/mkdir.c \
164 toys/posix/mkfifo.c \
165 toys/posix/nice.c \
166 toys/posix/nl.c \
167 toys/posix/nohup.c \
168 toys/posix/od.c \
169 toys/posix/paste.c \
170 toys/posix/patch.c \
171 toys/posix/printf.c \
172 toys/posix/pwd.c \
173 toys/posix/renice.c \
174 toys/posix/rm.c \
175 toys/posix/rmdir.c \
176 toys/posix/sed.c \
177 toys/posix/sleep.c \
178 toys/posix/sort.c \
179 toys/posix/split.c \
180 toys/posix/strings.c \
181 toys/posix/tail.c \
182 toys/posix/tee.c \
183 toys/posix/time.c \
184 toys/posix/touch.c \
185 toys/posix/true.c \
186 toys/posix/tty.c \
187 toys/posix/uname.c \
188 toys/posix/uniq.c \
189 toys/posix/wc.c \
Hashcode57332152016-12-20 01:30:49 +0100190 toys/posix/xargs.c
191
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500192ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
193# there are some conflicts here with AOSP-7.[01] and CM-14.[01]
Hashcode57332152016-12-20 01:30:49 +0100194# the following items have been removed for compatibility
195# ifconfig, netcat, netstat, rfkill, switch_root
196LOCAL_STATIC_LIBRARIES := libcrypto_static
197
198LOCAL_C_INCLUDES += \
199 external/boringssl/include \
200 bionic/libc/dns/include
201
202LOCAL_SRC_FILES += \
203 lib/linestack.c \
204 lib/password.c \
205 toys/other/flock.c \
206 toys/other/hwclock.c \
207 toys/other/ionice.c \
208 toys/other/lspci.c \
209 toys/other/readahead.c \
210 toys/other/reset.c \
211 toys/other/uptime.c \
212 toys/other/xxd.c \
213 toys/pending/arp.c \
214 toys/pending/diff.c \
Hashcode57332152016-12-20 01:30:49 +0100215 toys/pending/lsof.c \
216 toys/pending/telnet.c \
217 toys/pending/test.c \
218 toys/pending/watch.c \
219 toys/pending/xzcat.c \
220 toys/posix/ps.c \
221 toys/posix/ulimit.c
222
Ethan Yonker95e80072017-08-24 21:45:50 -0500223ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
224# Android 8.0 had some tools in different paths
225LOCAL_SRC_FILES += \
226 toys/pending/dmesg.c \
227 toys/net/ftpget.c
228else
229LOCAL_SRC_FILES += \
230 toys/lsb/dmesg.c \
231 toys/pending/ftpget.c
232endif
233
Hashcode57332152016-12-20 01:30:49 +0100234# Account for master branch changes pulld into CM14.1
235ifneq ($(CM_BUILD),)
236LOCAL_SRC_FILES += \
237 toys/android/log.c \
238 toys/android/sendevent.c \
239 toys/android/start.c \
240 toys/net/ifconfig.c \
241 toys/net/netcat.c \
242 toys/net/netstat.c \
243 toys/net/rfkill.c \
244 toys/net/tunctl.c \
245 toys/other/setfattr.c \
246 toys/pending/chrt.c \
247 toys/pending/fdisk.c \
248 toys/pending/getfattr.c \
249 toys/pending/host.c \
250 toys/pending/resize.c \
251 toys/posix/file.c
252else
253LOCAL_SRC_FILES += \
Ethan Yonker95e80072017-08-24 21:45:50 -0500254 toys/other/switch_root.c
255ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
256# Android 8.0 had some tools in different paths
257LOCAL_SRC_FILES += \
258 toys/net/ifconfig.c \
259 toys/net/netcat.c \
260 toys/net/netstat.c \
261 toys/net/rfkill.c
262else
263LOCAL_SRC_FILES += \
Hashcode57332152016-12-20 01:30:49 +0100264 toys/other/ifconfig.c \
265 toys/other/netcat.c \
266 toys/other/rfkill.c \
Hashcode57332152016-12-20 01:30:49 +0100267 toys/pending/netstat.c
268endif
Ethan Yonker95e80072017-08-24 21:45:50 -0500269endif
Hashcode57332152016-12-20 01:30:49 +0100270else
271LOCAL_SRC_FILES += \
272 toys/other/ifconfig.c \
273 toys/other/netcat.c \
274 toys/other/rfkill.c \
275 toys/other/switch_root.c \
276 toys/pending/hwclock.c \
277 toys/pending/netstat.c \
278 toys/pending/pgrep.c \
279 toys/pending/top.c
280endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500281
282LOCAL_CFLAGS += \
283 -std=c99 \
284 -Os \
285 -Wno-char-subscripts \
286 -Wno-sign-compare \
287 -Wno-string-plus-int \
288 -Wno-uninitialized \
289 -Wno-unused-parameter \
290 -funsigned-char \
291 -ffunction-sections -fdata-sections \
292 -fno-asynchronous-unwind-tables \
293
294toybox_version := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null)-android
295LOCAL_CFLAGS += -DTOYBOX_VERSION='"$(toybox_version)"'
296
297LOCAL_CLANG := true
298
299LOCAL_SHARED_LIBRARIES := libcutils libselinux
300
301LOCAL_MODULE := toybox_recovery
302LOCAL_MODULE_STEM := toybox
303LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
304LOCAL_MODULE_TAGS := optional
305
306# dupes: dd df du ls mount renice
307# useless?: freeramdisk fsfreeze install makedevs mkfifo nbd-client
308# partprobe pivot_root pwdx rev rfkill switch_root tty vconfig
309# prefer BSD netcat instead?: nc netcat
310# prefer efs2progs instead?: blkid chattr lsattr
311
312ALL_TOOLS := \
313 acpi \
314 basename \
315 blkid \
316 blockdev \
317 bzcat \
318 cal \
319 cat \
320 chcon \
321 chgrp \
322 chmod \
323 chown \
324 chroot \
325 cksum \
326 clear \
327 comm \
328 cmp \
329 cp \
330 cpio \
331 cut \
332 date \
333 dirname \
334 dmesg \
335 dos2unix \
336 echo \
337 env \
338 expand \
339 expr \
340 fallocate \
341 false \
342 find \
343 free \
344 getenforce \
345 getprop \
346 groups \
347 head \
348 hostname \
349 hwclock \
350 id \
351 ifconfig \
352 inotifyd \
353 insmod \
354 kill \
355 load_policy \
356 ln \
357 logname \
358 losetup \
359 lsmod \
360 lsusb \
361 md5sum \
362 mkdir \
363 mknod \
364 mkswap \
365 mktemp \
366 modinfo \
367 more \
368 mountpoint \
369 mv \
370 netstat \
371 nice \
372 nl \
373 nohup \
374 od \
375 paste \
376 patch \
377 pgrep \
378 pidof \
379 pkill \
380 pmap \
381 printenv \
382 printf \
383 pwd \
384 readlink \
385 realpath \
386 restorecon \
387 rm \
388 rmdir \
389 rmmod \
390 route \
391 runcon \
392 sed \
393 seq \
394 setenforce \
395 setprop \
396 setsid \
397 sha1sum \
398 sleep \
399 sort \
400 split \
401 stat \
402 strings \
403 swapoff \
404 swapon \
405 sync \
406 sysctl \
407 tac \
408 tail \
409 tar \
410 taskset \
411 tee \
412 time \
413 timeout \
414 touch \
415 tr \
416 true \
417 truncate \
418 umount \
419 uname \
420 uniq \
421 unix2dos \
422 usleep \
423 vmstat \
424 wc \
425 which \
426 whoami \
427 xargs \
Hashcode57332152016-12-20 01:30:49 +0100428 yes
429
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500430ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Hashcode57332152016-12-20 01:30:49 +0100431ALL_TOOLS += \
432 arp \
433 base64 \
434 chattr \
435 dd \
436 df \
437 diff \
Hashcode57332152016-12-20 01:30:49 +0100438 egrep \
439 fgrep \
440 flock \
441 freeramdisk \
442 fsfreeze \
443 fstype \
444 ftpget \
445 ftpput \
446 grep \
447 help \
448 install \
449 ionice \
450 iorenice \
451 iotop \
452 killall \
453 ls \
454 lsattr \
455 lsof \
456 lspci \
457 makedevs \
458 mkfifo \
459 mount \
460 nbd-client \
461 nc \
462 netcat \
463 nproc \
464 partprobe \
465 pivot_root \
466 ps \
467 pwdx \
468 readahead \
469 renice \
470 reset \
471 rev \
472 rfkill \
473 sha224sum \
474 sha256sum \
475 sha384sum \
476 sha512sum \
477 telnet \
478 test \
479 top \
480 traceroute \
481 traceroute6 \
482 tty \
483 tunctl \
484 ulimit \
485 uptime \
486 vconfig \
487 watch \
488 xxd \
489 xzcat
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500490ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 24; echo $$?),0)
491ALL_TOOLS += \
492 du
493endif
Hashcode57332152016-12-20 01:30:49 +0100494# Account for master branch changes pulld into CM14.1
495ifneq ($(CM_BUILD),)
496ALL_TOOLS += \
497 chrt \
498 fdisk \
499 file \
500 getfattr \
501 host \
502 log \
503 resize \
504 setfattr
505endif
506endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500507
508# Install the symlinks.
509LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
510
511include $(BUILD_EXECUTABLE)
512
513# Make /sbin/toolbox launchers for each tool
514SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
515$(SYMLINKS): TOYBOX_BINARY := $(LOCAL_MODULE_STEM)
516$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
517 @echo "Symlink: $@ -> $(TOYBOX_BINARY)"
518 @mkdir -p $(dir $@)
519 @rm -rf $@
520 $(hide) ln -sf $(TOYBOX_BINARY) $@
521
522include $(CLEAR_VARS)
523LOCAL_MODULE := toybox_symlinks
524LOCAL_MODULE_TAGS := optional
525LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
526include $(BUILD_PHONY_PACKAGE)
527
528endif
529
530endif