#!/bin/bash
U32=0 #编译64位arm时 U32=0 编译32位arm时 U32=1 其他参数不需要变动
TARGET=android-24
HOST=darwin-x86_64
TOOL=aarch64-linux-android #arm-linux-androideabi aarch64-linux-android
ARCH=arch-arm64 #arch-arm arch-arm64
if [ $U32 -ne 0 ]; then
echo "32位arm"
TOOL=arm-linux-androideabi
ARCH=arch-arm
fi
TOOLCHAIN=$TOOL-4.9
export NDK_ROOT=/Users/musictom/Library/Android/sdk/ndk-bundle/
export SYSROOT="$NDK_ROOT/platforms/$TARGET/$ARCH"
export CPPFLAGS="-I$NDK_ROOT/platforms/$TARGET/$ARCH/usr/include -I$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include"
export LDFLAGS="-L$NDK_ROOT/platforms/$TARGET/$ARCH/usr/lib --sysroot=$SYSROOT"
rm -f *.so *.o
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -Wall -fPIC -O2 -c ../c/inet/libinetsocket.c $CPPFLAGS
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -Wall -fPIC -O2 -c ../c/unix/libunixsocket.c $CPPFLAGS
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -shared -o libsocket.so libinetsocket.o libunixsocket.o $LDFLAGS
rm -f *.o
cp *.so $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/lib/
mkdir $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket
cp ../headers/*.hpp $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket/
cp ../headers/*.h $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket/
参考https://github.com/gcesarmza/curl-android-ios/blob/master/curl-compile-scripts/build_Android.sh
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步