Project

General

Profile

Download (4.18 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / configure @ 201fcfad

1 4320edc9 jahoti
#!/bin/sh
2
3
# This file is part of Haketilo
4
#
5
# Copyright (C) 2021, jahoti
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the CC0 1.0 Universal License as published by
9
# the Creative Commons Corporation.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# CC0 1.0 Universal License for more details.
15
16
set -e
17
18 3fcff338 jahoti
# Set BROWSERPATH appropriately
19
set_browserpath () {
20 c39c6b9e jahoti
    BROWSERPATH="${BROWSERPATH:-$(realpath "$1")}"
21 3fcff338 jahoti
}
22
23 4320edc9 jahoti
SRCDIR=''
24
TARGET=''
25
26
# Parse command line options
27
while [ "x$1" != x ]; do
28
    case "$1" in
29 3fcff338 jahoti
	--srcdir=*)           SRCDIR="$(echo "$1" | cut -c 10-)";;
30
	--srcdir)                             SRCDIR="$2"; shift;;
31 c39c6b9e jahoti
	BROWSER=*)        BROWSERPATH="$(echo "$1" | cut -c 9-)";;
32 3fcff338 jahoti
	DESTDIR=*)            DESTDIR="$(echo "$1" | cut -c 9-)";;
33
	PYTEST=*)              PYTEST="$(echo "$1" | cut -c 8-)";;
34
	PYTHON=*)              PYTHON="$(echo "$1" | cut -c 8-)";;
35 c39c6b9e jahoti
	TEST_BROWSER=*) TEST_BROWSER="$(echo "$1" | cut -c 14-)";;
36 3fcff338 jahoti
	TEST_PORT=*)       TEST_PORT="$(echo "$1" | cut -c 11-)";;
37
	TEST_PROFILE=*) TEST_PROFILE="$(echo "$1" | cut -c 14-)";;
38
	UPDATE_URL=*)     UPDATE_URL="$(echo "$1" | cut -c 12-)";;
39
	--host=*)              TARGET="$(echo "$1" | cut -c 8-)";;
40
	--host)                               TARGET="$2"; shift;;
41 bd767301 Wojtek Kosior
42 f318575f jahoti
	# browsers
43
	chromium | chrome | google-chrome | mozilla |\
44
	firefox | librewolf | icecat | iceweasel | abrowser |\
45 3fcff338 jahoti
	iceweasel-uxp | tor-browser)                   TARGET=$1;;
46
	*)                           echo Ignoring option "'$1'";;
47 4320edc9 jahoti
    esac
48
    shift
49
done
50
51
# Autodetect srcdir
52
if [ "x$SRCDIR" = x ]; then
53
    SRCDIR=..
54 bd767301 Wojtek Kosior
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
55 4320edc9 jahoti
	SRCDIR=.
56
    fi
57
fi
58
59
# Check srcdir
60
if [ ! -f "$SRCDIR"/manifest.json ]; then
61
    echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
62
    exit 1
63
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
64
    echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
65
    exit 1
66
fi
67
68 f318575f jahoti
# Autodetect target
69
if [ "x$TARGET" = x ]; then
70
    echo Detecting target automatically.
71
    if [ -h /etc/alternatives/x-www-browser ]; then
72 3fcff338 jahoti
	set_browserpath /etc/alternatives/x-www-browser
73
	TARGET="$("$BROWSERPATH" --version 2> /dev/null |
74 f318575f jahoti
	    tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
75
    else
76
    	echo Warning: could not find target automatically. >&2
77
    	echo Some make rules may fail. >&2
78
    fi
79
else
80 3fcff338 jahoti
    set_browserpath "$(which $TARGET)"
81 f318575f jahoti
fi
82 4320edc9 jahoti
83 c39c6b9e jahoti
TEST_BROWSER="${TEST_BROWSER:-$BROWSERPATH}"
84
85 f318575f jahoti
# Check and standardize target
86 ef5ae649 jahoti
case "$TARGET" in
87 f318575f jahoti
    mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
88
    librewolf | iceweasel | gnu | tor-browser)   TARGET=mozilla;;
89
    chromium | chrome | google-chrome | google) TARGET=chromium;;
90
    "")                                                        ;;
91
    *)              echo Invalid target "'$TARGET'" >&2; exit 2;;
92 4320edc9 jahoti
esac
93
94 f318575f jahoti
# Autodetect DESTDIR (no check needed)
95
if [ "x$DESTDIR" = x ]; then
96
    echo Guessing installation directory.
97
    if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
98
	DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
99
	if [ $TARGET = mozilla ]; then
100
	    DESTDIR="$DESTDIR"/browser
101
	fi
102
	DESTDIR="$DESTDIR"/extensions
103
    else
104
    	echo Warning: could not guess installation directory. >&2
105
    	echo Some make rules may fail. >&2
106
    fi
107
fi
108
109 e0c94ac4 jahoti
# Write record.conf (LEAVE SRCDIR FIRST)
110
echo srcdir = "$SRCDIR" > record.conf
111 4320edc9 jahoti
echo default_target = "$TARGET" >> record.conf
112 fa5a0e79 jahoti
echo DESTDIR = "$DESTDIR" >> record.conf
113 3fcff338 jahoti
echo PYTEST = "${PYTEST:-$(which pytest)}" >> record.conf
114
echo PYTHON = "${PYTHON:-$(which python3)}" >> record.conf
115 e0c94ac4 jahoti
echo UPDATE_URL = "$UPDATE_URL" >> record.conf
116 4320edc9 jahoti
117 3fcff338 jahoti
# (Re-)write testing.conf
118
rm -f testing.conf
119 c39c6b9e jahoti
[ "x$TEST_BROWSER" != x ] && echo BINARY "$TEST_BROWSER" >> testing.conf
120 3fcff338 jahoti
[ "x$TEST_PROFILE" != x ] && echo TEST_PROFILE "$TEST_PROFILE" >> testing.conf
121
[ "x$TEST_PORT" != x ] && echo TEST_PORT "$TEST_PORT" >> testing.conf
122 201fcfad jahoti
[ "$srcdir" != '.' ] && echo CERT_DIR "$PWD/test/certs" >> testing.conf
123 4320edc9 jahoti
124 e0c94ac4 jahoti
# Prepare and run write_makefile.sh (as config.status)
125 4320edc9 jahoti
if [ ! -e config.status ]; then
126
    cp "$SRCDIR"/write_makefile.sh config.status
127
fi
128
129
./config.status