美文网首页
交叉编译shell脚本常用的写法

交叉编译shell脚本常用的写法

作者: mapleSeriesX | 来源:发表于2019-11-08 10:56 被阅读0次

多种写法 在备注后面,注意使用./configure --help查看根据需求调整
[1]

#!/bin/bash
function build_xxx
{
./configure \
--prefix=$PREFIX \#编译后的文件的安装目录
--host=$CPU-linux \#编译后使用文件的平台
--disable-shared \#不需要动态库 多种写法 --disable-shared=yes \  --enable-shared=no \
--enable-static \# 需要静态库  --enable-static=yes \ --disable-static=no \
--disable-asm \#兼容低版本,不使用汇编代码
--enable-pic \#android使用的交叉编译不能让代码段引用的数据对象重定位 --with-pic \ 
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \#gcc交叉编译工具目录
--sysroot=$SYSROOT \#gcc编译头文件搜索目录
--cflags="-fPIC"# 如果没有 --enable-pic 选项 需要加这个标记  --extra-cflags  "-O0  -fPIC" "-Os  -fpic"
#也可以复制AS中 项目目录/app/.cxx/cmake/debug/armeabi-v7a/build.ninja 中的 FLAGS加以修改
#FLAGS="-isysroot $NDK_ROOT/sysroot -isystem $NDK_ROOT/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=17 
#-g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes
# -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -
#Werror=format-security -std=c++11  -O0  -fPIC" 
make clean 
make install
}

#CPU架构 不含bit
CPU=x86
#CPU架构 包含bit
ARCH=x86
#编译后的文件的安装目录
PREFIX=$(pwd)/android/$ARCH
#编译动/静态库使用的版本
PLATFORM_VERSION=android-17
#gcc编译头文件搜索目录
SYSROOT=$NDK_ROOT/platforms/$PLATFORM_VERSION/arch-$ARCH/
#gcc交叉编译工具链目录
TOOLCHAIN=$NDK_ROOT/toolchains/x86-4.8/prebuilt/linux-x86_64
#gcc交叉编译工具目录 这里不需要-是因为 export CC中需要用到这个变量连接-gcc [1]第四点
#通常需要- 参考上面--cross-prefix
CROSS_COMPILE=$TOOLCHAIN/bin/i686-linux-android
#没有--cross-prefix  --sysroot 选项的时候 使用环境变量引入 具体查看configure
export CC="$CROSS_COMPILE-gcc --sysroot=$SYSROOT"
build_xxx


CPU=arm
ARCH=arm
PREFIX=$(pwd)/android/$ARCH
PLATFORM_VERSION=android-17
SYSROOT=$NDK_ROOT/platforms/$PLATFORM_VERSION/arch-$ARCH/
TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi
export CC="$CROSS_COMPILE-gcc --sysroot=$SYSROOT"
build_xxx

CPU=arm
ARCH=arm64
PREFIX=$(pwd)/android/$ARCH
PLATFORM_VERSION=android-21#最低21才支持arm64
SYSROOT=$NDK_ROOT/platforms/$PLATFORM_VERSION/arch-$ARCH/
TOOLCHAIN=$NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-android
export CC="$CROSS_COMPILE-gcc --sysroot=$SYSROOT"
build_xxx

相关文章

网友评论

      本文标题:交叉编译shell脚本常用的写法

      本文链接:https://www.haomeiwen.com/subject/svsibctx.html