From f318575f5a8a3533541b93ee6a018c5b35ee643b Mon Sep 17 00:00:00 2001 From: jahoti Date: Thu, 14 Oct 2021 00:00:00 +0000 Subject: Add target and install directory auto-detection It's simplistic, yet (hopefully) good enough. --- configure | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'configure') diff --git a/configure b/configure index fb56ec8..e348907 100755 --- a/configure +++ b/configure @@ -15,6 +15,7 @@ set -e +BROWSERPATH='' SRCDIR='' TARGET='' @@ -27,7 +28,11 @@ while [ "x$1" != x ]; do "UPDATE_URL"=*) UPDATE_URL="$(echo "$1" | cut -c 12-)";; --host=*) TARGET="$(echo "$1" | cut -c 8-)";; --host) TARGET="$2"; shift;; - mozilla | chromium) TARGET=$1;; + + # browsers + chromium | chrome | google-chrome | mozilla |\ + firefox | librewolf | icecat | iceweasel | abrowser |\ + iceweasel-uxp | tor-browser) TARGET=$1;; *) echo Ignoring option "'$1'";; esac shift @@ -36,7 +41,7 @@ done # Autodetect srcdir if [ "x$SRCDIR" = x ]; then SRCDIR=.. - if [ -f manifest.json -a -f write_makefile.sh]; then + if [ -f manifest.json ] && [ -f write_makefile.sh]; then SRCDIR=. fi fi @@ -50,15 +55,45 @@ elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then exit 1 fi -# TODO: automate target detection +# 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 -# Standardize and check browser names +# Check and standardize target case "$TARGET" in - mozilla) TARGET=mozilla;; - chromium) TARGET=chromium;; - *) echo Invalid target "'$1'" >&2; exit 2;; + 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 +# 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 + else + echo Warning: could not guess installation directory. >&2 + echo Some make rules may fail. >&2 + fi +fi + # Write record.conf (LEAVE SRCDIR FIRST) echo srcdir = "$SRCDIR" > record.conf echo default_target = "$TARGET" >> record.conf -- cgit v1.2.3