#!/bin/bash

if [ $# -eq 0 ]; then
    echo "No command line parameters are provided. Please enter '$0 -h' to view usage instructions."
    exit 1
fi

if test x"$1" = x"-h" -o x"$1" = x"--help"; then
cat <<EOF

Usage: ./configure [options]

Help:
    -h, --help                  print this message

Standard options:
    -x86_64                     编译x86_64平台的库文件
    -arm                        编译arm32平台的库文件
    -aarch64                    编译aarch64平台的库文件

EOF
exit 1
fi

X264_BUILD_DIR=$(pwd)

# configure
if [[ x"$1" = x"-x86_64" ]];then
    if [ -d x86_64 ]; then
        rm -rf x86_64
    fi
    mkdir -p x86_64/install
    cd x86_64
    ./../x264/configure \
        --prefix="${X264_BUILD_DIR}/x86_64/install" \
        --enable-shared \
        --enable-static \
        --enable-pic \
        --disable-cli \
        --disable-asm

    if [ $? -ne 0 ]; then
        echo "x264 configure failed!"
        exit 1
    fi

    make -j8
    if [ $? -ne 0 ]; then
        echo "x264 make failed!"
        exit 1
    fi

    make install
    if [ $? -ne 0 ]; then
        echo "x264 make install failed!"
        exit 1
    fi

elif [[ x"$1" = x"-arm" ]];then
    echo "compile arm32"
elif [[ x"$1" = x"-aarch64" ]];then
    echo "compile arm64"
else
    echo "parameters error"
fi

# 检查 ./x264/configure 脚本的返回状态
if [ $? -ne 0 ];then
    echo "Exec configure failed!"
    exit 1
fi


