
I'm taking a page from Dolphin's book, and including copies of each dependency's source code. This combines the ease of use of including pre-built libraries instead of needing to navigate a package manager - as is (or was) the case for MSVC - with the portability of using packages. Granted, this method's more of a jack of all trades, master of none, since it's *less* user-friendly than prebuilt packages (compilation times), and you don't get the per-distro compatibility fixes you'd get from a package manager. You can still use system libs if you want. In fact, it's still the default behaviour: compiling the libs manually is just a fallback. I'll add an option to force-enable this soon, however, since it's a nicer way to produce static MSYS2 builds than the hackish nightmare that I was using before. Not to mention, having my own copy of the sources means I can provide my own fixes and tweaks your package manager may not. For example, I can combine MSYS2's FreeType subpixel rendering with vcpkg's fix for SDL2 exporting its symbols in static builds.
100 lines
2.4 KiB
Bash
Executable file
100 lines
2.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
SOURCES=()
|
|
MKSOURCES=""
|
|
CURDIR=`pwd -P`
|
|
|
|
# Fetch sources
|
|
if [[ $# -ge 2 ]]; then
|
|
for src in ${@:2}
|
|
do
|
|
SOURCES+=($src)
|
|
MKSOURCES="$MKSOURCES $(basename $src)"
|
|
done
|
|
else
|
|
if [ -n "$1" ]; then
|
|
while read src
|
|
do
|
|
SOURCES+=($src)
|
|
MKSOURCES="$MKSOURCES $(basename $src)"
|
|
done
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$1" ] || [ -z "$SOURCES" ]; then
|
|
echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
|
|
echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
|
|
echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
|
|
exit 1
|
|
fi
|
|
|
|
SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
|
|
|
|
if [ -z "$ANDROID_HOME" ];then
|
|
echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "$ANDROID_HOME/ndk-bundle" -a -z "$ANDROID_NDK_HOME" ]; then
|
|
echo "Please set the ANDROID_NDK_HOME directory to the path of the Android NDK"
|
|
exit 1
|
|
fi
|
|
|
|
APP="$1"
|
|
APPARR=(${APP//./ })
|
|
BUILDPATH="$SDLPATH/build/$APP"
|
|
|
|
# Start Building
|
|
|
|
rm -rf $BUILDPATH
|
|
mkdir -p $BUILDPATH
|
|
|
|
cp -r $SDLPATH/android-project/* $BUILDPATH
|
|
|
|
# Copy SDL sources
|
|
mkdir -p $BUILDPATH/app/jni/SDL
|
|
if [ -z "$COPYSOURCE" ]; then
|
|
ln -s $SDLPATH/src $BUILDPATH/app/jni/SDL
|
|
ln -s $SDLPATH/include $BUILDPATH/app/jni/SDL
|
|
else
|
|
cp -r $SDLPATH/src $BUILDPATH/app/jni/SDL
|
|
cp -r $SDLPATH/include $BUILDPATH/app/jni/SDL
|
|
fi
|
|
|
|
cp -r $SDLPATH/Android.mk $BUILDPATH/app/jni/SDL
|
|
sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/app/jni/src/Android.mk
|
|
sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/build.gradle
|
|
sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/src/main/AndroidManifest.xml
|
|
|
|
# Copy user sources
|
|
for src in "${SOURCES[@]}"
|
|
do
|
|
cp $src $BUILDPATH/app/jni/src
|
|
done
|
|
|
|
# Create an inherited Activity
|
|
cd $BUILDPATH/app/src/main/java
|
|
for folder in "${APPARR[@]}"
|
|
do
|
|
mkdir -p $folder
|
|
cd $folder
|
|
done
|
|
|
|
ACTIVITY="${folder}Activity"
|
|
sed -i -e "s|\"SDLActivity\"|\"$ACTIVITY\"|g" $BUILDPATH/app/src/main/AndroidManifest.xml
|
|
|
|
# Fill in a default Activity
|
|
cat >"$ACTIVITY.java" <<__EOF__
|
|
package $APP;
|
|
|
|
import org.libsdl.app.SDLActivity;
|
|
|
|
public class $ACTIVITY extends SDLActivity
|
|
{
|
|
}
|
|
__EOF__
|
|
|
|
# Update project and build
|
|
echo "To build and install to a device for testing, run the following:"
|
|
echo "cd $BUILDPATH"
|
|
echo "./gradlew installDebug"
|