ksh93 / ksh

ksh 93u+m: KornShell lives! | Latest release: https://github.com/ksh93/ksh/releases
Eclipse Public License 2.0
192 stars 32 forks source link

building for termux on android #746

Open numberokta opened 7 months ago

numberokta commented 7 months ago

I want to build ksh93 for termux on android but it gives me this error (compiling with clang)

+ cc -D_BLD_DLL -fPIC -D_BLD_ast -Os -I. -I/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast -Icomp -I/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp -Iinclude -I/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/include -Istd -I/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/std -c /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:103:17: error: call to undeclared function 'catopen'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  103 |                 if (s && (d = catopen(s, flag)) != (nl_catd)(-1) || !(s = 0) && (d = catopen(name, flag)) != (nl_catd)(-1))
      |                               ^
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:103:15: error: incompatible integer to pointer conversion assigning to 'nl_catd' (aka 'void *') from 'int' [-Wint-conversion]
  103 |                 if (s && (d = catopen(s, flag)) != (nl_catd)(-1) || !(s = 0) && (d = catopen(name, flag)) != (nl_catd)(-1))
      |                             ^ ~~~~~~~~~~~~~~~~
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:103:70: error: incompatible integer to pointer conversion assigning to 'nl_catd' (aka 'void *') from 'int' [-Wint-conversion]
  103 |                 if (s && (d = catopen(s, flag)) != (nl_catd)(-1) || !(s = 0) && (d = catopen(name, flag)) != (nl_catd)(-1))
      |                                                                                    ^ ~~~~~~~~~~~~~~~~~~~
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:107:5: error: call to undeclared function 'catclose'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  107 |                                 catclose(d);
      |                                 ^
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:115:6: error: call to undeclared function 'catclose'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  115 |                                         catclose(d);
      |                                         ^
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:148:16: error: call to undeclared function 'catgets'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  148 |                 msg = (char*)catgets(((Cc_t*)cat)->cat, set, num, msg);
      |                              ^
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:148:9: warning: cast to 'char *' from smaller integer type 'int' [-Wint-to-pointer-cast]
  148 |                 msg = (char*)catgets(((Cc_t*)cat)->cat, set, num, msg);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/src/lib/libast/comp/catopen.c:175:10: error: call to undeclared function 'catclose'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  175 |                 return catclose(((Cc_t*)cat)->cat);
      |                        ^
1 warning and 7 errors generated.
mamake [lib/libast]: *** exit code 1 making catopen.o
mamake: *** exit code 1 making lib/libast
mamake: *** exit code 1 making all
package: make failed at Fri Apr 19 11:14:10 +0330 2024 in /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh-1.0.8/arch/linux.arm64-64

See full build log here

McDutchie commented 7 months ago

Thanks for the report. This should already have been fixed in commit c3fec93fd7ea16feea53d52901c3d1edf7293a70, so the upcoming 1.0.9 release should build on Termux. In the meantime, please try building the current git code and let me know if it works for you:

git clone -b 1.0 https://github.com/ksh93/ksh
cd ksh
bin/package make
bin/package use
numberokta commented 7 months ago

Thanks for your replay, I tested that and it gives this error

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: libandroid_shmget
>>> referenced by /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64/dyn/lib/libast.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: libandroid_shmat
>>> referenced by /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64/dyn/lib/libast.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: libandroid_shmdt
>>> referenced by /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64/dyn/lib/libast.so

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: libandroid_shmctl
>>> referenced by /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64/dyn/lib/libast.so
cc: error: linker command failed with exit code 1 (use -v to see invocation)
mamake [cmd/builtin]: *** exit code 1 making /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64/dyn/bin/pty
mamake: *** exit code 1 making cmd/builtin
mamake: *** exit code 1 making all
package: make failed at Fri Apr 19 19:08:06 +0330 2024 in /data/data/com.termux/files/home/neuctl/build/termux/ksh/ksh/arch/android.arm64-64
McDutchie commented 7 months ago

Strange. I cannot reproduce that at all. :(

What Android version are you using, and what version of termux, and what version of clang, and did you set CCFLAGS and/or LDFLAGS, and if so, to what values?

numberokta commented 7 months ago

That error happened on Termux 0.118.0+8e3a898 Now i tested with this Android 13 Termux 0.118.0+2f40df9 env: TERMUX_APP__TARGET_SDK="28"

clang -v
Clang version 18.1.3
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin

I didn't set CCFLAGS and/or LDFLAGS It gives me error (log file) I think the issue is related to the target because i saw --target=armv8l-linux-android26 in log file

McDutchie commented 4 months ago

I'm now running an Android 13.0 arm64 VM in Android Studio and I'm finding that ksh builds and runs without a hitch. The clang version on it is 18.1.8, though. And of course I'm using a fresh installation. The only packages I installed in termux apart from the defaults are: clang, binutils, getconf, git, ncurses-utils (and their dependencies) -- that's all ksh needs to build and run.

I've looked at your log. The problem appears to be that it can't find certain essential termux libraries (crtbegin_dynamic.o, libunwind.a, crtend_android.o). I am unable to reproduce this problem. (Exporting TERMUX_APP__TARGET_SDK="28" makes no difference.)

I'm guessing that either something is broken in your termux installation, or some other package that I've not installed is somehow interfering. But I have no way of knowing what it is. I also don't know if it makes a difference that you're building on a 32-bit ARM processor, which I cannot test here.

Would it be possible for you try building with a fresh and updated termux installation with just pkg install clang binutils getconf git ncurses-utils and nothing else done to it?