aboutsummaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure137
1 files changed, 137 insertions, 0 deletions
diff --git a/configure b/configure
new file mode 100755
index 0000000..0608b83
--- /dev/null
+++ b/configure
@@ -0,0 +1,137 @@
+#!/usr/bin/env sh
+#
+# Configure script for impl
+#
+
+CONFIGURE_CMD_ARGS="${*}"
+
+PACKAGE_VERSION="0.1.0"
+PACKAGE_DATE="$(date +%Y-%m-%d)"
+PACKAGE_STRING="impl $PACKAGE_VERSION"
+PACKAGE_BUGREPORT="ethan@gweithio.com"
+PACKAGE_URL="https://sixfourtwelve.com/repos/impl.git"
+
+find_program() {
+ varname=$1
+ shift
+
+ printf "Checking for $varname ..." >&2
+ for x in $*; do
+ if command -v $x >/dev/null 2>&1 && [ -x $(command -v $x) ]; then
+ binary="$(command -v $x)"
+ printf " $binary\n" >&2
+ echo "${binary}"
+ return 0
+ fi
+ done
+ printf " not found\n" >&2
+ return 1
+}
+
+die() {
+ printf "%s\n" "${*}"
+ exit 1
+}
+
+# Default values
+PREFIX="/usr/local"
+OPTIMISE="release"
+CC=""
+AR="ar"
+RANLIB="ranlib"
+RM="rm"
+INSTALL="install"
+
+# Parse arguments
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --prefix=*)
+ PREFIX="${1#--prefix=}"
+ ;;
+ --prefix)
+ shift
+ PREFIX="$1"
+ ;;
+ --debug)
+ OPTIMISE="debug"
+ ;;
+ --release)
+ OPTIMISE="release"
+ ;;
+ --help)
+ cat <<EOF
+Configure script for impl
+
+Options:
+ --prefix=PREFIX Installation prefix (default: /usr/local)
+ --debug Build with debug symbols, no optimization
+ --release Build with optimizations (default)
+ --help Show this help message
+
+Environment variables:
+ CC C compiler
+ AR Archiver
+ RANLIB ranlib
+ CFLAGS Additional C flags
+ LDFLAGS Additional linker flags
+EOF
+ exit 0
+ ;;
+ *)
+ die "Unknown option: $1"
+ ;;
+ esac
+ shift
+done
+
+# Find required tools
+if [ -z "$CC" ]; then
+ CC=$(find_program CC cc clang gcc) || die "No C compiler found"
+fi
+
+# Use basename only for better tool compatibility (e.g., bear)
+CC=$(basename "$CC")
+
+# Detect compiler type
+if $CC --version 2>&1 | grep -i clang >/dev/null; then
+ CCOM="clang"
+elif $CC --version 2>&1 | grep -i gcc >/dev/null; then
+ CCOM="gcc"
+else
+ CCOM="unknown"
+fi
+
+printf "Compiler: %s (%s)\n" "$CC" "$CCOM"
+
+# Generate config.h
+cat > config.h <<EOF_CONFIG
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+#define PACKAGE_STRING "$PACKAGE_STRING"
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+#define PACKAGE_URL "$PACKAGE_URL"
+
+#endif /* CONFIG_H */
+EOF_CONFIG
+
+# Determine source directory
+SRCDIR="$(dirname "$0")"
+SRCDIR="$(cd "$SRCDIR" && pwd)"
+
+# Generate Makefile from Makefile.in
+sed \
+ -e "s|@PREFIX@|$PREFIX|g" \
+ -e "s|@CC@|$CC|g" \
+ -e "s|@CCOM@|$CCOM|g" \
+ -e "s|@AR@|$AR|g" \
+ -e "s|@RANLIB@|$RANLIB|g" \
+ -e "s|@RM@|$RM|g" \
+ -e "s|@INSTALL@|$INSTALL|g" \
+ -e "s|@OPTIMISE@|$OPTIMISE|g" \
+ -e "s|@VERSION@|$PACKAGE_VERSION|g" \
+ -e "s|@SRCDIR@|$SRCDIR|g" \
+ < "$SRCDIR/Makefile.in" > Makefile
+
+echo "Configuration complete. Run 'make' to build."