├── .gitattributes
├── .gitignore
├── README.md
├── bash_patches
├── bashline.c.patch
├── config-top.h.patch
├── config.h.in.patch
├── fpurge.c.patch
├── parse.y.patch
├── pathnames.h.patch
├── rlconf.h.patch
├── tmpfile.c.patch
└── y.tab.c.patch
├── bc_libmath.h
├── build.sh
├── coreutils.patch
├── coreutils_modules
├── nano_wrapper
└── ndk_static_patches
├── coreutils.patch
├── diffutils.patch
├── findutils.patch
├── patch.patch
└── tar.patch
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Declare files that will always have LF line endings on checkout.
2 | * text eol=lf
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Deprecated - [See here for the new build script](https://github.com/Zackptg5/Cross-Compiled-Binaries-Android/tree/master/build_script)
2 |
3 |
4 | ## GNU Utils for Android Build Script ##
5 |
6 | This will build any of the following static GNU binaries:
7 | bash, bc (also includes dc), coreutils (has optional selinux support) (has openssl support) (includes advanced cp/mv - progress bar functionality), cpio, diffutils (includes cmp, diff, diff3, sdiff), ed, emacs, findutils (includes find, locate, updatedb, xargs), gawk (GNU awk), grep (also includes egrep and fgrep) (has full perl regex support), gzip (also includes gunzip and gzexe), ncurses (includes capconvert, clear, infocmp, tabs, tic, toe, tput, tset), patch, sed, tar
8 |
9 | ## Build instructions
10 |
11 | ```
12 | sudo apt install build-essential gcc-multilib libgnutls28-dev lzip # For debian/ubuntu based distributions - install equivalent dev tools and dependencies for yours
13 | ./build.bash --help # For more info on usage
14 | ```
15 |
16 | ## Note
17 |
18 | If mirrors.kernel.org is down, replace all instances of that in build script with ftp.gnu.org
19 |
20 | ## Compatibility
21 |
22 | The below table notes if the binary is compatible with android ndk, linaro, or gcc compilers. If static or dynamic is listed, then only that link method is working
23 |
24 | | | NDK? | Linaro? | GCC? |
25 | | --------- |:-------:|:-------:|:------:|
26 | | **bash** | *Static* | Yes | Yes |
27 | | **bc** | Yes | Yes | Yes |
28 | | **coreutils** | Yes | *Static* | *Static* |
29 | | **cpio** | Yes | Yes | Yes |
30 | | **diffutils** | Yes | Yes | Yes |
31 | | **ed** | Yes | No | No |
32 | | **findutils** | Yes | *Dynamic* | *Dynamic* |
33 | | **gawk** | Yes | Yes | Yes |
34 | | **grep** | Yes | Yes | Yes |
35 | | **gzip** | Yes | Yes | Yes |
36 | | **nano** | *Static* | No | No |
37 | | **ncurses** | Yes | Yes | Yes |
38 | | **patch** | Yes | Yes | Yes |
39 | | **sed** | Yes | Yes | Yes |
40 | | **tar** | Yes | Yes | Yes |
41 |
42 | * Pwcat and Grcat (part of gawk) seg fault when ndk is used, compile without it to use them
43 | * Haven't tested nano outside of NDK much at this point
44 | * Coreutils won't build with selinux with dynamic link - static only
45 |
46 | ## Dynamic link Issue
47 |
48 | If the binary wasn't compiled with NDK, it'll have library depenencies on non existent libraries. Some of these can be remedied with symlinks to it (for example: libc.so -> libc.so.6) but some can't because no version of it exists on android (like libreadline). In the case of libdl, even if symlink is made, it still doesn't work oddly.
49 |
50 | ## Credits
51 |
52 | * [GNU](https://www.gnu.org/software/)
53 |
54 | ### Credits for Bash and Patches
55 |
56 | * [Alexander Gromnitsky](https://github.com/gromnitsky/bash-on-android)
57 | * [Termux](https://github.com/termux/termux-packages/tree/master/packages/bash)
58 | * [ATechnoHazard and koro666](https://github.com/ATechnoHazard/bash_patches)
59 | * [BlissRoms](https://github.com/BlissRoms/platform_external_bash)
60 |
61 | ## License
62 |
63 | MIT
64 |
--------------------------------------------------------------------------------
/bash_patches/bashline.c.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/bashline.c Fri Aug 05 20:44:05 2016
2 | +++ bashline.c Fri Dec 14 13:15:36 2018
3 | @@ -2478,7 +2478,7 @@
4 | const char *text;
5 | int state;
6 | {
7 | -#if defined (__WIN32__) || defined (__OPENNT) || !defined (HAVE_GRP_H)
8 | +#if defined (__WIN32__) || defined (__OPENNT) || defined(__ANDROID__) || !defined (HAVE_GRP_H)
9 | return ((char *)NULL);
10 | #else
11 | static char *gname = (char *)NULL;
12 |
--------------------------------------------------------------------------------
/bash_patches/config-top.h.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/config-top.h Thu May 19 13:34:02 2016
2 | +++ config-top.h Fri Dec 14 09:21:39 2018
3 | @@ -62,9 +62,14 @@
4 |
5 | /* The default value of the PATH variable. */
6 | #ifndef DEFAULT_PATH_VALUE
7 | +#ifdef __ANDROID__
8 | +#define DEFAULT_PATH_VALUE \
9 | + "/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin"
10 | +#else
11 | #define DEFAULT_PATH_VALUE \
12 | "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
13 | #endif
14 | +#endif
15 |
16 | /* If you want to unconditionally set a value for PATH in every restricted
17 | shell, set this. */
18 | @@ -73,9 +78,14 @@
19 | /* The value for PATH when invoking `command -p'. This is only used when
20 | the Posix.2 confstr () function, or CS_PATH define are not present. */
21 | #ifndef STANDARD_UTILS_PATH
22 | +#ifdef __ANDROID__
23 | +#define STANDARD_UTILS_PATH \
24 | + "/system/bin"
25 | +#else
26 | #define STANDARD_UTILS_PATH \
27 | "/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc"
28 | #endif
29 | +#endif
30 |
31 | /* Default primary and secondary prompt strings. */
32 | #define PPROMPT "\\s-\\v\\$ "
33 | @@ -88,13 +98,21 @@
34 | #define KSH_COMPATIBLE_SELECT
35 |
36 | /* Default interactive shell startup file. */
37 | -#define DEFAULT_BASHRC "~/.bashrc"
38 | +#define DEFAULT_BASHRC "/system/etc/bash/bashrc"
39 |
40 | /* System-wide .bashrc file for interactive shells. */
41 | +#ifdef __ANDROID__
42 | +/* #define SYS_BASHRC "/system/etc/bash.bashrc" */
43 | +#else
44 | /* #define SYS_BASHRC "/etc/bash.bashrc" */
45 | +#endif
46 |
47 | /* System-wide .bash_logout for login shells. */
48 | +#ifdef __ANDROID__
49 | +/* #define SYS_BASH_LOGOUT "/system/etc/bash.bash_logout" */
50 | +#else
51 | /* #define SYS_BASH_LOGOUT "/etc/bash.bash_logout" */
52 | +#endif
53 |
54 | /* Define this to make non-interactive shells begun with argv[0][0] == '-'
55 | run the startup files when not in posix mode. */
56 |
--------------------------------------------------------------------------------
/bash_patches/config.h.in.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/config.h.in Sat Dec 15 01:13:30 2018
2 | +++ config.h.in Sat Dec 15 01:13:41 2018
3 | @@ -626,8 +626,10 @@
4 | /* Define if you have the getcwd function. */
5 | #undef HAVE_GETCWD
6 |
7 | +#ifndef __LP64__
8 | /* Define if you have the getdtablesize function. */
9 | -#undef HAVE_GETDTABLESIZE
10 | +#define HAVE_GETDTABLESIZE 1
11 | +#endif
12 |
13 | /* Define if you have the getgroups function. */
14 | #undef HAVE_GETGROUPS
15 |
--------------------------------------------------------------------------------
/bash_patches/fpurge.c.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/lib/sh/fpurge.c Wed Dec 22 09:32:58 2010
2 | +++ lib/sh/fpurge.c Fri Dec 14 10:08:03 2018
3 | @@ -31,7 +31,7 @@
4 | #endif
5 | extern int fpurge __P((FILE *stream));
6 |
7 | -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */
8 | +#if defined HAVE___FPURGE && defined HAVE_STDIO_EXT_H /* glibc >= 2.2, Haiku, Solaris >= 7 */
9 | # include
10 | #endif
11 | #include
12 |
--------------------------------------------------------------------------------
/bash_patches/parse.y.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/parse.y Sun Sep 11 10:31:46 2016
2 | +++ parse.y Fri Dec 14 10:03:10 2018
3 | @@ -35,6 +35,7 @@
4 | #endif
5 |
6 | #include
7 | +#include
8 | #include "chartypes.h"
9 | #include
10 |
--------------------------------------------------------------------------------
/bash_patches/pathnames.h.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/pathnames.h.in Sun Jan 04 14:32:40 2009
2 | +++ pathnames.h.in Fri Dec 14 09:59:38 2018
3 | @@ -22,10 +22,18 @@
4 | #define _PATHNAMES_H_
5 |
6 | /* The default file for hostname completion. */
7 | +#ifdef __ANDROID__
8 | +#define DEFAULT_HOSTS_FILE "/system/etc/hosts"
9 | +#else
10 | #define DEFAULT_HOSTS_FILE "/etc/hosts"
11 | +#endif
12 |
13 | /* The default login shell startup file. */
14 | +#ifdef __ANDROID__
15 | +#define SYS_PROFILE "/system/etc/profile"
16 | +#else
17 | #define SYS_PROFILE "/etc/profile"
18 | +#endif
19 |
20 | /* The default location of the bash debugger initialization/startup file. */
21 | #define DEBUGGER_START_FILE "@DEBUGGER_START_FILE@"
22 |
--------------------------------------------------------------------------------
/bash_patches/rlconf.h.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/lib/readline/rlconf.h Mon Jan 25 10:35:32 2016
2 | +++ lib/readline/rlconf.h Fri Dec 14 09:26:29 2018
3 | @@ -43,7 +43,11 @@
4 | #define DEFAULT_INPUTRC "~/.inputrc"
5 |
6 | /* The ultimate last-ditch filename for an init file -- system-wide. */
7 | +#ifdef __ANDROID__
8 | +#define SYS_INPUTRC "/system/etc/inputrc"
9 | +#else
10 | #define SYS_INPUTRC "/etc/inputrc"
11 | +#endif
12 |
13 | /* If defined, expand tabs to spaces. */
14 | #define DISPLAY_TABS
15 |
--------------------------------------------------------------------------------
/bash_patches/tmpfile.c.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/lib/sh/tmpfile.c Thu Aug 11 10:05:58 2016
2 | +++ lib/sh/tmpfile.c Fri Dec 14 09:29:04 2018
3 | @@ -74,6 +74,11 @@
4 | return sys_tmpdir;
5 | #endif
6 |
7 | +#ifdef __ANDROID__
8 | + sys_tmpdir = "/data/local/tmp";
9 | + if (file_iswdir (sys_tmpdir))
10 | + return sys_tmpdir;
11 | +#else
12 | sys_tmpdir = "/tmp";
13 | if (file_iswdir (sys_tmpdir))
14 | return sys_tmpdir;
15 | @@ -85,6 +90,7 @@
16 | sys_tmpdir = "/usr/tmp";
17 | if (file_iswdir (sys_tmpdir))
18 | return sys_tmpdir;
19 | +#endif
20 |
21 | sys_tmpdir = DEFAULT_TMPDIR;
22 |
23 |
--------------------------------------------------------------------------------
/bash_patches/y.tab.c.patch:
--------------------------------------------------------------------------------
1 | --- ../bash-5.0/y.tab.c Sun Sep 11 10:32:05 2016
2 | +++ y.tab.c Fri Dec 14 10:04:44 2018
3 | @@ -80,6 +80,7 @@
4 | #endif
5 |
6 | #include
7 | +#include
8 | #include "chartypes.h"
9 | #include
10 |
--------------------------------------------------------------------------------
/bc_libmath.h:
--------------------------------------------------------------------------------
1 | {"@iK20:s2:p@r",
2 | "@iF1,5.6,7,8,9,10,11,12,13,14,15[l0:KA:#Z1:l0:s7:pKA:s0:pl5:C1,0:",
3 | "s14:pl7:s0:pl14:RN1:l5:0Z4:l10:1+s10:pl5:K2:/s5:pl2:",
5 | "1+s2:pJ3:N4:l13:s2:p1l5:+s14:pl5:s6:p1s8:pK2:s11:pN6:1B7:J5:N8:",
6 | "l11:i11:pJ6:N7:l6:l5:*s6:l8:l11:*s8:/s9:pl9:0=Z9:l10:0>Z10:N11:",
7 | "l10:d10:Z12:l14:l14:*s14:pJ11:N12:N10:l15:s2:pl12:Z13:1l14:/R",
8 | "N13:l14:1/RN9:l14:l9:+s14:pJ8:N5:0R]@r",
9 | "@iF2,5.7,9,10,11,12,13,14,15[l0:KA:#Z1:l0:s7:pKA:s0:pl5:C2,0:",
10 | "s14:pl7:s0:pl14:RN1:l5:0{Z2:1K10:l2:^-1/RN2:l2:s15:pK6:l2:+s2:",
11 | "pK2:s10:p0s11:pN3:l5:K2:}Z4:l10:K2:*s10:pl5:cRs5:pJ3:N4:N5:l5:",
12 | "K.5:{Z6:l10:K2:*s10:pl5:cRs5:pJ5:N6:l5:1-l5:1+/s13:s14:pl13:l13:",
13 | "*s12:pK3:s11:pN8:1B9:J7:N10:l11:K2:+s11:pJ8:N9:l13:l12:*s13:l11:",
14 | "/s9:pl9:0=Z11:l10:l14:*s14:pl15:s2:pl14:1/RN11:l14:l9:+s14:pJ10:N7:",
15 | "0R]@r",
16 | "@iF3,5.7,9,11,12,13,16,14,15[l0:KA:#Z1:l0:s7:pKA:s0:pl5:C3,0:",
17 | "s14:pl7:s0:pl14:RN1:l2:s15:pK1.1:l15:*K2:+s2:p1C4,0:s14:pl5:0",
18 | "Z11:l15:K5:+s2:pK.2:C4,0:s6:pN11:",
35 | "l15:K3:+s2:pN12:l5:K.2:>Z13:l10:1+s10:pl5:K.2:-1l5:K.2:*+/s5:",
36 | "pJ12:N13:l5:s13:s14:pl5:nl5:*s16:pK3:s11:pN15:1B16:J14:N17:l11:",
37 | "K2:+s11:pJ15:N16:l13:l16:*s13:l11:/s9:pl9:0=Z18:l15:s2:pl10:l6:",
38 | "*l14:+l12:/RN18:l14:l9:+s14:pJ17:N14:0R]@r",
39 | "@iF6,13,5.6,7,8,9,10,11,12,16,14,15[l0:KA:#Z1:l0:s7:pKA:s0:pl13:",
40 | "l5:C6,00:s14:pl7:s0:pl14:RN1:l2:s15:p0s2:pl13:1/s13:pl13:0/dev/null
35 | if [ -f "bash$PVER-$i" ]; then
36 | patch -p0 -i bash$PVER-$i
37 | rm -f bash$PVER-$i
38 | else
39 | break
40 | fi
41 | done
42 | for i in $DIR/bash_patches/*; do
43 | local PFILE=$(basename $i)
44 | cp -f $i $PFILE
45 | sed -i "s/4.4/$VER/g" $PFILE
46 | patch -p0 -i $PFILE
47 | [ $? -ne 0 ] && { echored "Patching failed!"; return 1; }
48 | rm -f $PFILE
49 | done
50 | }
51 | build_zlib() {
52 | export ZPREFIX="$(echo $PREFIX | sed "s|$LBIN|zlib|")"
53 | [ -d $ZPREFIX ] && return 0
54 | cd $DIR
55 | echogreen "Building ZLib..."
56 | [ -f "zlib-$ZVER.tar.gz" ] || wget http://zlib.net/zlib-$ZVER.tar.gz
57 | [ -d zlib-$ZVER ] || tar -xf zlib-$ZVER.tar.gz
58 | cd zlib-$ZVER
59 | [ "$1" == "static" ] && ./configure --prefix=$ZPREFIX --static || ./configure --prefix=$ZPREFIX
60 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
61 | make -j$JOBS
62 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
63 | make install
64 | make clean
65 | cd $DIR/$LBIN-$VER
66 | }
67 | build_bzip2() {
68 | export BPREFIX="$(echo $PREFIX | sed "s|$LBIN|bzip2|")"
69 | [ -d $BPREFIX ] && return 0
70 | cd $DIR
71 | echogreen "Building BZip2..."
72 | [ -f "bzip2-latest.tar.gz" ] || wget https://www.sourceware.org/pub/bzip2/bzip2-latest.tar.gz
73 | [[ -d "bzip2-"[0-9]* ]] || tar -xf bzip2-latest.tar.gz
74 | cd bzip2-[0-9]*
75 | sed -i -e '/# To assist in cross-compiling/,/LDFLAGS=/d' -e "s/CFLAGS=/CFLAGS=$CFLAGS /" -e "s|^PREFIX=.*|PREFIX=$BPREFIX|" -e 's/bzip2recover test/bzip2recover/' Makefile
76 | make install -j$JOBS LDFLAGS="$LDFLAGS"
77 | [ $? -eq 0 ] || { echored "Bzip2 build failed!"; exit 1; }
78 | make clean
79 | $STRIP $BPREFIX/bin/bunzip2 $BPREFIX/bin/bzcat $BPREFIX/bin/bzip2 $BPREFIX/bin/bzip2recover
80 | cd $DIR/$LBIN-$VER
81 | }
82 | build_pcre() {
83 | build_zlib
84 | build_bzip2
85 | export PPREFIX="$(echo $PREFIX | sed "s|$LBIN|pcre|")"
86 | [ -d $PPREFIX ] && return 0
87 | cd $DIR
88 | rm -rf pcre-$PVER 2>/dev/null
89 | echogreen "Building PCRE..."
90 | [ -f "pcre-$PVER.tar.bz2" ] || wget https://ftp.pcre.org/pub/pcre/pcre-$PVER.tar.bz2
91 | [ -d pcre-$PVER ] || tar -xf pcre-$PVER.tar.bz2
92 | cd pcre-$PVER
93 | $STATIC && local FLAGS="$FLAGS--disable-shared "
94 | ./configure $FLAGS--prefix= --enable-unicode-properties --enable-jit --enable-pcre16 --enable-pcre32 --enable-pcregrep-libz --enable-pcregrep-libbz2 --host=$target_host CFLAGS="$CFLAGS -I$ZPREFIX/include -I$BPREFIX/include" LDFLAGS="$LDFLAGS -L$ZPREFIX/lib -L$BPREFIX/lib"
95 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
96 | make -j$JOBS
97 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
98 | make install -j$JOBS DESTDIR=$PPREFIX
99 | make clean
100 | cd $DIR/$LBIN-$VER
101 | }
102 | build_ncursesw() {
103 | export NPREFIX="$(echo $PREFIX | sed "s|$LBIN|ncursesw|")"
104 | [ -d $NPREFIX ] && return 0
105 | cd $DIR
106 | echogreen "Building NCurses wide..."
107 | [ -f "ncursesw-$NVER.tar.gz" ] || wget -O ncursesw-$NVER.tar.gz http://mirrors.kernel.org/gnu/ncurses/ncurses-$NVER.tar.gz
108 | [ -d ncursesw-$NVER ] || { mkdir ncursesw-$NVER; tar -xf ncursesw-$NVER.tar.gz --transform s/ncurses-$NVER/ncursesw-$NVER/; }
109 | cd ncursesw-$NVER
110 | ./configure $FLAGS--prefix=$NPREFIX --enable-widec --disable-nls --disable-stripping --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
111 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
112 | make -j$JOBS
113 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
114 | make install
115 | make clean
116 | cd $DIR/$LBIN-$VER
117 | }
118 | build_openssl() {
119 | build_zlib
120 | export OPREFIX="$(echo $PREFIX | sed "s|$LBIN|openssl|")"
121 | [ -d $OPREFIX ] && return 0
122 | cd $DIR
123 | echogreen "Building Openssl..."
124 | [ -d openssl ] && cd openssl || { git clone https://github.com/openssl/openssl; cd openssl; git checkout OpenSSL_$OVER; }
125 | if $STATIC; then
126 | sed -i "/#if \!defined(_WIN32)/,/#endif/d" fuzz/client.c
127 | sed -i "/#if \!defined(_WIN32)/,/#endif/d" fuzz/server.c
128 | local FLAGS=" no-shared zlib $FLAGS"
129 | else
130 | local FLAGS=" shared zlib-dynamic $FLAGS"
131 | fi
132 | ./Configure $OSARCH$FLAGS \
133 | -D__ANDROID_API__=$LAPI \
134 | --prefix=$OPREFIX \
135 | --with-zlib-include=$ZPREFIX/include \
136 | --with-zlib-lib=$ZPREFIX/lib
137 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
138 | make -j$JOBS
139 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
140 | make install_sw
141 | make distclean
142 | cd $DIR/$LBIN-$VER
143 | }
144 | build_pcre2() {
145 | build_zlib
146 | build_bzip2
147 | export P2PREFIX="$(echo $PREFIX | sed "s|$LBIN|pcre2|")"
148 | [ -d $P2PREFIX ] && return 0
149 | cd $DIR
150 | rm -rf pcre2-$P2VER 2>/dev/null
151 | echogreen "Building PCRE2..."
152 | [ -f "pcre2-$P2VER.tar.gz" ] || wget https://ftp.pcre.org/pub/pcre/pcre2-$P2VER.tar.gz
153 | [ -d pcre2-$P2VER ] || tar -xf pcre2-$P2VER.tar.gz
154 | cd pcre2-$P2VER
155 | ./configure $FLAGS--prefix= --enable-jit --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-fuzz-support --host=$target_host CFLAGS="-O2 -fPIE -fPIC -I$ZPREFIX/include -I$BPREFIX/include" LDFLAGS="-O2 -s -L$ZPREFIX/lib -L$BPREFIX/lib"
156 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
157 | make install -j$JOBS DESTDIR=$P2PREFIX
158 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
159 | make clean
160 | cd $DIR/$LBIN-$VER
161 | }
162 | build_selinux() {
163 | build_pcre2
164 | export SPREFIX="$(echo $PREFIX | sed "s|$LBIN|selinux|")"
165 | [ -d $SPREFIX ] && return 0
166 | cd $DIR
167 | rm -rf selinux
168 | git clone https://github.com/SELinuxProject/selinux.git selinux
169 | cd selinux
170 | sed -i "s/libsemanage .*//" Makefile # Only need libsepol and libselinux
171 | sed -i "s/^USE_PCRE2 ?= n/USE_PCRE2 ?= y/" libselinux/Makefile # Force pcre2 - it doesn't do this for some reason
172 | sed -i "s/ \&\& strverscmp(uts.release, \"2.6.30\") < 0//" libselinux/src/selinux_restorecon.c # This seemingly isn't in ndk
173 | cp -rf libsepol/cil/include/cil libsepol/include/sepol/
174 | make install DESTDIR=$SPREFIX PREFIX= -j$JOBS \
175 | CFLAGS="-O2 -fPIE -I$P2PREFIX/include -I$DIR/selinux/libsepol/include \
176 | -DNO_PERSISTENTLY_STORED_PATTERNS -D_GNU_SOURCE -DUSE_PCRE2 -DANDROID_HOST" \
177 | LDFLAGS="-O2 -s -L$P2PREFIX/lib -L$DIR/selinux/libsepol/src -lpcre2-8"
178 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
179 | mv -f $SPREFIX/sbin/* $SPREFIX/bin && rm -rf $SPREFIX/sbin
180 | cd $DIR/$LBIN-$VER
181 | }
182 | build_libmagic() {
183 | $STATIC && build_zlib static || build_zlib
184 | build_bzip2
185 | export MPREFIX="$(echo $PREFIX | sed "s|$LBIN|libmagic|")"
186 | [ -d $MPREFIX ] && return 0
187 | cd $DIR
188 | echogreen "Building libmagic..."
189 | [ -f "file-$MVER.tar.gz" ] || wget -O file-$MVER.tar.gz ftp://ftp.astron.com/pub/file/file-$MVER.tar.gz
190 | [ -d file-$MVER ] || { mkdir file-$MVER; tar -xf file-$MVER.tar.gz; }
191 | cd file-$MVER
192 | $STATIC && local FLAGS="--disable-shared $FLAGS"
193 | ./configure $FLAGS--prefix=$MPREFIX --disable-xzlib --host=$target_host --target=$target_host CFLAGS="$CFLAGS -I$ZPREFIX/include -I$BPREFIX/include" LDFLAGS="$LDFLAGS -Wl,--unresolved-symbols=ignore-all -L$ZPREFIX/lib -L$BPREFIX/lib" # Ignore errors about zlib and bzip2
194 | [ $? -eq 0 ] || { echored "Configure failed!"; exit 1; }
195 | sed -i "s|^FILE_COMPILE =.*|FILE_COMPILE = $(which file)|" magic/Makefile # Need to use host file binary
196 | make -j$JOBS
197 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
198 | make install
199 | make clean
200 | cd $DIR/$LBIN-$VER
201 | }
202 |
203 | TEXTRESET=$(tput sgr0)
204 | TEXTGREEN=$(tput setaf 2)
205 | TEXTRED=$(tput setaf 1)
206 | DIR=$PWD
207 | NDKVER=r21d
208 | STATIC=true
209 | SEP=false
210 | SELINUX=true
211 | export OPATH=$PATH
212 | OIFS=$IFS; IFS=\|;
213 | while true; do
214 | case "$1" in
215 | -h|--help) usage;;
216 | "") shift; break;;
217 | API=*|STATIC=*|BIN=*|ARCH=*|SEP=*|SELINUX=*) eval $(echo "$1" | sed -e 's/=/="/' -e 's/$/"/' -e 's/,/ /g'); shift;;
218 | *) echored "Invalid option: $1!"; usage;;
219 | esac
220 | done
221 | IFS=$OIFS
222 | [ -z "$ARCH" -o "$ARCH" == "all" ] && ARCH="arm arm64 x86 x64"
223 | [ -z "$BIN" -o "$BIN" == "all" ] && BIN="bash bc coreutils cpio diffutils ed findutils gawk grep gzip ncurses patch sed tar"
224 |
225 | case $API in
226 | 21|22|23|24|26|27|28|29|30) ;;
227 | *) API=21;;
228 | esac
229 |
230 | if [ -f /proc/cpuinfo ]; then
231 | JOBS=$(grep flags /proc/cpuinfo | wc -l)
232 | elif [ ! -z $(which sysctl) ]; then
233 | JOBS=$(sysctl -n hw.ncpu)
234 | else
235 | JOBS=2
236 | fi
237 |
238 | # Set up Android NDK
239 | echogreen "Fetching Android NDK $NDKVER"
240 | [ -f "android-ndk-$NDKVER-linux-x86_64.zip" ] || wget https://dl.google.com/android/repository/android-ndk-$NDKVER-linux-x86_64.zip
241 | [ -d "android-ndk-$NDKVER" ] || unzip -qo android-ndk-$NDKVER-linux-x86_64.zip
242 | export ANDROID_NDK_HOME=$DIR/android-ndk-$NDKVER
243 | export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
244 | export ANDROID_TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin
245 |
246 | for LBIN in $BIN; do
247 | NDK=true
248 | # Versioning and overrides
249 | LAPI=$API
250 | MVER=5.39
251 | NVER=6.2
252 | OVER=1_1_1g
253 | PVER=8.44
254 | P2VER=10.35
255 | ZVER=1.2.11
256 | case $LBIN in
257 | "bash") EXT=gz; VER=5.1; $STATIC || NDK=false;;
258 | "bc") EXT=gz; VER=1.07.1;;
259 | "coreutils") EXT=xz; VER=8.32; $SELINUX && { [ $LAPI -lt 28 ] && LAPI=28; } || { [ $LAPI -lt 23 ] && LAPI=23; };;
260 | "cpio") EXT=gz; VER=2.12;;
261 | "diffutils") EXT=xz; VER=3.7;;
262 | "ed") EXT=lz; VER=1.16;;
263 | "findutils") EXT=xz; VER=4.7.0; [ $LAPI -lt 23 ] && LAPI=23;;
264 | "gawk") EXT=xz; VER=5.1.0; $STATIC || { [ $LAPI -lt 26 ] && LAPI=26; };;
265 | "grep") EXT=xz; VER=3.6; [ $LAPI -lt 23 ] && LAPI=23;;
266 | "gzip") EXT=xz; VER=1.10;;
267 | "nano") EXT=xz; VER=5.4;;
268 | "ncurses") EXT=gz; VER=$NVER;;
269 | "patch") EXT=xz; VER=2.7.6;;
270 | "sed") EXT=xz; VER=4.8; [ $LAPI -lt 23 ] && LAPI=23;;
271 | "tar") EXT=xz; VER=1.32; ! $STATIC && [ $LAPI -lt 28 ] && LAPI=28;;
272 | *) echored "Invalid binary specified!"; usage;;
273 | esac
274 |
275 | [[ $(wget -S --spider http://mirrors.kernel.org/gnu/$LBIN/$LBIN-$VER.tar.$EXT 2>&1 | grep 'HTTP/1.1 200 OK') ]] || { echored "Invalid $LBIN VER! Check this: http://mirrors.kernel.org/gnu/$LBIN for valid versions!"; exit 1; }
276 |
277 | # Setup
278 | echogreen "Fetching $LBIN $VER"
279 | rm -rf $LBIN-$VER
280 | [ -f "$LBIN-$VER.tar.$EXT" ] || wget http://mirrors.kernel.org/gnu/$LBIN/$LBIN-$VER.tar.$EXT
281 | tar -xf $LBIN-$VER.tar.$EXT
282 |
283 | for LARCH in $ARCH; do
284 | # Setup toolchain
285 | case $LARCH in
286 | arm64|aarch64) LINKER=linker64; LARCH=aarch64; OSARCH=android-arm64; $NDK && target_host=aarch64-linux-android || { target_host=aarch64-linux-gnu; LINARO=true; };;
287 | arm) LINKER=linker; LARCH=arm; OSARCH=android-arm; $NDK && target_host=arm-linux-androideabi || { target_host=arm-linux-gnueabi; LINARO=true; };;
288 | x64|x86_64) LINKER=linker64; LARCH=x86_64; LINARO=false; OSARCH=android-x86_64; $NDK && target_host=x86_64-linux-android || target_host=x86_64-linux-gnu;;
289 | x86|i686) LINKER=linker; LARCH=i686; LINARO=false; OSARCH=android-x86; $NDK && target_host=i686-linux-android || target_host=i686-linux-gnu;;
290 | *) echored "Invalid ARCH entered!"; usage;;
291 | esac
292 | export PATH=$OPATH
293 | unset AR AS LD RANLIB STRIP CC CXX GCC GXX
294 | if $NDK || $LINARO; then
295 | export AR=$target_host-ar
296 | export AS=$target_host-as
297 | export LD=$target_host-ld
298 | export RANLIB=$target_host-ranlib
299 | export STRIP=$target_host-strip
300 | if $NDK; then
301 | export CC=$target_host-clang
302 | export GCC=$target_host-gcc
303 | export CXX=$target_host-clang++
304 | export GXX=$target_host-g++
305 | export PATH=$ANDROID_TOOLCHAIN:$PATH
306 | [ "$LARCH" == "arm" ] && target_host=armv7a-linux-androideabi
307 | # Create sometimes needed symlinks
308 | ln -sf $ANDROID_TOOLCHAIN/$target_host$LAPI-clang $ANDROID_TOOLCHAIN/$CC
309 | ln -sf $ANDROID_TOOLCHAIN/$target_host$LAPI-clang++ $ANDROID_TOOLCHAIN/$CXX
310 | ln -sf $ANDROID_TOOLCHAIN/$target_host$LAPI-clang $ANDROID_TOOLCHAIN/$GCC
311 | ln -sf $ANDROID_TOOLCHAIN/$target_host$LAPI-clang++ $ANDROID_TOOLCHAIN/$GXX
312 | [ "$LARCH" == "arm" ] && target_host=arm-linux-androideabi
313 | elif $LINARO; then
314 | [ -f gcc-linaro-7.5.0-2019.12-x86_64_$target_host.tar.xz ] || { echogreen "Fetching Linaro gcc"; wget https://releases.linaro.org/components/toolchain/binaries/latest-7/$target_host/gcc-linaro-7.5.0-2019.12-x86_64_$target_host.tar.xz; }
315 | [ -d gcc-linaro-7.5.0-2019.12-x86_64_$target_host ] || { echogreen "Setting up Linaro gcc"; tar -xf gcc-linaro-7.5.0-2019.12-x86_64_$target_host.tar.xz; }
316 | export PATH=$PWD/gcc-linaro-7.5.0-2019.12-x86_64_$target_host/bin:$PATH
317 | export CC=$target_host-gcc
318 | export CXX=$target_host-g++
319 | fi
320 | fi
321 |
322 | rm -rf $LBIN-$VER 2>/dev/null
323 | tar -xf $LBIN-$VER.tar.$EXT
324 | unset FLAGS
325 | cd $DIR/$LBIN-$VER
326 |
327 | if $STATIC; then
328 | CFLAGS='-static -O3'
329 | LDFLAGS='-static'
330 | $NDK && [ -f $DIR/ndk_static_patches/$LBIN.patch ] && patch_file $DIR/ndk_static_patches/$LBIN.patch
331 | export PREFIX=$DIR/build-static/$LBIN/$LARCH
332 | else
333 | CFLAGS='-O2 -fPIE -fPIC'
334 | LDFLAGS='-s -pie'
335 | $NDK || LDFLAGS="$LDFLAGS -Wl,-dynamic-linker,/system/bin/$LINKER"
336 | export PREFIX=$DIR/build-dynamic/$LBIN/$LARCH
337 | fi
338 | if ! $NDK; then
339 | case $LARCH in
340 | "arm") CFLAGS="$CFLAGS -mfloat-abi=softfp -mthumb"; LDFLAGS="$LDFLAGS -march=armv7-a -Wl,--fix-cortex-a8";;
341 | "i686") CFLAGS="$CFLAGS -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32";;
342 | "x86_64") CFLAGS="$CFLAGS -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel";;
343 | esac
344 | elif [ "$LARCH" == "i686" ]; then
345 | FLAGS="TIME_T_32_BIT_OK=yes "
346 | fi
347 |
348 | # Fixes:
349 | # 1) mktime_internal build error for non-ndk arm/64 cross-compile
350 | # 2) %n issue due to these binaries using old gnulib (This was in Jan 2019: http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=6c0f109fb98501fc8d65ea2c83501b45a80b00ab)
351 | # 3) minus_zero duplication error in NDK
352 | # 4) Bionic error fix in NDK
353 | # 5) Sort and timeout binaries have what appears to be seccomp problems and so don't work when compiled without ndk
354 | # 6) New syscall function has been added in coreutils 8.32 - won't compile with android toolchains - fix only needed for 64bit arch's oddly enough
355 | # 7) Coreutils doesn't detect pcre2 related functions for whatever reason - ignore resulting errors - must happen for coreutils only (after gnulib)
356 | echogreen "Configuring for $LARCH"
357 | case $LBIN in
358 | "bash")
359 | $STATIC && { FLAGS="$FLAGS--enable-static-link "; sed -i 's/-rdynamic//g' configure; sed -i 's/-rdynamic//g' configure.ac; }
360 | bash_patches || exit 1
361 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --without-bash-malloc bash_cv_dev_fd=whacky bash_cv_getcwd_malloc=yes --enable-largefile --enable-alias --enable-history --enable-readline --enable-multibyte --enable-job-control --enable-array-variables --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
362 | ;;
363 | "bc")
364 | ./configure $FLAGS--prefix=$PREFIX --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
365 | sed -i -e '\|./fbc -c|d' -e 's|$(srcdir)/fix-libmath_h|cp -f ../../bc_libmath.h $(srcdir)/libmath.h|' bc/Makefile
366 | ;;
367 | "coreutils")
368 | build_openssl
369 | build_selinux
370 | patch_file $DIR/coreutils.patch
371 | if ! $SEP; then
372 | FLAGS="$FLAGS--enable-single-binary=symlinks "
373 | $NDK || FLAGS="$FLAGS--enable-single-binary-exceptions=sort,timeout " #5
374 | fi
375 | sed -i 's/#ifdef __linux__/#ifndef __linux__/g' src/ls.c #6
376 | if $NDK; then
377 | sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" lib/cdefs.h #4
378 | sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" lib/stdio.in.h #4
379 | sed -i -e '/if (!num && negative)/d' -e "/return minus_zero/d" -e "/DOUBLE minus_zero = -0.0/d" lib/strtod.c #3
380 | if $SELINUX; then
381 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --with-openssl=yes --with-linux-crypto --enable-no-install-program=stdbuf --host=$target_host --target=$target_host CFLAGS="$CFLAGS -I$OPREFIX/include -I$P2PREFIX/include -I$SPREFIX/include" LDFLAGS="$LDFLAGS -L$OPREFIX/lib -L$P2PREFIX/lib -L$SPREFIX/lib" || { echored "Configure failed!"; exit 1; }
382 | else
383 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --with-openssl=yes --with-linux-crypto --enable-no-install-program=stdbuf --host=$target_host --target=$target_host CFLAGS="$CFLAGS -I$OPREFIX/include" LDFLAGS="$LDFLAGS -L$OPREFIX/lib" || { echored "Configure failed!"; exit 1; }
384 | fi
385 | else
386 | sed -i -e '/WANT_MKTIME_INTERNAL=0/i\WANT_MKTIME_INTERNAL=1\n$as_echo "#define NEED_MKTIME_INTERNAL 1" >>confdefs.h' -e '/^ *WANT_MKTIME_INTERNAL=0/,/^ *fi/d' configure #1
387 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --enable-no-install-program=stdbuf --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
388 | fi
389 | $SELINUX && [ ! "$(grep "^LDFLAGS += -Wl,--unresolved-symbols=ignore-in-object-files" src/local.mk)" ] && sed -i "1iLDFLAGS += -Wl,--unresolved-symbols=ignore-in-object-files" src/local.mk #7
390 | # sed -ri "/^LDFLAGS \+= -Wl,--warn-unresolved-symbol|^LDFLAGS \+= -Wl,--unresolved-symbols=ignore-all/d" src/local.mk
391 | # if $SELINUX; then
392 | # case $LARCH in
393 | # *64) sed -i "1iLDFLAGS += -Wl,--warn-unresolved-symbol" src/local.mk;;
394 | # *) sed -i "1iLDFLAGS += -Wl,--unresolved-symbols=ignore-all" src/local.mk;;
395 | # esac
396 | # fi
397 | [ ! "$(grep "#define HAVE_MKFIFO 1" lib/config.h)" ] && echo "#define HAVE_MKFIFO 1" >> lib/config.h
398 | ;;
399 | "cpio")
400 | sed -i 's/!defined __UCLIBC__)/!defined __UCLIBC__) || defined __ANDROID__/' gnu/vasnprintf.c #2
401 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
402 | ;;
403 | "diffutils")
404 | $NDK || sed -i -e '/WANT_MKTIME_INTERNAL=0/i\WANT_MKTIME_INTERNAL=1\n$as_echo "#define NEED_MKTIME_INTERNAL 1" >>confdefs.h' -e '/^ *WANT_MKTIME_INTERNAL=0/,/^ *fi/d' configure #1
405 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
406 | ;;
407 | "ed")
408 | ./configure $FLAGS--prefix=$PREFIX CC=$GCC CXX=$GXX CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
409 | ;;
410 | "findutils")
411 | $NDK || sed -i -e '/WANT_MKTIME_INTERNAL=0/i\WANT_MKTIME_INTERNAL=1\n$as_echo "#define NEED_MKTIME_INTERNAL 1" >>confdefs.h' -e '/^ *WANT_MKTIME_INTERNAL=0/,/^ *fi/d' configure #1
412 | ./configure $FLAGS--disable-nls --prefix=/system --sbindir=/system/bin --libexecdir=/system/bin --datarootdir=/system/usr/share --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
413 | $STATIC || sed -i -e "/#ifndef HAVE_ENDGRENT/,/#endif/d" -e "/#ifndef HAVE_ENDPWENT/,/#endif/d" -e "/endpwent/d" -e "/endgrent/d" find/parser.c
414 | ;;
415 | "gawk")
416 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
417 | ;;
418 | "grep")
419 | build_pcre
420 | ./configure $FLAGS--prefix=$PREFIX --enable-perl-regexp --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS -I$PPREFIX/include" LDFLAGS="$LDFLAGS -L$PPREFIX/lib" || { echored "Configure failed!"; exit 1; }
421 | ;;
422 | "gzip")
423 | sed -i 's/!defined __UCLIBC__)/!defined __UCLIBC__) || defined __ANDROID__/' lib/vasnprintf.c #2
424 | ./configure $FLAGS--prefix=$PREFIX --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
425 | ;;
426 | "nano")
427 | build_ncursesw
428 | mkdir -p $PREFIX/system/usr/share
429 | cp -rf $NPREFIX/share/terminfo $PREFIX/system/usr/share
430 | build_libmagic
431 | # Workaround no longer needed
432 | # wget -O - "https://kernel.googlesource.com/pub/scm/fs/ext2/xfstests-bld/+/refs/heads/master/android-compat/getpwent.c?format=TEXT" | base64 --decode > src/getpwent.c
433 | # wget -O src/pty.c https://raw.githubusercontent.com/CyanogenMod/android_external_busybox/cm-13.0/android/libc/pty.c
434 | # sed -i 's|int ptsname_r|//hack int ptsname_r(int fd, char* buf, size_t len) {\nint bb_ptsname_r|' src/pty.c
435 | # sed -i "/#include \"nano.h\"/a#define ptsname_r bb_ptsname_r\n//#define ttyname bb_ttyname\n#define ttyname_r bb_ttyname_r" src/proto.h
436 | ./configure $FLAGS--disable-nls --prefix=/system --sbindir=/system/bin --libexecdir=/system/bin --datarootdir=/system/usr/share --host=$target_host --target=$target_host CFLAGS="$CFLAGS -I$ZPREFIX/include -I$BPREFIX/include -I$NPREFIX/include -I$MPREFIX/include" LDFLAGS="$LDFLAGS -L$ZPREFIX/lib -L$BPREFIX/lib -L$NPREFIX/lib -L$MPREFIX/lib" || { echored "Configure failed!"; exit 1; }
437 | sed -i "/#ifdef USE_SLANG/i#define HAVE_NCURSESW_NCURSES_H" src/definitions.h # Was src/nano.h in nano v4.9
438 | cp -rf $NPREFIX/include/ncursesw $NPREFIX/lib/libncursesw.a $MPREFIX/include/* $MPREFIX/lib/* src/
439 | ;;
440 | "ncurses")
441 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --disable-stripping --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
442 | ;;
443 | "patch")
444 | $NDK || sed -i -e '/WANT_MKTIME_INTERNAL=0/i\WANT_MKTIME_INTERNAL=1\n$as_echo "#define NEED_MKTIME_INTERNAL 1" >>confdefs.h' -e '/^ *WANT_MKTIME_INTERNAL=0/,/^ *fi/d' configure #1
445 | ./configure $FLAGS--prefix=$PREFIX --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
446 | ;;
447 | "sed")
448 | $NDK && { sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" lib/cdefs.h; sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" lib/stdio.in.h; } #4
449 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
450 | ;;
451 | "tar")
452 | sed -i 's/!defined __UCLIBC__)/!defined __UCLIBC__) || defined __ANDROID__/' gnu/vasnprintf.c #2
453 | if $NDK; then
454 | sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" gnu/cdefs.h #4
455 | sed -i "s/USE_FORTIFY_LEVEL/BIONIC_FORTIFY/g" gnu/stdio.in.h #4
456 | else
457 | sed -i -e '/WANT_MKTIME_INTERNAL=0/i\WANT_MKTIME_INTERNAL=1\n$as_echo "#define NEED_MKTIME_INTERNAL 1" >>confdefs.h' -e '/^ *WANT_MKTIME_INTERNAL=0/,/^ *fi/d' configure #1
458 | fi
459 | ./configure $FLAGS--prefix=$PREFIX --disable-nls --host=$target_host --target=$target_host CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" || { echored "Configure failed!"; exit 1; }
460 | ;;
461 | esac
462 |
463 | [ "$LBIN" == "nano" ] && make -j$JOBS LIBS="libncursesw.a" || make -j$JOBS
464 | [ $? -eq 0 ] || { echored "Build failed!"; exit 1; }
465 |
466 | if [ "$LBIN" == "findutils" ]; then
467 | sed -i -e "s|/usr/bin|/system/bin|g" -e "s|SHELL=\".*\"|SHELL=\"/system/bin/sh\"|" locate/updatedb
468 | make install DESTDIR=$PREFIX
469 | mv -f $PREFIX/system/* $PREFIX
470 | rm -rf $PREFIX/sdcard $PREFIX/system
471 | elif [ "$LBIN" == "nano" ]; then
472 | make install DESTDIR=$PREFIX
473 | $STRIP $PREFIX/system/bin/nano
474 | mv -f $PREFIX/system/bin/nano $PREFIX/system/bin/nano.bin
475 | cp -f $DIR/nano_wrapper $PREFIX/system/bin/nano
476 | rm -rf $PREFIX/system/usr/share/nano
477 | git clone https://github.com/scopatz/nanorc $PREFIX/system/usr/share/nano
478 | rm -rf $PREFIX/system/usr/share/nano/.* $PREFIX/system/usr/share/nano/AUTHORS.txt 2>/dev/null
479 | else
480 | make install
481 | fi
482 | echogreen "$LBIN built sucessfully and can be found at: $PREFIX"
483 | cd $DIR
484 | done
485 | done
--------------------------------------------------------------------------------
/coreutils.patch:
--------------------------------------------------------------------------------
1 | --- src/copy.c 2018-07-01 04:32:02.000000000 +0200
2 | +++ src/copy.c 2018-09-20 10:32:15.473398296 +0200
3 | @@ -129,6 +129,72 @@
4 | dev_t dev;
5 | };
6 |
7 | +struct progress_status {
8 | + int iCountDown;
9 | + char ** cProgressField;
10 | + struct timeval last_time;
11 | + int last_size, iBarLength;
12 | + struct stat src_open_sb;
13 | +};
14 | +
15 | +/* Begin progress Mod*/
16 | +static void file_progress_bar ( char * _cDest, int _iBarLength, long _lProgress, long _lTotal )
17 | +{
18 | + double dPercent = (double) _lProgress / (double) _lTotal * 100.f;
19 | + sprintf( _cDest + ( _iBarLength - 6), "%4.1f", dPercent );
20 | + _cDest[_iBarLength - 2] = ' ';
21 | +
22 | + int i;
23 | + for ( i=1; i<=_iBarLength - 9; i++)
24 | + {
25 | + if ( dPercent > (double) (i-1) / (_iBarLength - 10) * 100.f )
26 | + {
27 | + _cDest[i] = '=';
28 | + }
29 | + else
30 | + {
31 | + _cDest[i] = ' ';
32 | + }
33 | + }
34 | + for ( i=1; i<_iBarLength - 9; i++)
35 | + {
36 | + if ( ( _cDest[i+1] == ' ' ) && ( _cDest[i] == '=' ) )
37 | + _cDest[i] = '>' ;
38 | + }
39 | +}
40 | +
41 | +int file_size_format ( char * _cDst, long _lSize, int _iCounter )
42 | +{
43 | + int iCounter = _iCounter;
44 | + double dSize = ( double ) _lSize;
45 | + while ( dSize >= 1000. )
46 | + {
47 | + dSize /= 1024.;
48 | + iCounter++;
49 | + }
50 | +
51 | + /* get unit */
52 | + char * sUnit;
53 | + if ( iCounter == 0 )
54 | + sUnit = "B";
55 | + else if ( iCounter == 1 )
56 | + sUnit = "KiB";
57 | + else if ( iCounter == 2 )
58 | + sUnit = "MiB";
59 | + else if ( iCounter == 3 )
60 | + sUnit = "GiB";
61 | + else if ( iCounter == 4 )
62 | + sUnit = "TiB";
63 | + else
64 | + sUnit = "N/A";
65 | +
66 | + /* write number */
67 | + return sprintf ( _cDst, "%5.1f %s", dSize, sUnit );
68 | +}
69 | +/* END progress mod */
70 | +
71 | +
72 | +
73 | /* Initial size of the cp.dest_info hash table. */
74 | #define DEST_INFO_INITIAL_CAPACITY 61
75 |
76 | @@ -225,7 +291,8 @@
77 | size_t hole_size, bool punch_holes,
78 | char const *src_name, char const *dst_name,
79 | uintmax_t max_n_read, off_t *total_n_read,
80 | - bool *last_write_made_hole)
81 | + bool *last_write_made_hole,
82 | + struct progress_status *s_progress)
83 | {
84 | *last_write_made_hole = false;
85 | *total_n_read = 0;
86 | @@ -234,6 +301,83 @@
87 |
88 | while (max_n_read)
89 | {
90 | +
91 | + if (progress) {
92 | + /* BEGIN progress mod */
93 | + /* update countdown */
94 | + s_progress->iCountDown--;
95 | + char * sProgressBar = s_progress->cProgressField[5];
96 | + if ( s_progress->iCountDown < 0 )
97 | + s_progress->iCountDown = 100;
98 | +
99 | + /* just print one line with the percentage, but not always */
100 | + if ( s_progress->iCountDown == 0 )
101 | + {
102 | + /* calculate current speed */
103 | + struct timeval cur_time;
104 | + gettimeofday ( & cur_time, NULL );
105 | + int cur_size = g_iTotalWritten + *total_n_read / 1024;
106 | + int usec_elapsed = cur_time.tv_usec - s_progress->last_time.tv_usec;
107 | + double sec_elapsed = ( double ) usec_elapsed / 1000000.f;
108 | + sec_elapsed += ( double ) ( cur_time.tv_sec - s_progress->last_time.tv_sec );
109 | + int copy_speed = ( int ) ( ( double ) ( cur_size - s_progress->last_size )
110 | + / sec_elapsed );
111 | + char s_copy_speed[20];
112 | + file_size_format ( s_copy_speed, copy_speed, 1 );
113 | + /* update vars */
114 | + s_progress->last_time = cur_time;
115 | + s_progress->last_size = cur_size;
116 | +
117 | + /* how many time has passed since the start? */
118 | + int isec_elapsed = cur_time.tv_sec - g_oStartTime.tv_sec;
119 | + int sec_remaining = ( int ) ( ( double ) isec_elapsed / cur_size
120 | + * g_iTotalSize ) - isec_elapsed;
121 | + int min_remaining = sec_remaining / 60;
122 | + sec_remaining -= min_remaining * 60;
123 | + int hours_remaining = min_remaining / 60;
124 | + min_remaining -= hours_remaining * 60;
125 | + /* print out */
126 | + sprintf ( s_progress->cProgressField[3],
127 | + "Copying at %s/s (about %uh %um %us remaining)", s_copy_speed,
128 | + hours_remaining, min_remaining, sec_remaining );
129 | +
130 | + int fs_len;
131 | + if ( g_iTotalFiles > 1 )
132 | + {
133 | + /* global progress bar */
134 | + file_progress_bar ( s_progress->cProgressField[2], s_progress->iBarLength,
135 | + g_iTotalWritten + *total_n_read / 1024, g_iTotalSize );
136 | +
137 | + /* print the global status */
138 | + fs_len = file_size_format ( s_progress->cProgressField[1] + s_progress->iBarLength - 21,
139 | + g_iTotalWritten + *total_n_read / 1024, 1 );
140 | + s_progress->cProgressField[1][s_progress->iBarLength - 21 + fs_len] = ' ';
141 | + }
142 | +
143 | + /* current progress bar */
144 | + file_progress_bar ( sProgressBar, s_progress->iBarLength, *total_n_read, s_progress->src_open_sb.st_size );
145 | +
146 | + /* print the status */
147 | + fs_len = file_size_format ( s_progress->cProgressField[4] + s_progress->iBarLength - 21, *total_n_read, 0 );
148 | + s_progress->cProgressField[4][s_progress->iBarLength - 21 + fs_len] = ' ';
149 | +
150 | + /* print the field */
151 | + int it;
152 | + for ( it = g_iTotalFiles>1 ? 0 : 3; it < 6; it++ )
153 | + {
154 | + printf ( "\033[K%s\n", s_progress->cProgressField[it] );
155 | + if ( strlen ( s_progress->cProgressField[it] ) < s_progress->iBarLength )
156 | + printf ( "" );
157 | + }
158 | + if ( g_iTotalFiles > 1 )
159 | + printf ( "\r\033[6A" );
160 | + else
161 | + printf ( "\r\033[3A" );
162 | + fflush ( stdout );
163 | + }
164 | + /* END progress mod */
165 | + }
166 | +
167 | ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size));
168 | if (n_read < 0)
169 | {
170 | @@ -320,6 +464,14 @@
171 | certain files in /proc or /sys with linux kernels. */
172 | }
173 |
174 | + /* BEGIN progress mod */
175 | + if (progress) {
176 | + /* update total size */
177 | + g_iTotalWritten += *total_n_read / 1024;
178 | + g_iFilesCopied++;
179 | + }
180 | + /* END progress mod */
181 | +
182 | /* Ensure a trailing hole is created, so that subsequent
183 | calls of sparse_copy() start at the correct offset. */
184 | if (make_hole && ! create_hole (dest_fd, dst_name, punch_holes, psize))
185 | @@ -388,7 +540,9 @@
186 | size_t hole_size, off_t src_total_size,
187 | enum Sparse_type sparse_mode,
188 | char const *src_name, char const *dst_name,
189 | - bool *require_normal_copy)
190 | + bool *require_normal_copy,
191 | + int iCountDown, char ** cProgressField, struct timeval last_time,
192 | + int last_size, int iBarLength, struct stat src_open_sb)
193 | {
194 | struct extent_scan scan;
195 | off_t last_ext_start = 0;
196 | @@ -519,10 +673,16 @@
197 | last_ext_len = ext_len;
198 | bool read_hole;
199 |
200 | + struct timeval a;
201 | + struct stat b;
202 | +
203 | + struct progress_status s_progress={iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb};
204 | +
205 | +
206 | if ( ! sparse_copy (src_fd, dest_fd, buf, buf_size,
207 | sparse_mode == SPARSE_ALWAYS ? hole_size: 0,
208 | true, src_name, dst_name, ext_len, &n_read,
209 | - &read_hole))
210 | + &read_hole,&s_progress))
211 | goto fail;
212 |
213 | dest_pos = ext_start + n_read;
214 | @@ -1270,6 +1430,70 @@
215 |
216 | buf_alloc = xmalloc (buf_size + buf_alignment);
217 | buf = ptr_align (buf_alloc, buf_alignment);
218 | +
219 | + /* BEGIN progress mod */
220 | + /* create a field of 6 lines */
221 | + char ** cProgressField = ( char ** ) calloc ( 6, sizeof ( char * ) );
222 | + /* get console width */
223 | + int iBarLength = 80;
224 | + struct winsize win;
225 | + if ( ioctl (STDOUT_FILENO, TIOCGWINSZ, (char *) &win) == 0 && win.ws_col > 0 )
226 | + iBarLength = win.ws_col;
227 | + /* create rows */
228 | + int it;
229 | + for ( it = 0; it < 6; it++ )
230 | + {
231 | + cProgressField[it] = ( char * ) malloc ( iBarLength + 1 );
232 | + /* init with spaces */
233 | + int j;
234 | + for ( j = 0; j < iBarLength; j++ )
235 | + cProgressField[it][j] = ' ';
236 | + cProgressField[it][iBarLength] = '\0';
237 | + }
238 | +
239 | + /* global progress bar? */
240 | + if ( g_iTotalFiles > 1 )
241 | + {
242 | + /* init global progress bar */
243 | + cProgressField[2][0] = '[';
244 | + cProgressField[2][iBarLength - 8] = ']';
245 | + cProgressField[2][iBarLength - 7] = ' ';
246 | + cProgressField[2][iBarLength - 1] = '%';
247 | +
248 | + /* total size */
249 | + cProgressField[1][iBarLength - 11] = '/';
250 | + file_size_format ( cProgressField[1] + iBarLength - 9, g_iTotalSize, 1 );
251 | +
252 | + /* show how many files were written */
253 | + int sum_length = sprintf ( cProgressField[1], "%d files copied so far...", g_iFilesCopied );
254 | + cProgressField[1][sum_length] = ' ';
255 | + }
256 | +
257 | + /* truncate filename? */
258 | + int fn_length;
259 | + if ( strlen ( src_name ) > iBarLength - 22 )
260 | + fn_length =
261 | + sprintf ( cProgressField[4], "...%s", src_name + ( strlen ( src_name ) - iBarLength + 25 ) );
262 | + else
263 | + fn_length = sprintf ( cProgressField[4], "%s", src_name );
264 | + cProgressField[4][fn_length] = ' ';
265 | +
266 | + /* filesize */
267 | + cProgressField[4][iBarLength - 11] = '/';
268 | + file_size_format ( cProgressField[4] + iBarLength - 9, src_open_sb.st_size, 0 );
269 | +
270 | + int iCountDown = 1;
271 | + char * sProgressBar = cProgressField[5];
272 | + sProgressBar[0] = '[';
273 | + sProgressBar[iBarLength - 8] = ']';
274 | + sProgressBar[iBarLength - 7] = ' ';
275 | + sProgressBar[iBarLength - 1] = '%';
276 | +
277 | + /* this will always save the time in between */
278 | + struct timeval last_time;
279 | + gettimeofday ( & last_time, NULL );
280 | + int last_size = g_iTotalWritten;
281 | + /* END progress mod */
282 |
283 | if (sparse_src)
284 | {
285 | @@ -1282,7 +1506,9 @@
286 | if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size,
287 | src_open_sb.st_size,
288 | make_holes ? x->sparse_mode : SPARSE_NEVER,
289 | - src_name, dst_name, &normal_copy_required))
290 | + src_name, dst_name, &normal_copy_required,
291 | + iCountDown, cProgressField, last_time, last_size,
292 | + iBarLength, src_open_sb))
293 | goto preserve_metadata;
294 |
295 | if (! normal_copy_required)
296 | @@ -1294,11 +1520,12 @@
297 |
298 | off_t n_read;
299 | bool wrote_hole_at_eof;
300 | + struct progress_status s_progress = { iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb};
301 | if (! sparse_copy (source_desc, dest_desc, buf, buf_size,
302 | make_holes ? hole_size : 0,
303 | x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name,
304 | UINTMAX_MAX, &n_read,
305 | - &wrote_hole_at_eof))
306 | + &wrote_hole_at_eof, &s_progress))
307 | {
308 | return_val = false;
309 | goto close_src_and_dst_desc;
310 | @@ -1309,6 +1536,14 @@
311 | return_val = false;
312 | goto close_src_and_dst_desc;
313 | }
314 | + /* BEGIN progress mod */
315 | + if (progress) {
316 | + int i;
317 | + for ( i = 0; i < 6; i++ )
318 | + free ( cProgressField[i] );
319 | + free ( cProgressField );
320 | + }
321 | + /* END progress mod */
322 | }
323 |
324 | preserve_metadata:
325 | --- src/copy.h 2018-05-14 06:20:24.000000000 +0200
326 | +++ src/copy.h 2018-09-19 19:23:13.265541538 +0200
327 | @@ -234,6 +234,9 @@
328 | Create destination directories as usual. */
329 | bool symbolic_link;
330 |
331 | + /* If true, draw a nice progress bar on screen */
332 | + bool progress_bar;
333 | +
334 | /* If true, do not copy a nondirectory that has an existing destination
335 | with the same or newer modification time. */
336 | bool update;
337 | @@ -309,4 +312,15 @@
338 | bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE;
339 | mode_t cached_umask (void);
340 |
341 | +/* BEGIN OF PROGRESS MOD */
342 | +int file_size_format ( char * _cDst, long _lSize, int _iCounter );
343 | +
344 | +long g_iTotalSize;
345 | +long g_iTotalWritten;
346 | +int g_iFilesCopied;
347 | +struct timeval g_oStartTime;
348 | +int g_iTotalFiles;
349 | +bool progress;
350 | +/* END OF PROGRESS MOD */
351 | +
352 | #endif
353 | --- src/cp.c 2018-06-24 04:12:51.000000000 +0200
354 | +++ src/cp.c 2018-09-19 20:42:07.159168551 +0200
355 | @@ -131,6 +131,7 @@
356 | {"symbolic-link", no_argument, NULL, 's'},
357 | {"target-directory", required_argument, NULL, 't'},
358 | {"update", no_argument, NULL, 'u'},
359 | + {"progress-bar", no_argument, NULL, 'g'},
360 | {"verbose", no_argument, NULL, 'v'},
361 | {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
362 | {GETOPT_HELP_OPTION_DECL},
363 | @@ -170,6 +171,7 @@
364 | -f, --force if an existing destination file cannot be\n\
365 | opened, remove it and try again (this option\n\
366 | is ignored when the -n option is also used)\n\
367 | + -g, --progress-bar add a progress bar\n\
368 | -i, --interactive prompt before overwrite (overrides a previous -n\
369 | \n\
370 | option)\n\
371 | @@ -635,6 +637,70 @@
372 | die (EXIT_FAILURE, 0, _("target %s is not a directory"),
373 | quoteaf (file[n_files - 1]));
374 | }
375 | + struct timeval start_time;
376 | + if (progress) {
377 | + /* BEGIN progress mod */
378 | + g_iTotalSize = 0;
379 | + g_iTotalFiles = 0;
380 | + g_iFilesCopied = 0;
381 | + g_iTotalWritten = 0;
382 | +
383 | + /* save time */
384 | + gettimeofday ( & start_time, NULL );
385 | + g_oStartTime = start_time;
386 | +
387 | + printf ( "Calculating total size... \r" );
388 | + fflush ( stdout );
389 | + long iTotalSize = 0;
390 | + int iFiles = n_files;
391 | + if ( ! target_directory )
392 | + iFiles = n_files - 1;
393 | + int j;
394 | +
395 | + /* how many files are we copying */
396 | + char command[1024];
397 | + sprintf( command, "find \"%s\" -type f | wc -l", file[0]);
398 | + FILE *fp ;
399 | + char output[1024];
400 | + fp = popen(command,"r");
401 | + if ( fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL)
402 | + printf("failed to run find.\n");
403 | + else
404 | + g_iTotalFiles = atoi( output ) ;
405 | +
406 | + for (j = 0; j < iFiles; j++)
407 | + {
408 | + /* call du -s for each file */
409 | + /* create command */
410 | + char command[1024];
411 | + sprintf ( command, "du -s \"%s\"", file[j] );
412 | + /* TODO: replace all quote signs in file[i] */
413 | +
414 | + FILE *fp;
415 | + char output[1024];
416 | +
417 | + /* run command */
418 | + fp = popen(command, "r");
419 | + if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) {
420 | + printf("failed to run du.\n" );
421 | + }
422 | + else
423 | + {
424 | + /* isolate size */
425 | + strchr ( output, '\t' )[0] = '\0';
426 | + iTotalSize += atol ( output );
427 | +
428 | + printf ( "Calculating total size... %ld\r", iTotalSize );
429 | + fflush ( stdout );
430 | + }
431 | +
432 | + /* close */
433 | + pclose(fp);
434 | + }
435 | + g_iTotalSize = iTotalSize;
436 | + /* END progress mod */
437 | + }
438 | +
439 |
440 | if (target_directory)
441 | {
442 | @@ -777,6 +843,46 @@
443 | ok = copy (source, new_dest, 0, x, &unused, NULL);
444 | }
445 |
446 | + if (progress) {
447 | + /* BEGIN progress mod */
448 | + /* remove everything */
449 | + int i;
450 | + if ( g_iTotalFiles > 1 )
451 | + {
452 | + for ( i = 0; i < 6; i++ )
453 | + printf ( "\033[K\n" );
454 | + printf ( "\r\033[6A" );
455 | + }
456 | + else
457 | + {
458 | + for ( i = 0; i < 3; i++ )
459 | + printf ( "\033[K\n" );
460 | + printf ( "\r\033[3A" );
461 | + }
462 | +
463 | + /* save time */
464 | + struct timeval end_time;
465 | + gettimeofday ( & end_time, NULL );
466 | + int usec_elapsed = end_time.tv_usec - start_time.tv_usec;
467 | + double sec_elapsed = ( double ) usec_elapsed / 1000000.f;
468 | + sec_elapsed += ( double ) ( end_time.tv_sec - start_time.tv_sec );
469 | +
470 | + /* get total size */
471 | + char sTotalWritten[20];
472 | + file_size_format ( sTotalWritten, g_iTotalSize, 1 );
473 | + /* TODO: using g_iTotalWritten would be more correct, but is less accurate */
474 | +
475 | + /* calculate speed */
476 | + int copy_speed = ( int ) ( ( double ) g_iTotalWritten / sec_elapsed );
477 | + char s_copy_speed[20];
478 | + file_size_format ( s_copy_speed, copy_speed, 1 );
479 | +
480 | + /* good-bye message */
481 | + printf ( "%d files (%s) copied in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten,
482 | + sec_elapsed, s_copy_speed );
483 | + /* END progress mod */
484 | + }
485 | +
486 | return ok;
487 | }
488 |
489 | @@ -812,6 +918,7 @@
490 | x->recursive = false;
491 | x->sparse_mode = SPARSE_AUTO;
492 | x->symbolic_link = false;
493 | + x->progress_bar = false;
494 | x->set_mode = false;
495 | x->mode = 0;
496 |
497 | @@ -950,7 +1057,7 @@
498 | selinux_enabled = (0 < is_selinux_enabled ());
499 | cp_option_init (&x);
500 |
501 | - while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
502 | + while ((c = getopt_long (argc, argv, "abdfgHilLnprst:uvxPRS:TZ",
503 | long_opts, NULL))
504 | != -1)
505 | {
506 | @@ -1007,6 +1114,10 @@
507 | x.unlink_dest_after_failed_open = true;
508 | break;
509 |
510 | + case 'g':
511 | + progress = true;
512 | + break;
513 | +
514 | case 'H':
515 | x.dereference = DEREF_COMMAND_LINE_ARGUMENTS;
516 | break;
517 | --- src/mv.c 2018-06-24 04:12:51.000000000 +0200
518 | +++ src/mv.c 2018-09-20 10:36:33.316124125 +0200
519 | @@ -66,6 +66,7 @@
520 | {"target-directory", required_argument, NULL, 't'},
521 | {"update", no_argument, NULL, 'u'},
522 | {"verbose", no_argument, NULL, 'v'},
523 | + {"progress-ar", no_argument, NULL, 'g'},
524 | {GETOPT_HELP_OPTION_DECL},
525 | {GETOPT_VERSION_OPTION_DECL},
526 | {NULL, 0, NULL, 0}
527 | @@ -168,10 +169,86 @@
528 | static bool
529 | do_move (const char *source, const char *dest, const struct cp_options *x)
530 | {
531 | + struct timeval start_time;
532 | +
533 | bool copy_into_self;
534 | bool rename_succeeded;
535 | + if(progress && x->rename_errno != 0) {
536 | + /* BEGIN progress mod */
537 | + g_iTotalSize = 0;
538 | + g_iFilesCopied = 0;
539 | + g_iTotalWritten = 0;
540 | +
541 | + gettimeofday (& start_time, NULL);
542 | + g_oStartTime = start_time;
543 | +
544 | + printf ("Calculating total size... \r");
545 | + fflush (stdout);
546 | + long iTotalSize = 0;
547 | + /* call du -s for each file */
548 | + /* create command */
549 | + char command[1024];
550 | + sprintf ( command, "du -s '%s'", source );
551 | + /* TODO: replace all quote signs in file[i] */
552 | +
553 | + FILE *fp;
554 | + char output[1024];
555 | +
556 | + /* run command */
557 | + fp = popen(command, "r");
558 | + if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) {
559 | + //printf("failed to run du.\n" );
560 | + }
561 | + else
562 | + {
563 | + /* isolate size */
564 | + strchr ( output, '\t' )[0] = '\0';
565 | + iTotalSize += atol ( output );
566 | + printf ( "Calculating total size... %ld\r", iTotalSize );
567 | + fflush ( stdout );
568 | + }
569 | +
570 | + /* close */
571 | + pclose(fp);
572 | + g_iTotalSize = iTotalSize;
573 | + /* END progress mod */
574 | +
575 | + }
576 | +
577 | bool ok = copy (source, dest, false, x, ©_into_self, &rename_succeeded);
578 |
579 | + if (progress && (x->rename_errno != 0 && ok)) {
580 | + /* BEGIN progress mod */
581 | + /* remove everything */
582 | + int i;
583 | + int limit = (g_iTotalFiles > 1 ? 6 : 3);
584 | + for ( i = 0; i < limit; i++ )
585 | + printf ( "\033[K\n" );
586 | + printf ( "\r\033[3A" );
587 | +
588 | + /* save time */
589 | + struct timeval end_time;
590 | + gettimeofday ( & end_time, NULL );
591 | + int usec_elapsed = end_time.tv_usec - start_time.tv_usec;
592 | + double sec_elapsed = ( double ) usec_elapsed / 1000000.f;
593 | + sec_elapsed += ( double ) ( end_time.tv_sec - start_time.tv_sec );
594 | +
595 | + /* get total size */
596 | + char sTotalWritten[20];
597 | + file_size_format ( sTotalWritten, g_iTotalSize, 1 );
598 | + /* TODO: using g_iTotalWritten would be more correct, but is less accurate */
599 | +
600 | + /* calculate speed */
601 | + int copy_speed = ( int ) ( ( double ) g_iTotalWritten / sec_elapsed );
602 | + char s_copy_speed[20];
603 | + file_size_format ( s_copy_speed, copy_speed, 1 );
604 | +
605 | + /* good-bye message */
606 | + printf ( "%d files (%s) moved in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten,
607 | + sec_elapsed, s_copy_speed );
608 | + /* END progress mod */
609 | + }
610 | +
611 | if (ok)
612 | {
613 | char const *dir_to_remove;
614 | @@ -306,6 +383,7 @@
615 | \n\
616 | -b like --backup but does not accept an argument\n\
617 | -f, --force do not prompt before overwriting\n\
618 | + -g, --progress-bar add progress-bar\n\
619 | -i, --interactive prompt before overwrite\n\
620 | -n, --no-clobber do not overwrite an existing file\n\
621 | If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
622 | @@ -361,7 +439,7 @@
623 | /* Try to disable the ability to unlink a directory. */
624 | priv_set_remove_linkdir ();
625 |
626 | - while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
627 | + while ((c = getopt_long (argc, argv, "bfint:uvgS:TZ", long_options, NULL))
628 | != -1)
629 | {
630 | switch (c)
631 | @@ -407,6 +485,11 @@
632 | case 'v':
633 | x.verbose = true;
634 | break;
635 | +
636 | + case 'g':
637 | + progress = true;
638 | + break;
639 | +
640 | case 'S':
641 | make_backups = true;
642 | backup_suffix = optarg;
643 |
--------------------------------------------------------------------------------
/coreutils_modules:
--------------------------------------------------------------------------------
1 | [
2 | b2sum
3 | base32
4 | base64
5 | basename
6 | cat
7 | chcon
8 | chgrp
9 | chmod
10 | chown
11 | chroot
12 | cksum
13 | comm
14 | cp
15 | csplit
16 | cut
17 | date
18 | dd
19 | df
20 | dir
21 | dircolors
22 | dirname
23 | du
24 | echo
25 | env
26 | expand
27 | expr
28 | factor
29 | false
30 | fmt
31 | fold
32 | ginstall
33 | groups
34 | head
35 | hostid
36 | id
37 | join
38 | kill
39 | link
40 | ln
41 | logname
42 | ls
43 | md5sum
44 | mkdir
45 | mkfifo
46 | mknod
47 | mktemp
48 | mv
49 | nice
50 | nl
51 | nohup
52 | nproc
53 | numfmt
54 | od
55 | paste
56 | pathchk
57 | pinky
58 | pr
59 | printenv
60 | printf
61 | ptx
62 | pwd
63 | readlink
64 | realpath
65 | rm
66 | rmdir
67 | runcon
68 | seq
69 | sha1sum
70 | sha224sum
71 | sha256sum
72 | sha384sum
73 | sha512sum
74 | shred
75 | shuf
76 | sleep
77 | sort
78 | split
79 | stat
80 | stty
81 | sum
82 | sync
83 | tac
84 | tail
85 | tee
86 | test
87 | timeout
88 | touch
89 | tr
90 | true
91 | truncate
92 | tsort
93 | tty
94 | uname
95 | unexpand
96 | uniq
97 | unlink
98 | uptime
99 | users
100 | vdir
101 | wc
102 | who
103 | whoami
104 | yes
105 |
--------------------------------------------------------------------------------
/nano_wrapper:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 | # nano: wrapper to set up and run nano from terminal
3 | # osm0sis @ xda-developers
4 |
5 | dir="$(cd "$(dirname "$0")"; pwd)";
6 |
7 | if [ "$1" == "--term" ]; then
8 | term=$2;
9 | shift 2;
10 | else
11 | term=screen;
12 | fi;
13 |
14 | clear;
15 | resize >/dev/null;
16 | TERMINFO=/system/usr/share/terminfo TERM=$term $dir/nano.bin "$@";
17 |
--------------------------------------------------------------------------------
/ndk_static_patches/coreutils.patch:
--------------------------------------------------------------------------------
1 | --- lib/time_rz.c.orig 2019-01-02 13:16:01.000000000 -0500
2 | +++ lib/time_rz.c 2019-06-08 20:59:58.286255700 -0400
3 | @@ -89,28 +89,6 @@
4 | abbrs[abbr_size] = '\0';
5 | }
6 |
7 | -/* Return a newly allocated time zone for NAME, or NULL on failure.
8 | - A null NAME stands for wall clock time (which is like unset TZ). */
9 | -timezone_t
10 | -tzalloc (char const *name)
11 | -{
12 | - size_t name_size = name ? strlen (name) + 1 : 0;
13 | - size_t abbr_size = name_size < ABBR_SIZE_MIN ? ABBR_SIZE_MIN : name_size + 1;
14 | - timezone_t tz = malloc (FLEXSIZEOF (struct tm_zone, abbrs, abbr_size));
15 | - if (tz)
16 | - {
17 | - tz->next = NULL;
18 | -#if HAVE_TZNAME && !HAVE_TM_ZONE
19 | - tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
20 | -#endif
21 | - tz->tz_is_set = !!name;
22 | - tz->abbrs[0] = '\0';
23 | - if (name)
24 | - extend_abbrs (tz->abbrs, name, name_size);
25 | - }
26 | - return tz;
27 | -}
28 | -
29 | /* Save into TZ any nontrivial time zone abbreviation used by TM, and
30 | update *TM (if HAVE_TM_ZONE) or *TZ (if !HAVE_TM_ZONE &&
31 | HAVE_TZNAME) if they use the abbreviation. Return true if
32 | @@ -191,19 +169,6 @@
33 | return true;
34 | }
35 |
36 | -/* Free a time zone. */
37 | -void
38 | -tzfree (timezone_t tz)
39 | -{
40 | - if (tz != local_tz)
41 | - while (tz)
42 | - {
43 | - timezone_t next = tz->next;
44 | - free (tz);
45 | - tz = next;
46 | - }
47 | -}
48 | -
49 | /* Get and set the TZ environment variable. These functions can be
50 | overridden by programs like Emacs that manage their own environment. */
51 |
52 | @@ -281,64 +246,3 @@
53 | return ok;
54 | }
55 | }
56 | -
57 | -/* Use time zone TZ to compute localtime_r (T, TM). */
58 | -struct tm *
59 | -localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
60 | -{
61 | -#ifdef HAVE_LOCALTIME_INFLOOP_BUG
62 | - /* The -67768038400665599 comes from:
63 | - https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
64 | - On affected platforms the greatest POSIX-compatible time_t value
65 | - that could return nonnull is 67768036191766798 (when
66 | - TZ="XXX24:59:59" it resolves to the year 2**31 - 1 + 1900, on
67 | - 12-31 at 23:59:59), so test for that too while we're in the
68 | - neighborhood. */
69 | - if (! (-67768038400665599 <= *t && *t <= 67768036191766798))
70 | - {
71 | - errno = EOVERFLOW;
72 | - return NULL;
73 | - }
74 | -#endif
75 | -
76 | - if (!tz)
77 | - return gmtime_r (t, tm);
78 | - else
79 | - {
80 | - timezone_t old_tz = set_tz (tz);
81 | - if (old_tz)
82 | - {
83 | - bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
84 | - if (revert_tz (old_tz) && abbr_saved)
85 | - return tm;
86 | - }
87 | - return NULL;
88 | - }
89 | -}
90 | -
91 | -/* Use time zone TZ to compute mktime (TM). */
92 | -time_t
93 | -mktime_z (timezone_t tz, struct tm *tm)
94 | -{
95 | - if (!tz)
96 | - return timegm (tm);
97 | - else
98 | - {
99 | - timezone_t old_tz = set_tz (tz);
100 | - if (old_tz)
101 | - {
102 | - time_t t = mktime (tm);
103 | -#if HAVE_TM_ZONE || HAVE_TZNAME
104 | - time_t badtime = -1;
105 | - struct tm tm_1;
106 | - if ((t != badtime
107 | - || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
108 | - && !save_abbr (tz, tm))
109 | - t = badtime;
110 | -#endif
111 | - if (revert_tz (old_tz))
112 | - return t;
113 | - }
114 | - return -1;
115 | - }
116 | -}
117 |
--------------------------------------------------------------------------------
/ndk_static_patches/diffutils.patch:
--------------------------------------------------------------------------------
1 | --- lib/time_rz.c 2019-01-04 11:18:35.000000000 -0500
2 | +++ lib/time_rz.c-2 2019-06-08 18:01:37.586438400 -0400
3 | @@ -89,28 +89,6 @@
4 | abbrs[abbr_size] = '\0';
5 | }
6 |
7 | -/* Return a newly allocated time zone for NAME, or NULL on failure.
8 | - A null NAME stands for wall clock time (which is like unset TZ). */
9 | -timezone_t
10 | -tzalloc (char const *name)
11 | -{
12 | - size_t name_size = name ? strlen (name) + 1 : 0;
13 | - size_t abbr_size = name_size < ABBR_SIZE_MIN ? ABBR_SIZE_MIN : name_size + 1;
14 | - timezone_t tz = malloc (FLEXSIZEOF (struct tm_zone, abbrs, abbr_size));
15 | - if (tz)
16 | - {
17 | - tz->next = NULL;
18 | -#if HAVE_TZNAME && !HAVE_TM_ZONE
19 | - tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
20 | -#endif
21 | - tz->tz_is_set = !!name;
22 | - tz->abbrs[0] = '\0';
23 | - if (name)
24 | - extend_abbrs (tz->abbrs, name, name_size);
25 | - }
26 | - return tz;
27 | -}
28 | -
29 | /* Save into TZ any nontrivial time zone abbreviation used by TM, and
30 | update *TM (if HAVE_TM_ZONE) or *TZ (if !HAVE_TM_ZONE &&
31 | HAVE_TZNAME) if they use the abbreviation. Return true if
32 | @@ -191,19 +169,6 @@
33 | return true;
34 | }
35 |
36 | -/* Free a time zone. */
37 | -void
38 | -tzfree (timezone_t tz)
39 | -{
40 | - if (tz != local_tz)
41 | - while (tz)
42 | - {
43 | - timezone_t next = tz->next;
44 | - free (tz);
45 | - tz = next;
46 | - }
47 | -}
48 | -
49 | /* Get and set the TZ environment variable. These functions can be
50 | overridden by programs like Emacs that manage their own environment. */
51 |
52 | @@ -281,64 +246,3 @@
53 | return ok;
54 | }
55 | }
56 | -
57 | -/* Use time zone TZ to compute localtime_r (T, TM). */
58 | -struct tm *
59 | -localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
60 | -{
61 | -#ifdef HAVE_LOCALTIME_INFLOOP_BUG
62 | - /* The -67768038400665599 comes from:
63 | - https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
64 | - On affected platforms the greatest POSIX-compatible time_t value
65 | - that could return nonnull is 67768036191766798 (when
66 | - TZ="XXX24:59:59" it resolves to the year 2**31 - 1 + 1900, on
67 | - 12-31 at 23:59:59), so test for that too while we're in the
68 | - neighborhood. */
69 | - if (! (-67768038400665599 <= *t && *t <= 67768036191766798))
70 | - {
71 | - errno = EOVERFLOW;
72 | - return NULL;
73 | - }
74 | -#endif
75 | -
76 | - if (!tz)
77 | - return gmtime_r (t, tm);
78 | - else
79 | - {
80 | - timezone_t old_tz = set_tz (tz);
81 | - if (old_tz)
82 | - {
83 | - bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
84 | - if (revert_tz (old_tz) && abbr_saved)
85 | - return tm;
86 | - }
87 | - return NULL;
88 | - }
89 | -}
90 | -
91 | -/* Use time zone TZ to compute mktime (TM). */
92 | -time_t
93 | -mktime_z (timezone_t tz, struct tm *tm)
94 | -{
95 | - if (!tz)
96 | - return timegm (tm);
97 | - else
98 | - {
99 | - timezone_t old_tz = set_tz (tz);
100 | - if (old_tz)
101 | - {
102 | - time_t t = mktime (tm);
103 | -#if HAVE_TM_ZONE || HAVE_TZNAME
104 | - time_t badtime = -1;
105 | - struct tm tm_1;
106 | - if ((t != badtime
107 | - || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
108 | - && !save_abbr (tz, tm))
109 | - t = badtime;
110 | -#endif
111 | - if (revert_tz (old_tz))
112 | - return t;
113 | - }
114 | - return -1;
115 | - }
116 | -}
117 |
--------------------------------------------------------------------------------
/ndk_static_patches/findutils.patch:
--------------------------------------------------------------------------------
1 | --- gl/lib/time_rz.c.orig 2019-01-02 13:16:01.000000000 -0500
2 | +++ gl/lib/time_rz.c 2019-06-08 20:59:58.286255700 -0400
3 | @@ -89,28 +89,6 @@
4 | abbrs[abbr_size] = '\0';
5 | }
6 |
7 | -/* Return a newly allocated time zone for NAME, or NULL on failure.
8 | - A null NAME stands for wall clock time (which is like unset TZ). */
9 | -timezone_t
10 | -tzalloc (char const *name)
11 | -{
12 | - size_t name_size = name ? strlen (name) + 1 : 0;
13 | - size_t abbr_size = name_size < ABBR_SIZE_MIN ? ABBR_SIZE_MIN : name_size + 1;
14 | - timezone_t tz = malloc (FLEXSIZEOF (struct tm_zone, abbrs, abbr_size));
15 | - if (tz)
16 | - {
17 | - tz->next = NULL;
18 | -#if HAVE_TZNAME && !HAVE_TM_ZONE
19 | - tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
20 | -#endif
21 | - tz->tz_is_set = !!name;
22 | - tz->abbrs[0] = '\0';
23 | - if (name)
24 | - extend_abbrs (tz->abbrs, name, name_size);
25 | - }
26 | - return tz;
27 | -}
28 | -
29 | /* Save into TZ any nontrivial time zone abbreviation used by TM, and
30 | update *TM (if HAVE_TM_ZONE) or *TZ (if !HAVE_TM_ZONE &&
31 | HAVE_TZNAME) if they use the abbreviation. Return true if
32 | @@ -191,19 +169,6 @@
33 | return true;
34 | }
35 |
36 | -/* Free a time zone. */
37 | -void
38 | -tzfree (timezone_t tz)
39 | -{
40 | - if (tz != local_tz)
41 | - while (tz)
42 | - {
43 | - timezone_t next = tz->next;
44 | - free (tz);
45 | - tz = next;
46 | - }
47 | -}
48 | -
49 | /* Get and set the TZ environment variable. These functions can be
50 | overridden by programs like Emacs that manage their own environment. */
51 |
52 | @@ -281,64 +246,3 @@
53 | return ok;
54 | }
55 | }
56 | -
57 | -/* Use time zone TZ to compute localtime_r (T, TM). */
58 | -struct tm *
59 | -localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
60 | -{
61 | -#ifdef HAVE_LOCALTIME_INFLOOP_BUG
62 | - /* The -67768038400665599 comes from:
63 | - https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
64 | - On affected platforms the greatest POSIX-compatible time_t value
65 | - that could return nonnull is 67768036191766798 (when
66 | - TZ="XXX24:59:59" it resolves to the year 2**31 - 1 + 1900, on
67 | - 12-31 at 23:59:59), so test for that too while we're in the
68 | - neighborhood. */
69 | - if (! (-67768038400665599 <= *t && *t <= 67768036191766798))
70 | - {
71 | - errno = EOVERFLOW;
72 | - return NULL;
73 | - }
74 | -#endif
75 | -
76 | - if (!tz)
77 | - return gmtime_r (t, tm);
78 | - else
79 | - {
80 | - timezone_t old_tz = set_tz (tz);
81 | - if (old_tz)
82 | - {
83 | - bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
84 | - if (revert_tz (old_tz) && abbr_saved)
85 | - return tm;
86 | - }
87 | - return NULL;
88 | - }
89 | -}
90 | -
91 | -/* Use time zone TZ to compute mktime (TM). */
92 | -time_t
93 | -mktime_z (timezone_t tz, struct tm *tm)
94 | -{
95 | - if (!tz)
96 | - return timegm (tm);
97 | - else
98 | - {
99 | - timezone_t old_tz = set_tz (tz);
100 | - if (old_tz)
101 | - {
102 | - time_t t = mktime (tm);
103 | -#if HAVE_TM_ZONE || HAVE_TZNAME
104 | - time_t badtime = -1;
105 | - struct tm tm_1;
106 | - if ((t != badtime
107 | - || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
108 | - && !save_abbr (tz, tm))
109 | - t = badtime;
110 | -#endif
111 | - if (revert_tz (old_tz))
112 | - return t;
113 | - }
114 | - return -1;
115 | - }
116 | -}
117 |
--------------------------------------------------------------------------------
/ndk_static_patches/patch.patch:
--------------------------------------------------------------------------------
1 | --- lib/time_rz.c 2018-02-03 07:42:19.000000000 -0500
2 | +++ lib/time_rz.c-2 2019-06-08 20:09:07.341262200 -0400
3 | @@ -89,28 +89,6 @@
4 | abbrs[abbr_size] = '\0';
5 | }
6 |
7 | -/* Return a newly allocated time zone for NAME, or NULL on failure.
8 | - A null NAME stands for wall clock time (which is like unset TZ). */
9 | -timezone_t
10 | -tzalloc (char const *name)
11 | -{
12 | - size_t name_size = name ? strlen (name) + 1 : 0;
13 | - size_t abbr_size = name_size < ABBR_SIZE_MIN ? ABBR_SIZE_MIN : name_size + 1;
14 | - timezone_t tz = malloc (FLEXSIZEOF (struct tm_zone, abbrs, abbr_size));
15 | - if (tz)
16 | - {
17 | - tz->next = NULL;
18 | -#if HAVE_TZNAME && !HAVE_TM_ZONE
19 | - tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
20 | -#endif
21 | - tz->tz_is_set = !!name;
22 | - tz->abbrs[0] = '\0';
23 | - if (name)
24 | - extend_abbrs (tz->abbrs, name, name_size);
25 | - }
26 | - return tz;
27 | -}
28 | -
29 | /* Save into TZ any nontrivial time zone abbreviation used by TM, and
30 | update *TM (if HAVE_TM_ZONE) or *TZ (if !HAVE_TM_ZONE &&
31 | HAVE_TZNAME) if they use the abbreviation. Return true if
32 | @@ -191,19 +169,6 @@
33 | return true;
34 | }
35 |
36 | -/* Free a time zone. */
37 | -void
38 | -tzfree (timezone_t tz)
39 | -{
40 | - if (tz != local_tz)
41 | - while (tz)
42 | - {
43 | - timezone_t next = tz->next;
44 | - free (tz);
45 | - tz = next;
46 | - }
47 | -}
48 | -
49 | /* Get and set the TZ environment variable. These functions can be
50 | overridden by programs like Emacs that manage their own environment. */
51 |
52 | @@ -281,49 +246,3 @@
53 | return ok;
54 | }
55 | }
56 | -
57 | -/* Use time zone TZ to compute localtime_r (T, TM). */
58 | -struct tm *
59 | -localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
60 | -{
61 | - if (!tz)
62 | - return gmtime_r (t, tm);
63 | - else
64 | - {
65 | - timezone_t old_tz = set_tz (tz);
66 | - if (old_tz)
67 | - {
68 | - bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
69 | - if (revert_tz (old_tz) && abbr_saved)
70 | - return tm;
71 | - }
72 | - return NULL;
73 | - }
74 | -}
75 | -
76 | -/* Use time zone TZ to compute mktime (TM). */
77 | -time_t
78 | -mktime_z (timezone_t tz, struct tm *tm)
79 | -{
80 | - if (!tz)
81 | - return timegm (tm);
82 | - else
83 | - {
84 | - timezone_t old_tz = set_tz (tz);
85 | - if (old_tz)
86 | - {
87 | - time_t t = mktime (tm);
88 | -#if HAVE_TM_ZONE || HAVE_TZNAME
89 | - time_t badtime = -1;
90 | - struct tm tm_1;
91 | - if ((t != badtime
92 | - || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
93 | - && !save_abbr (tz, tm))
94 | - t = badtime;
95 | -#endif
96 | - if (revert_tz (old_tz))
97 | - return t;
98 | - }
99 | - return -1;
100 | - }
101 | -}
102 |
--------------------------------------------------------------------------------
/ndk_static_patches/tar.patch:
--------------------------------------------------------------------------------
1 | --- gnu/time_rz.c.orig 2019-01-02 13:16:01.000000000 -0500
2 | +++ gnu/time_rz.c 2019-06-08 20:59:58.286255700 -0400
3 | @@ -89,28 +89,6 @@
4 | abbrs[abbr_size] = '\0';
5 | }
6 |
7 | -/* Return a newly allocated time zone for NAME, or NULL on failure.
8 | - A null NAME stands for wall clock time (which is like unset TZ). */
9 | -timezone_t
10 | -tzalloc (char const *name)
11 | -{
12 | - size_t name_size = name ? strlen (name) + 1 : 0;
13 | - size_t abbr_size = name_size < ABBR_SIZE_MIN ? ABBR_SIZE_MIN : name_size + 1;
14 | - timezone_t tz = malloc (FLEXSIZEOF (struct tm_zone, abbrs, abbr_size));
15 | - if (tz)
16 | - {
17 | - tz->next = NULL;
18 | -#if HAVE_TZNAME && !HAVE_TM_ZONE
19 | - tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
20 | -#endif
21 | - tz->tz_is_set = !!name;
22 | - tz->abbrs[0] = '\0';
23 | - if (name)
24 | - extend_abbrs (tz->abbrs, name, name_size);
25 | - }
26 | - return tz;
27 | -}
28 | -
29 | /* Save into TZ any nontrivial time zone abbreviation used by TM, and
30 | update *TM (if HAVE_TM_ZONE) or *TZ (if !HAVE_TM_ZONE &&
31 | HAVE_TZNAME) if they use the abbreviation. Return true if
32 | @@ -191,19 +169,6 @@
33 | return true;
34 | }
35 |
36 | -/* Free a time zone. */
37 | -void
38 | -tzfree (timezone_t tz)
39 | -{
40 | - if (tz != local_tz)
41 | - while (tz)
42 | - {
43 | - timezone_t next = tz->next;
44 | - free (tz);
45 | - tz = next;
46 | - }
47 | -}
48 | -
49 | /* Get and set the TZ environment variable. These functions can be
50 | overridden by programs like Emacs that manage their own environment. */
51 |
52 | @@ -281,64 +246,3 @@
53 | return ok;
54 | }
55 | }
56 | -
57 | -/* Use time zone TZ to compute localtime_r (T, TM). */
58 | -struct tm *
59 | -localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
60 | -{
61 | -#ifdef HAVE_LOCALTIME_INFLOOP_BUG
62 | - /* The -67768038400665599 comes from:
63 | - https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
64 | - On affected platforms the greatest POSIX-compatible time_t value
65 | - that could return nonnull is 67768036191766798 (when
66 | - TZ="XXX24:59:59" it resolves to the year 2**31 - 1 + 1900, on
67 | - 12-31 at 23:59:59), so test for that too while we're in the
68 | - neighborhood. */
69 | - if (! (-67768038400665599 <= *t && *t <= 67768036191766798))
70 | - {
71 | - errno = EOVERFLOW;
72 | - return NULL;
73 | - }
74 | -#endif
75 | -
76 | - if (!tz)
77 | - return gmtime_r (t, tm);
78 | - else
79 | - {
80 | - timezone_t old_tz = set_tz (tz);
81 | - if (old_tz)
82 | - {
83 | - bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
84 | - if (revert_tz (old_tz) && abbr_saved)
85 | - return tm;
86 | - }
87 | - return NULL;
88 | - }
89 | -}
90 | -
91 | -/* Use time zone TZ to compute mktime (TM). */
92 | -time_t
93 | -mktime_z (timezone_t tz, struct tm *tm)
94 | -{
95 | - if (!tz)
96 | - return timegm (tm);
97 | - else
98 | - {
99 | - timezone_t old_tz = set_tz (tz);
100 | - if (old_tz)
101 | - {
102 | - time_t t = mktime (tm);
103 | -#if HAVE_TM_ZONE || HAVE_TZNAME
104 | - time_t badtime = -1;
105 | - struct tm tm_1;
106 | - if ((t != badtime
107 | - || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
108 | - && !save_abbr (tz, tm))
109 | - t = badtime;
110 | -#endif
111 | - if (revert_tz (old_tz))
112 | - return t;
113 | - }
114 | - return -1;
115 | - }
116 | -}
117 |
--------------------------------------------------------------------------------