Is your feature request related to a problem? Please describe.
Background, context. I'm using Termux on an Android device to make Android apps in Android itself, for various reasons, including an exercise in learning, a "fun constraint", morbid curiousity, poverty, disability/accessibility, spiteful resentment of Google's HEAVY, PC-centric oppressive bias, closed-source, rottenly documented tools, as well as disdain for the ecosystem of closed-source, paid SaaS, like ReactNative/expo, and others. Thus far, I've been able to build and install a basic "Hello World" app, with additional "Hello World" accessed via JNI to C. Further, I cross compiled this trivial C library as a .so for both aarch64 and armv7a, assembled in a single .apk file (in directories lib/arm64-v8a and lib/armeabi-v7a, respectively), and tested on both hardware devices (aarch64 Android 12, armv7l ['el' not 'one'] Android 5).
This brings me to my next phase. How do I cross compile libcalc as a .so on aarch64 for armv7a? That's a lot to unpack. Yes, the Termux project has compiled and packaged calc (thus libcalc) for Android, which is how I learned about calc. I could just copy the .so files (I'm aware of the possible libcalc dependency on other .so's, not ignoring, just deferring concern). However, it besides "cheating", it doesn't help if I'm trying to compile for armv7a. Nor does it help if I am on a Linux or Windows PC (say AMD or Intel x64 or server CPU), either physically or remotely, and wish to cross compile libcalc.so for aarch64 and armv7a.
In Termux, when I compile calc from unmodified source using the minimum commands (just make
or make -f Makefile
), I see gcc
is chosen, and there are lots of errors, and something ends in failure, yet there are some compiled binary executables and libs.
First problem, Google officially dropped gcc on Android years ago due primarily to GPL licensing and also cited project management issues as a (possibly bogus) excuse. While there is an unofficial, quasi-maintained patch to gcc within Termux, itself an unofficial, sporadically maintained set of patches, that gcc can be a source of untold errors. It seems to work fine, on simple programs, but who knows? Clang is far more supported on Android in Termux. Using clang --target arm64-linux-android24
(redundant when I'm on the device) and clang --target armv7a-linux-androideabi24
(with -fPIC -shared) seems to get the .so format that makes the Java/Android subsystem happy when calling System.loadLibrary().
I'm having difficulty knowing what command line options and/or variables to set, and/or if/what parts of the Makefile need to be modified to properly detect the Termux build environment, and how to build ONLY the libraries.
uname -s is Linux
uname -p is unknown
uname -m is aarch64
uname -o is Android (but this is stored in a variable named MINGW, ugh! hould be OS or OSNAME or something, an os-neutral variable name)
Describe the solution you'd like
I think I already have the ability to build the library, but ut seems to ONLY allow building shared library .so not only the .a libraries? I don't think I need .a only right now, but it seemed odd to lack that granularity of control.
I'm not sure if the code checks can be run to test libraries only, or if that requires the full command line utility to be built in order to run the tests. Separate lib-only tests would be nice, to isolate command line bugs from library bugs. Maybe it doesn't yield enough benefit for the effort? Clarity on this point?
I'd like to see, at a bare minimum, Android/Termux properly identified, clang chosen.
I'd really like to be able to specify cross-compilation, not assume that the current build-CPU arch is the only arch in the universe.
I'd really, really like to be able to specify multiple targets for cross compilation, run a single build command, and collect the binaries. I can manage via scripting (shell or Python) as an interim workaround (loop for each target, clean/clobber, build, copy, next).
It'd be nice to have a CMake build system, to manage these sorts of things. I'll let Santa, the Easter Bunny, and the Tooth Fairy know. I'm sure they'll get right on that. :o) But seriously, has this been considered, discussed? Is there a conversation somewhere that I may have missed? If so, direct me there. I'm curious about feasability, specific concerns, particularly regarding complex dependency issues between
Makefile, Makefile.ship and custom/Makefile` which are currently blocking parallel builds, possibly blocking cross compilation and multi-target builds. Does CMake offer easier access to these features? As well as the boilerplate utility and OS testing, which may make a large portion of existing Makefile redundant?
Finally, I'd eventually like to have my Android calculator app build on Linux proper, as well as Windows under WSLv2, MinGW/MSYS (implies Cygwin, sort of), and maybe one day if possible Visual Studio Build Tools (command line C preprocessor, C compiler, library linker), though I'm not optimistic about ARM cross compilation with freely available tools from MS (they tend to charge money for advanced features and then rabidly vendor-lock in a limited subset of environments), but who knows, I may be ignorant, hence the exploration of possibility.
Describe alternatives you've considered
make calc-dynamic-only LCC=clang CFLAGS="--target=arm64-linux-android24" BLD_TYPE=calc-dynamic-only
forming have_limits.h
have_limits.h formed
forming have_ban_pragma.h
have_ban_pragma.h formed
forming charbit.h
charbit.h formed
forming have_unistd.h
have_unistd.h formed
forming have_stdlib.h
have_stdlib.h formed
forming longbits.h
longbits.h formed
forming align32.h
align32.h formed
forming have_string.h
have_string.h formed
forming args.h
args.h formed
forming calcerr.h
calcerr.h formed
forming conf.h
conf.h formed
forming endian_calc.h
endian_calc.h formed
forming have_fpos.h
have_fpos.h formed
forming have_posscl.h
have_posscl.h formed
forming have_fpos_pos.h
have_fpos_pos.h formed
forming have_offscl.h
have_offscl.h formed
forming have_newstr.h
have_newstr.h formed
forming have_memmv.h
have_memmv.h formed
forming fposval.h fposval.h formed
forming have_const.h have_const.h formed forming have_getpgid.h
have_getpgid.h formed
forming have_getprid.h
have_getprid.h formed
forming have_getsid.h
have_getsid.h formed
forming have_gettime.h
have_gettime.h formed
forming have_rusage.h
have_rusage.h formed
forming have_strdup.h
have_strdup.h formed
forming have_strlcat.h
have_strlcat.h formed
forming have_strlcpy.h
have_strlcpy.h formed
forming have_times.h
have_times.h formed
forming have_uid_t.h
have_uid_t.h formed
forming have_unused.h
have_unused.h formed
forming have_urandom.h
have_urandom.h formed
forming have_ustat.h
have_ustat.h formed
forming terminal.h
terminal.h formed
forming have_environ.h
have_environ.h formed
forming have_arc4random.h
have_arc4random.h formed
forming calcerr.c
calcerr.c formed
rm -f custom/.all
cd custom; make -f Makefile ALLOW_CUSTOM="-DCUSTOM" AR="ar" ARCH_CFLAGS="" AWK="awk" BINDIR="/usr/bin" BLD_TYPE="calc-dynamic-only" CALC_INCDIR="/usr/include/calc" CALC_SHAREDIR="/usr/share/calc" CAT="cat" CC=" clang " CCBAN="-UUNBAN" CCERR="" CCMISC="" CCOPT="-O3 -g3" CCWARN="-Wall -Wextra -pedantic" CC_SHARE="-fPIC" CFLAGS="--target=arm64-linux-android24 -I.." CHMOD="chmod" CMP="cmp" CO="co" COMMON_ADD="" COMMON_CFLAGS="-DCALC_SRC -DCUSTOM -Wall -Wextra -pedantic -I.." COMMON_LDFLAGS=" " CP="cp" CUSTOMCALDIR="/usr/share/calc/custom" CUSTOMHELPDIR="/usr/share/calc/custhelp" CUSTOMINCDIR="/usr/include/calc/custom" DEBUG="-O3 -g3" DEFAULT_LIB_INSTALL_PATH="/data/data/com.termux/files/home/dev/calc-2.14.1.0:/lib:/usr/lib:/usr/lib:/usr/local/lib" DIFF="diff" E="2>/dev/null" FMT="fmt" GREP="egrep" H="@" HELPDIR="/usr/share/calc/help" ICFLAGS="-DCALC_SRC -DCUSTOM -Wall -Wextra -pedantic -UUNBAN -fPIC -I.." ILDFLAGS=" " INCDIR="/usr/include" LANG="C" LCC="clang" LDCONFIG="ldconfig" LDFLAGS=" " LD_SHARE=""-Wl,-rpath,/data/data/com.termux/files/home/dev/calc-2.14.1.0:/lib:/usr/lib:/usr/lib:/usr/local/lib" "-Wl,-rpath-link,/data/data/com.termux/files/home/dev/calc-2.14.1.0:/lib:/usr/lib:/usr/lib:/usr/local/lib"" LIBCUSTCALC_SHLIB="-shared "-Wl,-soname,libcustcalc.so.2.14.1.0"" LIBDIR="/usr/lib" LN="ln" LS="ls" MAKE="make" MAKEDEPEND="makedepend" MAKE_FILE=Makefile MKDIR="mkdir" MV="mv" MINGW="Android" PREFIX="/usr/local" PURIFY="" Q="@" RANLIB="ranlib" RM="rm" RMDIR="rmdir" S=">/dev/null 2>&1" SCRIPTDIR="/usr/bin/cscript" SED="sed" SHELL="/bin/bash" SORT="sort" T="" TAIL="tail" TOUCH="touch" TRUE="true" V="@:" VERSION="2.14.1.0" WNO_IMPLICT="-Wno-implicit" WNO_ERROR_LONG_LONG="-Wno-error=long-long" WNO_LONG_LONG="-Wno-long-long" target="Linux" all
make[1]: Entering directory '/data/data/com.termux/files/home/dev/calc-2.14.1.0/custom'
clang --target=arm64-linux-android24 -I.. -c -o custtbl.o custtbl.c
In file included from custtbl.c:30:
In file included from ../value.h:42: /data/data/com.termux/files/usr/include/calc/decl.h:29:10: fatal error: 'calc/have_const.h' file not found
#include "calc/have_const.h"
^~~~~~~~~~~~~~~~~~~
1 error generated.
make[1]: *** [<builtin>: custtbl.o] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/dev/calc-2.14.1.0/custom'
make: *** [Makefile:4373: custom/.all] Error 2
Additional context
I used bc
for nearly 3 decades. Then I found that it couldn't do decimal exponentiation. Then I found GMP but it has no CLI. Then I found calc via Termux package system, and it has a CLI, a library, and handles decimal exponentiation. Used this for a couple years. Then I had the (dumb, crazy, fun) idea to make a calculator app, after my old propietary app started spying. Existing Android build processes depend way too much on bloated, buggy, exponentially complex, proprietary nonsense. So I decided to build on Android in Termux using only bash, vim, openjdk's javac, jar, and keytool, android.jar, and whatever other build tools are necessary, like aapt2, d8 (DEX v8), 7z (or Info-Zip's zip would work), zipalign, apksigner, later, clang and llvm-strip, eventually git to publish on GitHub. I looked again at GMP and it was highly recommended by a friend, but the exponentiation functions only handle integers, meaning a fair bit of cooking the decomal into reduced rational form and doing many steps, common tasks which belong in a library as utility wrappers, which GMP is uninterested in. Also, I find that some of GMPs other decimal functions provide little or no better accuracy than IEEE 754 with its rounding errors. Hence the need to also use the MPFR library for all floating points. Ok. But the current release is 4.x. There's a Java binding library for MPFR but only v3.x. So I'd have to do the Android to JNI to C wrappers myself, straightforward, hopefully. MPFR lists aarch64-unknown-linux-gnu (gcc 8.5.0 and 12.2.0, clang 15.0.4 on Termux/Android, tcc mob branch);
as the very first supported platform, with both gcc and clang testing. It's nice to be placed as a first class platform, rather than an annoyance to be dismissed. My phone and old desktop PC are nearly equal in power. If my truck breaks down, I can use my phone to get help. I can't make a phone call by telepathic link to my desktop and then VOIP from my desktop. Can only afford one upgrade. Needed to delay desktop/laptop upgrade. Also, disability randomly makes sitting at desk impossible, sometimes for weeks at a time. It's easier to hold a 4oz phone in my hand while reclining, than an 80lb computer (including all peripherals). Sure, it'd be nice to afford a big enough room to live in and afford a large reclining chair with computer, monitor, and keyboard/mouse mounts, but see constraint above regarding computer upgrade. Even a laptop would honestly be very difficult to use. A tablet might be better, but can't call for help if I fall, get stuck, or car breaks down, or illness temporarily impairs ability to get to landline phone. Hence why I ended up on Android as my "primary" platform. All of that's no reason to stop learning and trying to build things. :o)