DynLoad is a cross-platform system for dynamically loading arbitrary libraries.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

270 lines
6.4 KiB

#!/bin/bash
#************
#***CONFIG***
#************
#If CC isn't set, the script will attempt to figure it out itself.
#CC=musl-gcc
#If this isn't set, the script will attempt to find ninja and samu, in that order.
#Alternatives include samurai's "samu"
#NINJA=ninja
#Directories
MDIR=meson
BINDIR=bin
LIBDIR=lib
#***********
#***OSMIA***
#***********
#
# This is osmia, a build script for meson.
#
# Official URL:
# https://git.orangehattech.com/dirkson/osmia
#
#*************
#***LICENSE***
#*************
#
# MIT License
#
# Copyright (c) 2018 Dirkson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#Functions
osmia_help () {
echo "Osmia build script for meson."
echo "Usage: ./build [-mode] [target]"
echo "Target will be passed to ninja directly"
echo "Mode defaults to release, or is one of the following:"
echo "-r OR --release : Builds using Meson's release mode"
echo "-d OR --debug : Builds using Meson's debug mode, with --werror added"
echo "-c OR --clean : Cleans up current project meson/ninja/osmia files"
echo "-a OR --add-san : Clang's address sanitizer"
echo "-w32 OR --win32 : Cross-compile for win32 using $MDIR/win32.txt"
echo "-w OR --win : cross-compile for win64 using $MDIR/win64.txt"
echo "-o OR --osx : cross-compile for OSX"
}
osmia_clean () {
rm -rf $MDIR/release $MDIR/debug $BINDIR $LIBDIR
}
osmia_symlink () {
FILES="$(find $1 -maxdepth 1 -type f $2 2> /dev/null)"
if [ ! -z "$FILES" ]; then
mkdir -p $3 2> /dev/null
rm -rf $3/* 2> /dev/null
for I in $FILES; do
ln -s ../$I $3/
done
fi
}
osmia_get () {
if [ ! -d "$1" ]; then
$2
if [ ! $? -eq 0 ]; then
echo "osmia: git command failed: $1"
exit 1
fi
if [ ! -d "$1" ]; then
echo "osmia: could not find directory: $1"
exit 1
fi
fi
}
#Begin
#If we needed to clean, clean.
if [ -e "$MDIR/osmia/clean" ]; then
osmia_clean
rm $MDIR/osmia/clean
fi
clear
err=0;
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
err=1
echo "osmia: er... Yeah, don't source this file."
return 1
fi
#What type of build?
case "$1" in
-d|-debug|--debug)
DIR=debug
BLD=debug
MESONOPTS="--werror"
;;
-a)
COMPILER="clang"
DIR=debug
BLD=debug
MESONOPTS=-Db_sanitize=address
MESONOPTS="--werror"
;;
-w32|-win32|--win32|-window32|--windows32)
DIR=release
BLD=release
MESONOPTS="--cross-file $MDIR/win32.txt"
;;
-w|-win|--win|--window|--windows|-w64|-win64|--win64|--windows64|--windows64)
DIR=release
BLD=release
MESONOPTS="--cross-file $MDIR/win64.txt"
;;
-c|-clean|--clean)
if [ "$#" -ne 1 ]; then
echo "osmia: you passed additional arguments to clean. I have no idea what you want. Did not clean."
exit 1
fi
osmia_clean
echo "osmia: cleaned."
exit 0
;;
-?|-h|-help|--help)
osmia_help
err=1
;;
-r|--release|*)
DIR=release
BLD=release
;;
esac
#do some basic error checking for the user
if [ -z "$NINJA" ]; then
NINJA=ninja
if [ ! -x "$(command -v $NINJA)" ]; then
NINJA=samu
if [ ! -x "$(command -v $NINJA)" ]; then
echo "osmia: neither ninja nor samu are installed. One of the two is required to build."
echo "osmia: Please install either samurai's samu or ninja-build's ninja."
err=1;
fi
fi
else
if [ ! -x "$(command -v $NINJA)" ]; then
echo "osmia: manually specified ninja command not found"
err=1;
fi
fi
if [ ! -x "$(command -v meson)" ]; then
echo "osmia: meson not installed. The meson build system is required to build, please install.";
err=1;
fi
if [ -z "$CC" ]; then
if [ -x "$(command -v clang)" ]; then
CC="clang"
elif [ -x "$(command -v gcc)" ]; then
CC="gcc"
elif [ -x "$(command -v tcc)" ]; then
CC="tcc"
elif [ -x "$(command -v icc)" ]; then
CC="icc"
else
echo "osmia: unable to find any compiler at all. Please install one: clang, musl-gcc, gcc, tcc, icc"
err=1
fi
else
if [ ! -x "$(command -v $CC)" ]; then
echo "osmia: manually specified compiler does not exist. Failing."
err=1
fi
fi
if [ ! -x "$(command -v ccache)" ]; then
CACHE=""
echo "osmia: ccache not installed. Installing it could speed the build up. Hint Hint."
else
CACHE="ccache"
fi
if [ "$#" -gt 2 ]; then
osmia_help
echo "osmia: failed, too many parameters."
err=1;
fi
#Note: For exit '0' is 'true' and '1' in 'false', in spite of all logic.
if [ $err -ne 0 ]; then
exit 1
fi
#Check if our CC changed. If it did, clean
if [ -e "$MDIR/osmia/cc" ]; then
if [ "$CC" != $(cat $MDIR/osmia/cc) ]; then
echo "osmia: compiler changed. Forced to clean."
osmia_clean
fi
fi
#Grab dependencies
if [ -e $MDIR/dependencies ]; then
cd "$MDIR"
source ./dependencies
cd ../
fi
mkdir -p $MDIR/osmia/ 2> /dev/null
if [ ! -d "$MDIR/$DIR" ]; then
echo $CC > $MDIR/osmia/cc
export CC="$CACHE $CC"
#Run meson if required
mkdir $MDIR/$DIR
meson $MDIR/$DIR $MESONOPTS --buildtype $BLD
if [ ! $? -eq 0 ]; then
#Generally an error here means we need to clean before the next run
tail $MDIR/$DIR/meson-logs/meson-log.txt
touch $MDIR/osmia/clean
echo "osmia: meson returned an error. Please check $MDIR/$DIR/meson-logs/meson-log.txt for more info."
exit 1
fi
#else
#May wish to look into this in the future
#meson configure $MESONOPTS
fi
#Actually build
cd $MDIR/$DIR
$NINJA $2
if [ ! $? -eq 0 ]; then
cd ../../
exit 1
fi
cd ../../
#set up symlinks
osmia_symlink "$MDIR/$DIR/*" "-name *.a -o -name *.so -o -name *.dll" $LIBDIR
osmia_symlink "$MDIR/$DIR/*" "-not -name *.so -not -name *.dll -executable -not -name sanitycheckc.exe" $BINDIR
echo "osmia: successful build."
exit 0