Project

General

Profile

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

haketilo / configure @ 26e4800d

1
#!/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
BROWSERPATH=''
19
SRCDIR=''
20
TARGET=''
21
BROWSER_BINARY=''
22
CLEAN_PROFILE=''
23
DRIVER=''
24
PYTEST=''
25

    
26
# Parse command line options
27
while [ "x$1" != x ]; do
28
    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'";;
50
    esac
51
    shift
52
done
53

    
54
# Autodetect srcdir
55
if [ "x$SRCDIR" = x ]; then
56
    SRCDIR=..
57
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
58
	SRCDIR=.
59
    fi
60
fi
61

    
62
# 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
68
    exit 1
69
fi
70

    
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
85

    
86
# Autodetect browser binary (needed for Selenium)
87
if [ "x$BROWSER_BINARY" = x ]; then
88
    if [ "x$TARGET" = xabrowser ]; then
89
	# Trisquel's path to Abrowser
90
	BROWSER_BINARY=/usr/lib/abrowser/abrowser
91
    elif [ "x$TARGET" = xlibrewolf ]; then
92
	# Debian's path to Librewolf
93
	BROWSER_BINARY=/usr/share/librewolf/librewolf
94
    elif [ "x$TARGET" = xicecat ]; then
95
	# Parabola's path to IceCat
96
	BROWSER_BINARY=/usr/lib/icecat/icecat
97
    fi
98
fi
99

    
100
# Check and standardize target
101
case "$TARGET" in
102
    mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
103
    librewolf | iceweasel | gnu | tor-browser)   TARGET=mozilla;;
104
    chromium | chrome | google-chrome | google) TARGET=chromium;;
105
    "")                                                        ;;
106
    *)              echo Invalid target "'$TARGET'" >&2; exit 2;;
107
esac
108

    
109
# Autodetect Selenium driver
110
if [ "x$DRIVER" = x ]; then
111
    if [ "x$TARGET" = mozilla ]; then
112
	DRIVER=geckodriver
113
    fi
114
fi
115

    
116
# Autodetect clean profile directory for use in selenium tests
117
if [ "x$CLEAN_PROFILE" = x ]; then
118
    if [ "x$TARGET" = mozilla ]; then
119
	CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
120
    fi
121
fi
122

    
123
# Autodetect pytest
124
for PYTEST_GUESS in pytest pytest-3 pytest3; do
125
    if [ "x$PYTEST" = x ]; then
126
	PYTEST="$(which $PYTEST_GUESS || true)"
127
    fi
128
done
129

    
130
# Autodetect DESTDIR (no check needed)
131
if [ "x$DESTDIR" = x ]; then
132
    echo Guessing installation directory.
133
    if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
134
	DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
135
	if [ $TARGET = mozilla ]; then
136
	    DESTDIR="$DESTDIR"/browser
137
	fi
138
	DESTDIR="$DESTDIR"/extensions
139
    else
140
    	echo Warning: could not guess installation directory. >&2
141
    	echo Some make rules may fail. >&2
142
    fi
143
fi
144

    
145
# Write record.conf (LEAVE SRCDIR FIRST)
146
printf '%s\n' "srcdir = $SRCDIR" > record.conf
147
printf '%s\n' "default_target = $TARGET" >> record.conf
148
printf '%s\n' "DESTDIR = $DESTDIR" >> record.conf
149
printf '%s\n' "UPDATE_URL = $UPDATE_URL" >> record.conf
150
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
151
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
152
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
153
printf '%s\n' "PYTEST = $PYTEST" >> record.conf
154

    
155
# Prepare and run write_makefile.sh (as config.status)
156
if [ ! -e config.status ]; then
157
    cp "$SRCDIR"/write_makefile.sh config.status
158
fi
159

    
160
./config.status
(6-6/16)