Project

General

Profile

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

haketilo / configure @ 57ce414c

1
#!/bin/sh
2

    
3
# This file is part of Haketilo
4
#
5
# Copyright (C) 2021 Jahoti
6
# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
7
#
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the CC0 1.0 Universal License as published by
10
# the Creative Commons Corporation.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# CC0 1.0 Universal License for more details.
16

    
17
set -e
18

    
19
TARGET_NAME=''
20
BROWSERPATH=''
21
TARGET=''
22
SRCDIR=''
23
BROWSER_BINARY=''
24
CLEAN_PROFILE=''
25
DRIVER=''
26
PYTHON=''
27

    
28
SOFT_FAILURES=n
29

    
30
ARG0="$0"
31

    
32
# Parse command line options
33
while [ "x$1" != x ]; do
34
    OPT="$1"
35
    case "$OPT" in
36
	chromium | chrome | google-chrome | mozilla | firefox | \
37
	    librewolf | icecat | iceweasel | abrowser | tor-browser)
38
            TARGET_NAME=$1
39
	    shift
40
	    continue
41
	    ;;
42
    esac
43

    
44
    if [ "x$(printf %s "$OPT" | cut -c -2)" = "x--" ]; then
45
	# Process a '--' option
46
	OPT="${OPT#--}"
47
	OPT_NAME="${OPT%%=*}"
48

    
49
	if [ "x$OPT_NAME" != "x$OPT" ]; then
50
	    OPT_VAL="${OPT#*=}"
51
	else
52
	    shift
53
	    OPT_VAL="$1"
54
	fi
55

    
56
	case "$OPT_NAME" in
57
	    srcdir)
58
                SRCDIR="$OPT_VAL";;
59
	    browser-binary)
60
		BROWSER_BINARY="$OPT_VAL";;
61
	    clean-profile)
62
		CLEAN_PROFILE="$OPT_VAL";;
63
	    driver)
64
                DRIVER="$OPT_VAL";;
65
	    python)
66
		PYTHON="$OPT_VAL";;
67
	    srcdir)
68
                SRCDIR="$OPT_VAL";;
69
	    destdir|dstdir)
70
	        DESTDIR="$OPT_VAL";;
71
	    update-url)
72
		UPDATE_URL="$OPT_VAL";;
73
	    host)
74
		TARGET_NAME="$OPT_VAL";;
75
	    *)
76
		printf "Unknown option '--%s'\n" "$OPT_NAME" >&2
77
		exit 1
78
		;;
79
	esac
80

    
81
	shift
82
	continue
83
    fi
84

    
85
    # Process a non-'--' option
86
    OPT_NAME="${OPT%%=*}"
87
    OPT_VAL="${OPT#*=}"
88

    
89
    case "$OPT_NAME" in
90
	BROWSER_BINARY)
91
            BROWSER_BINARY="$OPT_VAL";;
92
	CLEAN_PROFILE)
93
            CLEAN_PROFILE="$OPT_VAL";;
94
	DRIVER)
95
            DRIVER="$OPT_VAL";;
96
	PYTHON)
97
            PYTHON="$OPT_VAL";;
98
	SRCDIR)
99
            SRCDIR="$OPT_VAL";;
100
	DESTDIR|DSTDIR)
101
            DESTDIR="$OPT_VAL";;
102
	UPDATE_URL)
103
            UPDATE_URL="$OPT_VAL";;
104
	HOST)
105
            TARGET_NAME="$OPT_VAL";;
106
	*)
107
	    printf "Unknown variable '%s'\n" "$OPT_NAME" >&2
108
	    exit 1
109
	    ;;
110
    esac
111

    
112
    shift
113
done
114

    
115
# Check TARGET_NAME
116
if [ "x$TARGET_NAME" = x ]; then
117
    printf 'Target not specified. Please use `--host=<browser-name>`.\n' >&2
118
    exit 1
119
fi
120

    
121
# Check and standardize target
122
case "$TARGET_NAME" in
123
    mozilla | firefox | abrowser | icecat | librewolf | iceweasel | tor-browser)
124
	TARGET=mozilla
125
	;;
126
    ungoogled-chromium | chromium | chrome | google-chrome | brave | iridium | \
127
	bromite)
128
	TARGET=chromium
129
	printf "Tests won't yet run on a Chromium-based browser.\n"
130
	SOFT_FAILURES=y
131
	;;
132
    *)
133
	printf 'Invalid target: %s\n' "$TARGET_NAME" >&2
134
	exit 1
135
	;;
136
esac
137

    
138
# Autodetect srcdir
139
if [ "x$SRCDIR" = x ]; then
140
    if which "$ARG0" >/dev/null 2>&1; then
141
	SRCDIR="$(which "$ARG0")"
142
	SRCDIR="$(dirname "$SRCDIR")"
143
	SRCDIR="$(realpath "$SRCDIR" || true)"
144
    fi
145

    
146
    if [ "x$SRCDIR" = x ]; then
147
	SRCDIR=..
148
	if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
149
	    SRCDIR=.
150
	fi
151
    fi
152

    
153
    printf 'Guessing SRCDIR: %s\n' "$SRCDIR"
154
fi
155

    
156
# Check srcdir
157
for FILE in manifest.json write_makefile.sh version; do
158
    if [ -f "$SRCDIR"/"$FILE" ]; then
159
	continue
160
    fi
161

    
162
    printf "Invalid source directory '%s': missing %s\n" "$SRCDIR" $FILE >&2
163
    exit 1
164
done
165

    
166
BROWSERPATH="$(realpath "$(which $TARGET_NAME)" 2>/dev/null || true)"
167

    
168
# Guess browser binary (needed for Selenium)
169
if [ "x$BROWSER_BINARY" = x ]; then
170
    if [ "x$TARGET_NAME" = xabrowser ]; then
171
	# Trisquel's path to Abrowser
172
	BROWSER_BINARY=/usr/lib/abrowser/abrowser
173
    elif [ "x$TARGET_NAME" = xlibrewolf ]; then
174
	# Debian's path to Librewolf
175
	BROWSER_BINARY=/usr/share/librewolf/librewolf
176
    elif [ "x$TARGET_NAME" = xiceweasel ]; then
177
	# Parabola's path to Iceweasel
178
	BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
179
    elif [ "x$TARGET_NAME" = xicecat ]; then
180
	# Parabola's path to IceCat
181
	BROWSER_BINARY=/usr/lib/icecat/icecat
182
    fi
183

    
184
    if [ "x$BROWSER_BINARY" != x ]; then
185
	printf 'Guessing BROWSER_BINARY: %s\n' "$BROWSER_BINARY"
186
    elif [ "$TARGET" != "chromium" ]; then
187
	printf 'Cannot guess BROWSER_BINARY for %s.\n' "$TARGET_NAME"
188
	SOFT_FAILURES=y
189
    fi
190
fi
191

    
192
# Autodetect Selenium driver
193
if [ "x$DRIVER" = x ]; then
194
    if [ "x$TARGET" = xmozilla ]; then
195
	DRIVER="$(which geckodriver 2>/dev/null || true)"
196
	if [ -n "$DRIVER" ]; then
197
	    printf 'Guessing DRIVER: %s\n' "$DRIVER"
198
	else
199
	    printf 'Cannot guess DRIVER for %s.\n' "$TARGET_NAME"
200
	fi
201
    fi
202
fi
203

    
204
# Autodetect clean profile directory for use in selenium tests
205
if [ "x$CLEAN_PROFILE" = x ]; then
206
    if [ "x$TARGET" = xmozilla ]; then
207
	CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
208
    fi
209
fi
210

    
211
# Autodetect python
212
if [ "x$TARGET" = xmozilla -a "x$PYTHON" = x ]; then
213
    PYTHON2_SKIPPED=n
214
    for PYTHON_GUESS in python3 python-3 python; do
215
	if [ "x$PYTHON" = x ]; then
216
	    PYTHON="$(which $PYTHON_GUESS 2>/dev/null || true)"
217
	fi
218

    
219
	if [ -n "$PYTHON" ]; then
220
	    if [ "$PYTHON_GUESS" = python ]; then
221
		if python --version 2>&1 | grep '^Python 2' >/dev/null; then
222
		    PYTHON=''
223
		    PYTHON2_SKIPPED=y
224
		fi
225
	    fi
226
	fi
227

    
228
	if [ -n "$PYTHON" ]; then
229
	    break
230
	fi
231
    done
232

    
233
    if [ -n "$PYTHON" ]; then
234
	printf 'Guessing PYTHON: %s\n' "$PYTHON"
235
    else
236
	printf 'Cannot guess PYTHON'
237
	if [ "$PYTHON2_SKIPPED" = y ]; then
238
	    printf ' %s' \
239
		   '(skipped Python 2 executable in PATH; Python 3 is required)'
240
	fi
241
	printf '.\n'
242
	SOFT_FAILURES=y
243
    fi
244
fi
245

    
246
# Autodetect DESTDIR (no check needed)
247
if [ "x$DESTDIR" = x ]; then
248
    if [ "x$TARGET" = xmozilla ]; then
249
	DESTDIR=/usr/share/mozilla/extensions/
250
    elif test "x$TARGET_NAME" = xchromium -o \
251
	      "x$TARGET_NAME" = xungoogled-chromium; then
252
	DESTDIR=/usr/share/chromium/extensions
253
    fi
254

    
255
    if [ -n "$DESTDIR" ]; then
256
	printf 'Guessing DESTDIR: %s\n' "$DESTDIR"
257
    else
258
	printf 'Cannot guess DESTDIR.\n'
259
	SOFT_FAILURES=y
260
    fi
261
fi
262

    
263
# Write record.conf (LEAVE SRCDIR FIRST)
264
printf '%s\n' "srcdir = $SRCDIR" > record.conf
265
printf '%s\n' "default_target = $TARGET" >> record.conf
266
printf '%s\n' "DESTDIR = $DESTDIR" >> record.conf
267
printf '%s\n' "UPDATE_URL = $UPDATE_URL" >> record.conf
268
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
269
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
270
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
271
printf '%s\n' "PYTHON = $PYTHON" >> record.conf
272

    
273
# Prepare and run write_makefile.sh (as config.status)
274
cp "$SRCDIR"/write_makefile.sh config.status
275

    
276
./config.status
277

    
278
if [ "$SOFT_FAILURES" = "y" ]; then
279
    printf 'Some make rules may fail.\n'
280
fi
(7-7/18)