Skip to content

Instantly share code, notes, and snippets.

@enh
Created June 14, 2017 00:37
Show Gist options
  • Save enh/eb7c75e9a82d87bc18cac6a8f5a06d27 to your computer and use it in GitHub Desktop.
Save enh/eb7c75e9a82d87bc18cac6a8f5a06d27 to your computer and use it in GitHub Desktop.
ndkports
#!/bin/bash
set -eu
package_name=$1
if [ "$package_name" == "all" ]; then
for p in `ls ports`; do
echo "-----------------------------------"
echo "$p"
echo "-----------------------------------"
$0 $p || echo FAILED
done
exit
fi
# TODO: should come from command-line.
target_arch=arm64
target_host=aarch64-linux-android
#target_arch=arm
#target_host=arm-linux-androideabi
# ------------------------------------------------------------------------------------------------
# Optional things that can be overridden by pkg_info.
# ------------------------------------------------------------------------------------------------
PACKAGE_CFLAGS=""
PACKAGE_CONFIGURE_ARGS=""
PACKAGE_LDFLAGS=""
ndkports_pre_configure() {
return
}
# ------------------------------------------------------------------------------------------------
# Find out what we're building.
# ------------------------------------------------------------------------------------------------
source ports/$package_name/pkg_info
out_dir=$PWD/.out/$package_name
src_dir=$out_dir/package
package_cache=$PWD/.out/.packages
package_filename=$package_cache/$package_name
# ------------------------------------------------------------------------------------------------
# Set up cross-compiling standalone toolchain.
# ------------------------------------------------------------------------------------------------
toolchain=$PWD/toolchain
if [ ! -d "$toolchain" ]; then
echo "Building toolchain..."
$ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py \
--unified-headers \
--arch "$target_arch" \
--api 26 \
--install-dir="$toolchain" \
else
echo "Toolchain already built"
fi
export PATH=$PATH:$toolchain/bin
export CFLAGS="-fPIE -fPIC $PACKAGE_CFLAGS"
export LDFLAGS="-pie $PACKAGE_LDFLAGS"
export AS=$target_host-ar
export AS=$target_host-clang
export CC=$target_host-clang
export CPP=$target_host-cpp
export CXX=$target_host-clang++
export LD=$target_host-ld
export STRIP=$target_host-strip
# ------------------------------------------------------------------------------------------------
# Download and extract the source.
# ------------------------------------------------------------------------------------------------
if [ ! -d $out_dir ]; then
mkdir -p $out_dir
fi
if [ ! -d $package_cache ]; then
mkdir -p $package_cache
fi
if [ ! -f "$package_filename" ]; then
echo "Downloading $PACKAGE_URL..."
wget -O $package_filename $PACKAGE_URL
else
echo "$PACKAGE_URL already downloaded"
fi
if [ ! -d "$src_dir/$package_name-$PACKAGE_VERSION" ]; then
echo "Extracting..."
mkdir -p $src_dir
tar xf $package_filename -C $src_dir || unzip -d $src_dir $package_filename
else
echo "Archive $package_filename already unpacked into $src_dir"
fi
# ------------------------------------------------------------------------------------------------
# Configure.
# ------------------------------------------------------------------------------------------------
cd $src_dir/$package_name-$PACKAGE_VERSION
if [ ! -f "config.log" ]; then
echo "Configuring..."
ndkports_pre_configure
./configure --host=$target_host $PACKAGE_CONFIGURE_ARGS
#bash_cv_getcwd_malloc=yes
else
echo "Re-using configuration"
fi
# ------------------------------------------------------------------------------------------------
# Build.
# ------------------------------------------------------------------------------------------------
echo "Building..."
make -j32
# ------------------------------------------------------------------------------------------------
# TODO: Collect up the binaries for installation.
# ------------------------------------------------------------------------------------------------
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment