Thanks! To build nim on Termux, I had to patch config/nim.cfg and 
csources/makefile - see below.

`uname` returns Linux, only `uname -o` returns Android.

Currently I have hijacked the `unix` target by adding `-landroid-glob -latomic` 
to the linker flags. But this will probably fail for a non-Android Linux since 
there isn't libandroid-glob. So, for a clean patch, I would have to know how I 
can find out the value of `uname -o` within `nim.cfg`

Similar fixes have to be applied in csources/makefile where I could exec `uname 
-o`

Furthermore on my Tablet, `uname -m` reports `armv8l` which isn't accounted for 
in csources/makefile.

For the record, here is my recipe to build Nim on Termux 
    
    
    git clone https://github.com/nim-lang/Nim.git
    pushd Nim
    git clone -q --depth 1 https://github.com/nim-lang/csources.git
    patch -p0 < ../nim.cfg.patch
    patch -p0 < ../csources.patch
    ./build_all.sh
    for X in bin/{nim,nimble,nimgrep,nimsuggest,nimfind,nimpretty,testament}; do
      cp $X $PREFIX/bin
    done
    
    
    Run

with `nim.cf.patch` containing 
    
    
    --- config/nim.cfg.Orig     2020-11-12 21:01:55.772997865 +0100
    +++ config/nim.cfg  2020-11-12 21:04:01.402997775 +0100
    @@ -113,10 +113,10 @@
     @if unix:
       @if not bsd or haiku:
         # -fopenmp
    -    gcc.options.linker = "-ldl"
    -    gcc.cpp.options.linker = "-ldl"
    -    clang.options.linker = "-ldl"
    -    clang.cpp.options.linker = "-ldl"
    +    gcc.options.linker = "-ldl -landroid-glob -latomic"
    +    gcc.cpp.options.linker = "-ldl -landroid-glob -latomic"
    +    clang.options.linker = "-ldl -landroid-glob -latomic"
    +    clang.cpp.options.linker = "-ldl -landroid-glob -latomic"
         tcc.options.linker = "-ldl"
       @end
       @if bsd:
    
    
    Run

and `csources.patch` contains 
    
    
    --- csources/makefile.Orig  2020-11-13 11:48:32.222648732 +0100
    +++ csources/makefile       2020-11-13 11:32:31.795701655 +0100
    @@ -22,8 +22,14 @@
     endif
     
     ifeq ($(uos),linux)
    -  myos = linux
    -  LDFLAGS += -ldl -lm
    +  los := $(shell sh -c 'uname -o| tr "[:upper:]" "[:lower:]"')
    +  ifeq ($(los),android)
    +    LDFLAGS += -ldl -lm -landroid-glob -latomic
    +    myos = android
    +  else
    +    LDFLAGS += -ldl -lm
    +    myos = linux
    +  endif
     endif
     ifeq ($(uos),dragonfly)
       myos = freebsd
    @@ -146,6 +152,9 @@
     ifeq ($(ucpu),armv7hl)
       mycpu = arm
     endif
    +ifeq ($(ucpu),armv8l)
    +  mycpu = arm
    +endif
     ifeq ($(ucpu),aarch64)
       mycpu = arm64
     endif
    --- csources/build.sh.Orig  2020-11-13 12:50:10.675444931 +0100
    +++ csources/build.sh       2020-11-13 12:59:48.691413080 +0100
    @@ -71,6 +71,13 @@
     # convert to lower case:
     ucpu=`echo $`ucpu | tr "[:upper:]" "[:lower:]"`
     uos=`echo $uos | tr "[:upper:]" "[:lower:]"`
    +if [ "$uos" = "linux" ] ; then
    +  los=`uname -o`
    +  los=`echo $los | tr "[:upper:]" "[:lower:]"`
    +  if [ "$los" = "android" ] ; then
    +    uosname="android"
    +  fi
    +fi
     uosname=`echo $uosname | tr "[:upper:]" "[:lower:]"`
     
     case $uos in
    @@ -121,7 +128,7 @@
       *android* )
         myos="android"
         LINK_FLAGS="$LINK_FLAGS -ldl -lm -lrt"
    -    LINK_FLAGS="$LINK_FLAGS -landroid-glob"
    +    LINK_FLAGS="$LINK_FLAGS -landroid-glob -latomic"
         ;;
       *)
         echo 2>&1 "Error: unknown operating system: $uos"
    
    
    Run

Reply via email to