diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-11-23 16:09:08 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-04-15 13:34:54 +0200 |
commit | 098523b825c14184592a8717c2c3becbf6bc3f9f (patch) | |
tree | 691cce5484bb2a63555e688a5bfad8fda7585e70 /configure | |
parent | 1bf2694303843192e7098876c0fc709307eece65 (diff) |
Switch from meson to configure+make.
Meson is an extra dependency and generally sucks.
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/configure b/configure new file mode 100755 index 0000000..a2dfa88 --- /dev/null +++ b/configure @@ -0,0 +1,154 @@ +#!/bin/bash +# mg2d configure script +# partially inspired by/based on the FFmpeg configure script + +die() { + echo "$@" >&2 + exit 1 +} + +bootstrap() { + local source_dir + + [ -e configure ] && die "Cannot build from the source dir, create a separate build directory" + + source_dir=$(realpath $(dirname "$0")) + [ -d "$source_dir" ] || die "Cannot locate source directory" + + [ -h src ] || ln -s "$source_dir" src + + [ -h Makefile ] || ln -s "$source_dir/Makefile" + + echo $source_dir +} + +toupper() { + echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ +} + +is_in() { + value=$1 + shift + for var in $*; do + [ $var = $value ] && return 0 + done + return 1 +} + +probe_arch() { + arch=$(cc -dumpmachine | sed 's/-.*//') +} + +check_mpi() { + pkg-config --exists mpi || return 1 + mpi_cflags=$(pkg-config --cflags mpi) + mpi_libs=$(pkg-config --libs mpi) +} + +check_nasm() { + if ! command -v nasm &> /dev/null; then + echo "nasm not found, assembly code will not be built" + return 1 + fi +} + +check_component() { + name=$1 + shift + eval "check_$name" $@ && eval "have_$name=yes" +} + +source_dir=$(bootstrap) + + +CMDLINE_SET=" + cc +" + +cc=cc + +for arg; do + name="${arg%%=*}" + name="${name#--}" + name=$(echo "$name" | sed 's/-/_/g') + + val="${arg#*=}" + + if is_in $name $CMDLINE_SET; then + eval $name='$val' + continue + fi + + die "Unknown commandline argument: $name $val" +done + +probe_arch + +COMPONENTS_REQUIRED=" + mpi +" + +COMPONENTS_OPTIONAL=" + nasm +" + +COMPONENTS=" + $COMPONENTS_REQUIRED + $COMPONENTS_OPTIONAL +" + +for c in $COMPONENTS_REQUIRED; do + check_component $c || die "Required component $c not found" +done + +for c in $COMPONENTS_OPTIONAL; do + check_component $c +done + +cat > config.mak <<EOF +SOURCE_DIR = $source_dir +CC = $cc +CFLAGS_DEP = $mpi_cflags +LDFLAGS_DEP = $mpi_libs +EOF + +cat > config.h <<EOF +#ifndef MG2D_CONFIG_H +#define MG2D_CONFIG_H + +EOF + +cat > config.asm << EOF +EOF + +case "$arch" in + x86_64) + echo "ARCH_X86_64 = 1" >> config.mak + echo "#define ARCH_X86_64 1" >> config.h + echo "%define ARCH_X86_64 1" >> config.asm + ;; + *) + echo "ARCH_X86_64 = 0" >> config.mak + echo "#define ARCH_X86_64 0" >> config.h + echo "%define ARCH_X86_64 0" >> config.asm + ;; +esac + +for c in $COMPONENTS; do + C=$(toupper $c) + have_ref=have_$c + + if [ -n "${!have_ref}" ]; then + val_mak=yes + val_c=1 + else + val_mak=no + val_c=0 + fi + + echo "HAVE_$C = $val_mak" >> config.mak + echo "#define HAVE_$C $val_c" >> config.h + +done + +echo "#endif // MG2D_CONFIG_H" >> config.h |