Project

General

Profile

« Previous | Next » 

Revision 7965f1b4

Added by koszko over 1 year ago

improve the build system

View differences:

configure
2 2

  
3 3
# This file is part of Haketilo
4 4
#
5
# Copyright (C) 2021, jahoti
5
# Copyright (C) 2021 Jahoti
6
# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
6 7
#
7 8
# This program is free software: you can redistribute it and/or modify
8 9
# it under the terms of the CC0 1.0 Universal License as published by
......
15 16

  
16 17
set -e
17 18

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

  
28
SOFT_FAILURES=n
29

  
30
ARG0="$0"
25 31

  
26 32
# Parse command line options
27 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_BASE" != "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

  
28 89
    case "$1" in
29
	--srcdir=*)                 SRCDIR="$(printf %s "$1" | cut -c 10-)";;
30
	--srcdir)                                        SRCDIR="$2"; shift;;
31
	--browser-binary=*) BROWSER_BINARY="$(printf %s "$1" | cut -c 18-)";;
32
	--browser-binary)                        BROWSER_BINARY="$2"; shift;;
33
	--clean-profile=*)   CLEAN_PROFILE="$(printf %s "$1" | cut -c 17-)";;
34
	--clean-profile)                          CLEAN_PROFILE="$2"; shift;;
35
	--driver=*)                 DRIVER="$(printf %s "$1" | cut -c 10-)";;
36
	--driver)                                        DRIVER="$2"; shift;;
37
	--pytest=*)                 PYTEST="$(printf %s "$1" | cut -c 10-)";;
38
	--pytest)                                        PYTEST="$2"; shift;;
39
	--srcdir)                                        SRCDIR="$2"; shift;;
40
	"DESTDIR"=*)                DESTDIR="$(printf %s "$1" | cut -c 9-)";;
41
	"UPDATE_URL"=*)         UPDATE_URL="$(printf %s "$1" | cut -c 12-)";;
42
	--host=*)                    TARGET="$(printf %s "$1" | cut -c 8-)";;
43
	--host)                                          TARGET="$2"; shift;;
44

  
45
	# browsers
46
	chromium | chrome | google-chrome | mozilla |\
47
	firefox | librewolf | icecat | iceweasel | abrowser |\
48
	iceweasel-uxp | tor-browser)                 TARGET=$1;;
49
	*)                         echo Ignoring option "'$1'";;
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
	    ;;
50 110
    esac
111

  
51 112
    shift
52 113
done
53 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

  
54 138
# Autodetect srcdir
55 139
if [ "x$SRCDIR" = x ]; then
56
    SRCDIR=..
57
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
58
	SRCDIR=.
140
    if which "$ARG0" >/dev/null 2>&1; then
141
	SRCDIR="$(which "$ARG0")"
142
	SRCDIR="$(dirname "$SRCDIR")"
143
	SRCDIR="$(realpath "$SRCDIR" || true)"
59 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"
60 154
fi
61 155

  
62 156
# Check srcdir
63
if [ ! -f "$SRCDIR"/manifest.json ]; then
64
    echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
65
    exit 1
66
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
67
    echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
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
68 163
    exit 1
69
fi
164
done
70 165

  
71
# Autodetect target
72
if [ "x$TARGET" = x ]; then
73
    echo Detecting target automatically.
74
    if [ -h /etc/alternatives/x-www-browser ]; then
75
	BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
76
	TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
77
	    tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
78
    else
79
    	echo Warning: could not find target automatically. >&2
80
    	echo Some make rules may fail. >&2
81
    fi
82
else
83
    BROWSERPATH="$(realpath "$(which $TARGET)")"
84
fi
166
BROWSERPATH="$(realpath "$(which $TARGET_NAME)" 2>/dev/null || true)"
85 167

  
86
# Autodetect browser binary (needed for Selenium)
168
# Guess browser binary (needed for Selenium)
87 169
if [ "x$BROWSER_BINARY" = x ]; then
88
    if [ "x$TARGET" = xabrowser ]; then
170
    if [ "x$TARGET_NAME" = xabrowser ]; then
89 171
	# Trisquel's path to Abrowser
90 172
	BROWSER_BINARY=/usr/lib/abrowser/abrowser
91
    elif [ "x$TARGET" = xlibrewolf ]; then
173
    elif [ "x$TARGET_NAME" = xlibrewolf ]; then
92 174
	# Debian's path to Librewolf
93 175
	BROWSER_BINARY=/usr/share/librewolf/librewolf
94
    elif [ "x$TARGET" = xiceweasel ]; then
176
    elif [ "x$TARGET_NAME" = xiceweasel ]; then
95 177
	# Parabola's path to Iceweasel
96 178
	BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
97
    elif [ "x$TARGET" = xicecat ]; then
179
    elif [ "x$TARGET_NAME" = xicecat ]; then
98 180
	# Parabola's path to IceCat
99 181
	BROWSER_BINARY=/usr/lib/icecat/icecat
100 182
    fi
101
fi
102 183

  
103
# Check and standardize target
104
case "$TARGET" in
105
    mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
106
    librewolf | iceweasel | gnu | tor-browser)   TARGET=mozilla;;
107
    chromium | chrome | google-chrome | google) TARGET=chromium;;
108
    "")                                                        ;;
109
    *)              echo Invalid target "'$TARGET'" >&2; exit 2;;
110
esac
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
111 191

  
112 192
# Autodetect Selenium driver
113 193
if [ "x$DRIVER" = x ]; then
114
    if [ "x$TARGET" = mozilla ]; then
115
	DRIVER=geckodriver
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
116 201
    fi
117 202
fi
118 203

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

  
126
# Autodetect pytest
127
for PYTEST_GUESS in pytest pytest-3 pytest3; do
128
    if [ "x$PYTEST" = x ]; then
129
	PYTEST="$(which $PYTEST_GUESS || true)"
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
130 243
    fi
131
done
244
fi
132 245

  
133 246
# Autodetect DESTDIR (no check needed)
134 247
if [ "x$DESTDIR" = x ]; then
135
    echo Guessing installation directory.
136
    if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
137
	DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
138
	if [ $TARGET = mozilla ]; then
139
	    DESTDIR="$DESTDIR"/browser
140
	fi
141
	DESTDIR="$DESTDIR"/extensions
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"
142 257
    else
143
    	echo Warning: could not guess installation directory. >&2
144
    	echo Some make rules may fail. >&2
258
	printf 'Cannot guess DESTDIR.\n'
259
	SOFT_FAILURES=y
145 260
    fi
146 261
fi
147 262

  
......
153 268
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
154 269
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
155 270
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
156
printf '%s\n' "PYTEST = $PYTEST" >> record.conf
271
printf '%s\n' "PYTHON = $PYTHON" >> record.conf
157 272

  
158 273
# Prepare and run write_makefile.sh (as config.status)
159
if [ ! -e config.status ]; then
160
    cp "$SRCDIR"/write_makefile.sh config.status
161
fi
274
cp "$SRCDIR"/write_makefile.sh config.status
162 275

  
163 276
./config.status
277

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

Also available in: Unified diff