summaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure281
1 files changed, 199 insertions, 82 deletions
diff --git a/configure b/configure
index 80516fa..3e497b6 100755
--- a/configure
+++ b/configure
@@ -2,7 +2,8 @@
# This file is part of Haketilo
#
-# Copyright (C) 2021, jahoti
+# Copyright (C) 2021 Jahoti
+# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
@@ -15,133 +16,247 @@
set -e
+TARGET_NAME=''
BROWSERPATH=''
-SRCDIR=''
TARGET=''
+SRCDIR=''
BROWSER_BINARY=''
CLEAN_PROFILE=''
DRIVER=''
-PYTEST=''
+PYTHON=''
+
+SOFT_FAILURES=n
+
+ARG0="$0"
# Parse command line options
while [ "x$1" != x ]; do
+ OPT="$1"
+ case "$OPT" in
+ chromium | chrome | google-chrome | mozilla | firefox | \
+ librewolf | icecat | iceweasel | abrowser | tor-browser)
+ TARGET_NAME=$1
+ shift
+ continue
+ ;;
+ esac
+
+ if [ "x$(printf %s "$OPT" | cut -c -2)" = "x--" ]; then
+ # Process a '--' option
+ OPT="${OPT#--}"
+ OPT_NAME="${OPT%%=*}"
+
+ if [ "x$OPT_BASE" != "x$OPT" ]; then
+ OPT_VAL="${OPT#*=}"
+ else
+ shift
+ OPT_VAL="$1"
+ fi
+
+ case "$OPT_NAME" in
+ srcdir)
+ SRCDIR="$OPT_VAL";;
+ browser-binary)
+ BROWSER_BINARY="$OPT_VAL";;
+ clean-profile)
+ CLEAN_PROFILE="$OPT_VAL";;
+ driver)
+ DRIVER="$OPT_VAL";;
+ python)
+ PYTHON="$OPT_VAL";;
+ srcdir)
+ SRCDIR="$OPT_VAL";;
+ destdir|dstdir)
+ DESTDIR="$OPT_VAL";;
+ update-url)
+ UPDATE_URL="$OPT_VAL";;
+ host)
+ TARGET_NAME="$OPT_VAL";;
+ *)
+ printf "Unknown option '--%s'\n" "$OPT_NAME" >&2
+ exit 1
+ ;;
+ esac
+
+ shift
+ continue
+ fi
+
+ # Process a non-'--' option
+ OPT_NAME="${OPT%%=*}"
+ OPT_VAL="${OPT#*=}"
+
case "$1" in
- --srcdir=*) SRCDIR="$(printf %s "$1" | cut -c 10-)";;
- --srcdir) SRCDIR="$2"; shift;;
- --browser-binary=*) BROWSER_BINARY="$(printf %s "$1" | cut -c 18-)";;
- --browser-binary) BROWSER_BINARY="$2"; shift;;
- --clean-profile=*) CLEAN_PROFILE="$(printf %s "$1" | cut -c 17-)";;
- --clean-profile) CLEAN_PROFILE="$2"; shift;;
- --driver=*) DRIVER="$(printf %s "$1" | cut -c 10-)";;
- --driver) DRIVER="$2"; shift;;
- --pytest=*) PYTEST="$(printf %s "$1" | cut -c 10-)";;
- --pytest) PYTEST="$2"; shift;;
- --srcdir) SRCDIR="$2"; shift;;
- "DESTDIR"=*) DESTDIR="$(printf %s "$1" | cut -c 9-)";;
- "UPDATE_URL"=*) UPDATE_URL="$(printf %s "$1" | cut -c 12-)";;
- --host=*) TARGET="$(printf %s "$1" | cut -c 8-)";;
- --host) TARGET="$2"; shift;;
-
- # browsers
- chromium | chrome | google-chrome | mozilla |\
- firefox | librewolf | icecat | iceweasel | abrowser |\
- iceweasel-uxp | tor-browser) TARGET=$1;;
- *) echo Ignoring option "'$1'";;
+ BROWSER_BINARY)
+ BROWSER_BINARY="$OPT_VAL";;
+ CLEAN_PROFILE)
+ CLEAN_PROFILE="$OPT_VAL";;
+ DRIVER)
+ DRIVER="$OPT_VAL";;
+ PYTHON)
+ PYTHON="$OPT_VAL";;
+ SRCDIR)
+ SRCDIR="$OPT_VAL";;
+ DESTDIR|DSTDIR)
+ DESTDIR="$OPT_VAL";;
+ UPDATE_URL)
+ UPDATE_URL="$OPT_VAL";;
+ HOST)
+ TARGET_NAME="$OPT_VAL";;
+ *)
+ printf "Unknown variable '%s'\n" "$OPT_NAME" >&2
+ exit 1
+ ;;
esac
+
shift
done
+# Check TARGET_NAME
+if [ "x$TARGET_NAME" = x ]; then
+ printf 'Target not specified. Please use `--host=<browser-name>`.\n' >&2
+ exit 1
+fi
+
+# Check and standardize target
+case "$TARGET_NAME" in
+ mozilla | firefox | abrowser | icecat | librewolf | iceweasel | tor-browser)
+ TARGET=mozilla
+ ;;
+ ungoogled-chromium | chromium | chrome | google-chrome | brave | iridium | \
+ bromite)
+ TARGET=chromium
+ printf "Tests won't yet run on a Chromium-based browser.\n"
+ SOFT_FAILURES=y
+ ;;
+ *)
+ printf 'Invalid target: %s\n' "$TARGET_NAME" >&2
+ exit 1
+ ;;
+esac
+
# Autodetect srcdir
if [ "x$SRCDIR" = x ]; then
- SRCDIR=..
- if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
- SRCDIR=.
+ if which "$ARG0" >/dev/null 2>&1; then
+ SRCDIR="$(which "$ARG0")"
+ SRCDIR="$(dirname "$SRCDIR")"
+ SRCDIR="$(realpath "$SRCDIR" || true)"
fi
+
+ if [ "x$SRCDIR" = x ]; then
+ SRCDIR=..
+ if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
+ SRCDIR=.
+ fi
+ fi
+
+ printf 'Guessing SRCDIR: %s\n' "$SRCDIR"
fi
# Check srcdir
-if [ ! -f "$SRCDIR"/manifest.json ]; then
- echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
- exit 1
-elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
- echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
+for FILE in manifest.json write_makefile.sh version; do
+ if [ -f "$SRCDIR"/"$FILE" ]; then
+ continue
+ fi
+
+ printf "Invalid source directory '%s': missing %s\n" "$SRCDIR" $FILE >&2
exit 1
-fi
+done
-# Autodetect target
-if [ "x$TARGET" = x ]; then
- echo Detecting target automatically.
- if [ -h /etc/alternatives/x-www-browser ]; then
- BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
- TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
- tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
- else
- echo Warning: could not find target automatically. >&2
- echo Some make rules may fail. >&2
- fi
-else
- BROWSERPATH="$(realpath "$(which $TARGET)")"
-fi
+BROWSERPATH="$(realpath "$(which $TARGET_NAME)" 2>/dev/null || true)"
-# Autodetect browser binary (needed for Selenium)
+# Guess browser binary (needed for Selenium)
if [ "x$BROWSER_BINARY" = x ]; then
- if [ "x$TARGET" = xabrowser ]; then
+ if [ "x$TARGET_NAME" = xabrowser ]; then
# Trisquel's path to Abrowser
BROWSER_BINARY=/usr/lib/abrowser/abrowser
- elif [ "x$TARGET" = xlibrewolf ]; then
+ elif [ "x$TARGET_NAME" = xlibrewolf ]; then
# Debian's path to Librewolf
BROWSER_BINARY=/usr/share/librewolf/librewolf
- elif [ "x$TARGET" = xiceweasel ]; then
+ elif [ "x$TARGET_NAME" = xiceweasel ]; then
# Parabola's path to Iceweasel
BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
- elif [ "x$TARGET" = xicecat ]; then
+ elif [ "x$TARGET_NAME" = xicecat ]; then
# Parabola's path to IceCat
BROWSER_BINARY=/usr/lib/icecat/icecat
fi
-fi
-# Check and standardize target
-case "$TARGET" in
- mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
- librewolf | iceweasel | gnu | tor-browser) TARGET=mozilla;;
- chromium | chrome | google-chrome | google) TARGET=chromium;;
- "") ;;
- *) echo Invalid target "'$TARGET'" >&2; exit 2;;
-esac
+ if [ "x$BROWSER_BINARY" != x ]; then
+ printf 'Guessing BROWSER_BINARY: %s\n' "$BROWSER_BINARY"
+ elif [ "$TARGET" != "chromium" ]; then
+ printf 'Cannot guess BROWSER_BINARY for %s.\n' "$TARGET_NAME"
+ SOFT_FAILURES=y
+ fi
+fi
# Autodetect Selenium driver
if [ "x$DRIVER" = x ]; then
- if [ "x$TARGET" = mozilla ]; then
- DRIVER=geckodriver
+ if [ "x$TARGET" = xmozilla ]; then
+ DRIVER="$(which geckodriver 2>/dev/null || true)"
+ if [ -n "$DRIVER" ]; then
+ printf 'Guessing DRIVER: %s\n' "$DRIVER"
+ else
+ printf 'Cannot guess DRIVER for %s.\n' "$TARGET_NAME"
+ fi
fi
fi
# Autodetect clean profile directory for use in selenium tests
if [ "x$CLEAN_PROFILE" = x ]; then
- if [ "x$TARGET" = mozilla ]; then
+ if [ "x$TARGET" = xmozilla ]; then
CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
fi
fi
-# Autodetect pytest
-for PYTEST_GUESS in pytest pytest-3 pytest3; do
- if [ "x$PYTEST" = x ]; then
- PYTEST="$(which $PYTEST_GUESS || true)"
+# Autodetect python
+if [ "x$TARGET" = xmozilla -a "x$PYTHON" = x ]; then
+ PYTHON2_SKIPPED=n
+ for PYTHON_GUESS in python3 python-3 python; do
+ if [ "x$PYTHON" = x ]; then
+ PYTHON="$(which $PYTHON_GUESS 2>/dev/null || true)"
+ fi
+
+ if [ -n "$PYTHON" ]; then
+ if [ "$PYTHON_GUESS" = python ]; then
+ if python --version 2>&1 | grep '^Python 2' >/dev/null; then
+ PYTHON=''
+ PYTHON2_SKIPPED=y
+ fi
+ fi
+ fi
+
+ if [ -n "$PYTHON" ]; then
+ break
+ fi
+ done
+
+ if [ -n "$PYTHON" ]; then
+ printf 'Guessing PYTHON: %s\n' "$PYTHON"
+ else
+ printf 'Cannot guess PYTHON'
+ if [ "$PYTHON2_SKIPPED" = y ]; then
+ printf ' %s' \
+ '(skipped Python 2 executable in PATH; Python 3 is required)'
+ fi
+ printf '.\n'
+ SOFT_FAILURES=y
fi
-done
+fi
# Autodetect DESTDIR (no check needed)
if [ "x$DESTDIR" = x ]; then
- echo Guessing installation directory.
- if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
- DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
- if [ $TARGET = mozilla ]; then
- DESTDIR="$DESTDIR"/browser
- fi
- DESTDIR="$DESTDIR"/extensions
+ if [ "x$TARGET" = xmozilla ]; then
+ DESTDIR=/usr/share/mozilla/extensions/
+ elif test "x$TARGET_NAME" = xchromium -o \
+ "x$TARGET_NAME" = xungoogled-chromium; then
+ DESTDIR=/usr/share/chromium/extensions
+ fi
+
+ if [ -n "$DESTDIR" ]; then
+ printf 'Guessing DESTDIR: %s\n' "$DESTDIR"
else
- echo Warning: could not guess installation directory. >&2
- echo Some make rules may fail. >&2
+ printf 'Cannot guess DESTDIR.\n'
+ SOFT_FAILURES=y
fi
fi
@@ -153,11 +268,13 @@ printf '%s\n' "UPDATE_URL = $UPDATE_URL" >> record.conf
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
-printf '%s\n' "PYTEST = $PYTEST" >> record.conf
+printf '%s\n' "PYTHON = $PYTHON" >> record.conf
# Prepare and run write_makefile.sh (as config.status)
-if [ ! -e config.status ]; then
- cp "$SRCDIR"/write_makefile.sh config.status
-fi
+cp "$SRCDIR"/write_makefile.sh config.status
./config.status
+
+if [ "$SOFT_FAILURES" = "y" ]; then
+ printf 'Some make rules may fail.\n'
+fi