Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
leleliu008 committed Jan 20, 2025
1 parent 1b28ede commit cba89af
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 93 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Please read these caveats carefully before starting to use this software.
|[GNU/Linux](https://www.gnu.org/gnu/linux-and-gnu.en.html)|`x86_64`||✔︎|✔︎|✔︎|
|[Windows](https://www.microsoft.com/en-us/windows/)|`x86_64`|[WSL](https://docs.microsoft.com/en-us/windows/wsl/)||||
|[macOS](https://www.apple.com.cn/mac/)|`x86_64` `arm64`|||✔︎||
|[Android](https://www.apple.com.cn/mac/)|`aarch64`|[Termux](https://termux.dev/)||✔︎||

**Notes** :

Expand Down
193 changes: 100 additions & 93 deletions ndk-pkg
Original file line number Diff line number Diff line change
Expand Up @@ -5434,84 +5434,108 @@ $PACKAGE_ONSTART
if [ -f "$TOOLCHAIN_CONFIG_NATIVE" ] ; then
. "$TOOLCHAIN_CONFIG_NATIVE"
else
if [ "$NATIVE_PLATFORM_KIND" = 'darwin' ] ; then
step "locate C/C++ toolchain for native build"

CC_FOR_BUILD="$(xcrun --sdk macosx --find clang)"
OBJC_FOR_BUILD="$(xcrun --sdk macosx --find clang)"
CXX_FOR_BUILD="$(xcrun --sdk macosx --find clang++)"
AS_FOR_BUILD="$(xcrun --sdk macosx --find as)"
AR_FOR_BUILD="$(xcrun --sdk macosx --find ar)"
RANLIB_FOR_BUILD="$(xcrun --sdk macosx --find ranlib)"
LD_FOR_BUILD="$(xcrun --sdk macosx --find ld)"
NM_FOR_BUILD="$(xcrun --sdk macosx --find nm)"
SIZE_FOR_BUILD="$(xcrun --sdk macosx --find size)"
STRIP_FOR_BUILD="$(xcrun --sdk macosx --find strip)"
STRINGS_FOR_BUILD="$(xcrun --sdk macosx --find strings)"
OBJDUMP_FOR_BUILD="$(xcrun --sdk macosx --find objdump)"
SYSROOT_FOR_BUILD="$(xcrun --sdk macosx --show-sdk-path)"

CCFLAGS_FOR_BUILD="-isysroot $SYSROOT_FOR_BUILD -mmacosx-version-min=$NATIVE_PLATFORM_VERS -arch $NATIVE_PLATFORM_ARCH -Qunused-arguments"
LDFLAGS_FOR_BUILD='-Wl,-search_paths_first'
else
step "install C/C++ toolchain for native build"
case $NATIVE_PLATFORM_KIND in
darwin)
step "locate C/C++ toolchain for native build"

CC_FOR_BUILD="$(xcrun --sdk macosx --find clang)"
OBJC_FOR_BUILD="$(xcrun --sdk macosx --find clang)"
CXX_FOR_BUILD="$(xcrun --sdk macosx --find clang++)"
AS_FOR_BUILD="$(xcrun --sdk macosx --find as)"
AR_FOR_BUILD="$(xcrun --sdk macosx --find ar)"
RANLIB_FOR_BUILD="$(xcrun --sdk macosx --find ranlib)"
LD_FOR_BUILD="$(xcrun --sdk macosx --find ld)"
NM_FOR_BUILD="$(xcrun --sdk macosx --find nm)"
SIZE_FOR_BUILD="$(xcrun --sdk macosx --find size)"
STRIP_FOR_BUILD="$(xcrun --sdk macosx --find strip)"
STRINGS_FOR_BUILD="$(xcrun --sdk macosx --find strings)"
OBJDUMP_FOR_BUILD="$(xcrun --sdk macosx --find objdump)"
SYSROOT_FOR_BUILD="$(xcrun --sdk macosx --show-sdk-path)"

CCFLAGS_FOR_BUILD="-isysroot $SYSROOT_FOR_BUILD -mmacosx-version-min=$NATIVE_PLATFORM_VERS -arch $NATIVE_PLATFORM_ARCH -Qunused-arguments"
LDFLAGS_FOR_BUILD='-Wl,-search_paths_first'
;;
linux)
step "install C/C++ toolchain for native build"

if [ -f '/lib/ld-musl-x86_64.so.1' ] && ldd --version 2>&1 | grep -q musl ; then
NATIVE_PLATFORM_LIBC=musl
if [ -f '/lib/ld-musl-x86_64.so.1' ] && ldd --version 2>&1 | grep -q musl ; then
NATIVE_PLATFORM_LIBC=musl

if [ ! -f '/lib64/ld-linux-x86-64.so.2' ] || ! command -v g++ > /dev/null ; then
if [ -f /sbin/apk ] && [ -x /sbin/apk ] ; then
run $sudo /sbin/apk update
run $sudo /sbin/apk add gcompat g++ linux-headers
else
abort 1 'Due to Android NDK for Linux is linked dynamically against glibc, hence you need to install glibc and g++ by yourself for this system'
if [ ! -f '/lib64/ld-linux-x86-64.so.2' ] || ! command -v g++ > /dev/null ; then
if [ -f /sbin/apk ] && [ -x /sbin/apk ] ; then
run $sudo /sbin/apk update
run $sudo /sbin/apk add gcompat g++ linux-headers
else
abort 1 'Due to Android NDK for Linux is linked dynamically against glibc, hence you need to install glibc and g++ by yourself for this system'
fi
fi

CXX_FOR_BUILD="$(command -v g++ || command -v clang++ || command -v c++)" || abort 1 "C++ Compiler for native not found."
CC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
OBJC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
AS_FOR_BUILD="$(command -v as)" || abort 1 "command not found: as"
AR_FOR_BUILD="$(command -v ar)" || abort 1 "command not found: ar"
RANLIB_FOR_BUILD="$(command -v ranlib)" || abort 1 "command not found: ranlib"
LD_FOR_BUILD="$(command -v ld)" || abort 1 "command not found: ld"
NM_FOR_BUILD="$(command -v nm)" || abort 1 "command not found: nm"
SIZE_FOR_BUILD="$(command -v size)" || abort 1 "command not found: size"
STRIP_FOR_BUILD="$(command -v strip)" || abort 1 "command not found: strip"
STRINGS_FOR_BUILD="$(command -v strings)" || abort 1 "command not found: strings"
OBJDUMP_FOR_BUILD="$(command -v objdump)" || abort 1 "command not found: objdump"
OBJCOPY_FOR_BUILD="$(command -v objcopy)" || abort 1 "command not found: objcopy"
READELF_FOR_BUILD="$(command -v readelf)" || abort 1 "command not found: readelf"
else
NATIVE_PLATFORM_LIBC=glibc

uppm about
uppm update
uppm install zig@0.14 binutils

export PATH="$UPPM_HOME/installed/binutils/bin:$PATH"
export ZIG="$UPPM_HOME/installed/zig@0.14/bin/zig"

CXX_FOR_BUILD="$NDKPKG_CORE_DIR/zig-c++"
CC_FOR_BUILD="$NDKPKG_CORE_DIR/zig-cc"
OBJC_FOR_BUILD="$NDKPKG_CORE_DIR/zig-cc"
AS_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/as"
AR_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ar"
RANLIB_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ranlib"
LD_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ld"
NM_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/nm"
SIZE_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/size"
STRIP_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/strip"
STRINGS_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/strings"
OBJDUMP_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/objdump"
OBJCOPY_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/objcopy"
READELF_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/readelf"
fi

CXX_FOR_BUILD="$(command -v g++ || command -v clang++ || command -v c++)" || abort 1 "C++ Compiler for native not found."
CC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
OBJC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
AS_FOR_BUILD="$(command -v as)" || abort 1 "command not found: as"
AR_FOR_BUILD="$(command -v ar)" || abort 1 "command not found: ar"
RANLIB_FOR_BUILD="$(command -v ranlib)" || abort 1 "command not found: ranlib"
LD_FOR_BUILD="$(command -v ld)" || abort 1 "command not found: ld"
NM_FOR_BUILD="$(command -v nm)" || abort 1 "command not found: nm"
SIZE_FOR_BUILD="$(command -v size)" || abort 1 "command not found: size"
STRIP_FOR_BUILD="$(command -v strip)" || abort 1 "command not found: strip"
STRINGS_FOR_BUILD="$(command -v strings)" || abort 1 "command not found: strings"
OBJDUMP_FOR_BUILD="$(command -v objdump)" || abort 1 "command not found: objdump"
OBJCOPY_FOR_BUILD="$(command -v objcopy)" || abort 1 "command not found: objcopy"
READELF_FOR_BUILD="$(command -v readelf)" || abort 1 "command not found: readelf"
else
NATIVE_PLATFORM_LIBC=glibc

uppm about
uppm update
uppm install zig@0.14 binutils

export PATH="$UPPM_HOME/installed/binutils/bin:$PATH"
export ZIG="$UPPM_HOME/installed/zig@0.14/bin/zig"

CXX_FOR_BUILD="$NDKPKG_CORE_DIR/zig-c++"
CC_FOR_BUILD="$NDKPKG_CORE_DIR/zig-cc"
OBJC_FOR_BUILD="$NDKPKG_CORE_DIR/zig-cc"
AS_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/as"
AR_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ar"
RANLIB_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ranlib"
LD_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/ld"
NM_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/nm"
SIZE_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/size"
STRIP_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/strip"
STRINGS_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/strings"
OBJDUMP_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/objdump"
OBJCOPY_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/objcopy"
READELF_FOR_BUILD="$UPPM_HOME/installed/binutils/bin/readelf"
fi
# https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
CCFLAGS_FOR_BUILD="-fPIC -fno-common"
LDFLAGS_FOR_BUILD="-Wl,--as-needed"
;;
android)
step "install C/C++ toolchain for native build"

# https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
CCFLAGS_FOR_BUILD="-fPIC -fno-common"
LDFLAGS_FOR_BUILD="-Wl,--as-needed"
fi
if command -v termux-info > /dev/null && command -v pkg > /dev/null ; then
TERMUX=1
fi

CXX_FOR_BUILD="$(command -v g++ || command -v clang++ || command -v c++)" || abort 1 "C++ Compiler for native not found."
CC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
OBJC_FOR_BUILD="$(command -v gcc || command -v clang || command -v cc)" || abort 1 "C Compiler for native not found."
AS_FOR_BUILD="$(command -v as)" || abort 1 "command not found: as"
AR_FOR_BUILD="$(command -v ar)" || abort 1 "command not found: ar"
RANLIB_FOR_BUILD="$(command -v ranlib)" || abort 1 "command not found: ranlib"
LD_FOR_BUILD="$(command -v ld)" || abort 1 "command not found: ld"
NM_FOR_BUILD="$(command -v nm)" || abort 1 "command not found: nm"
SIZE_FOR_BUILD="$(command -v size)" || abort 1 "command not found: size"
STRIP_FOR_BUILD="$(command -v strip)" || abort 1 "command not found: strip"
STRINGS_FOR_BUILD="$(command -v strings)" || abort 1 "command not found: strings"
OBJDUMP_FOR_BUILD="$(command -v objdump)" || abort 1 "command not found: objdump"
OBJCOPY_FOR_BUILD="$(command -v objcopy)" || abort 1 "command not found: objcopy"
READELF_FOR_BUILD="$(command -v readelf)" || abort 1 "command not found: readelf"
esac

if [ "$DEBUG_CC" = 1 ] ; then
CCFLAGS_FOR_BUILD="$CCFLAGS_FOR_BUILD -v"
Expand Down Expand Up @@ -9020,7 +9044,7 @@ EOF
if [ "$NATIVE_PLATFORM_KIND" = android ] ; then
# use comunity compiled Android NDK for aarch64-linux right now, I might compile my own at some point.
# https://github.com/lzhiyong/termux-ndk/releases/tag/android-ndk
ANDROID_NDK_REVISION='r26b'
ANDROID_NDK_REVISION='r27b'
else
ANDROID_NDK_REVISION='r27c'
fi
Expand Down Expand Up @@ -9832,7 +9856,7 @@ fi
fi
}

NDKPKG_VERSION=0.20.2
NDKPKG_VERSION=0.20.3

NDKPKG_ARG0="$0"
NDKPKG_ARG1="$1"
Expand Down Expand Up @@ -9873,25 +9897,6 @@ if [ -n "$NDKPKG_URL_TRANSFORM" ] ; then
export URL_TRANSFORM="$NDKPKG_URL_TRANSFORM"
fi

unset CURLOPT_DNS_SERVERS

if [ "$(uname -o 2>/dev/null || true)" = Android ] ; then
LV="$(getprop ro.build.version.sdk)"
export UPPM_FORMULA_REPO_URL_OFFICIAL_CORE="https://github.com/fpliu1214/uppm-package-repository-android-$LV-aarch64"

if [ -z "$NDKPKG_DNS_SERVERS" ] ; then
NDKPKG_DNS_SERVERS='1.1.1.1,8.8.8.8'
fi

export CURLOPT_DNS_SERVERS="$NDKPKG_DNS_SERVERS"

if command -v termux-info > /dev/null ; then
TERMUX=1
else
unset TERMUX
fi
fi

##################################################################################

# https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_default_verify_paths.html
Expand Down Expand Up @@ -10055,6 +10060,8 @@ if [ "$NATIVE_PLATFORM_TYPE" = linux ] ; then
fi
fi

unset TERMUX

##################################################################################

if [ "$NATIVE_PLATFORM_EUID" -ne 0 ] ; then
Expand Down

0 comments on commit cba89af

Please sign in to comment.