Project

General

Profile

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

haketilo / configure @ c39c6b9e

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
# Set BROWSERPATH appropriately
19
set_browserpath () {
20
    BROWSERPATH="${BROWSERPATH:-$(realpath "$1")}"
21
}
22

    
23
SRCDIR=''
24
TARGET=''
25

    
26
# Parse command line options
27
while [ "x$1" != x ]; do
28
    case "$1" in
29
	--srcdir=*)           SRCDIR="$(echo "$1" | cut -c 10-)";;
30
	--srcdir)                             SRCDIR="$2"; shift;;
31
	BROWSER=*)        BROWSERPATH="$(echo "$1" | cut -c 9-)";;
32
	DESTDIR=*)            DESTDIR="$(echo "$1" | cut -c 9-)";;
33
	PYTEST=*)              PYTEST="$(echo "$1" | cut -c 8-)";;
34
	PYTHON=*)              PYTHON="$(echo "$1" | cut -c 8-)";;
35
	TEST_BROWSER=*) TEST_BROWSER="$(echo "$1" | cut -c 14-)";;
36
	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

    
42
	# browsers
43
	chromium | chrome | google-chrome | mozilla |\
44
	firefox | librewolf | icecat | iceweasel | abrowser |\
45
	iceweasel-uxp | tor-browser)                   TARGET=$1;;
46
	*)                           echo Ignoring option "'$1'";;
47
    esac
48
    shift
49
done
50

    
51
# Autodetect srcdir
52
if [ "x$SRCDIR" = x ]; then
53
    SRCDIR=..
54
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
55
	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
# Autodetect target
69
if [ "x$TARGET" = x ]; then
70
    echo Detecting target automatically.
71
    if [ -h /etc/alternatives/x-www-browser ]; then
72
	set_browserpath /etc/alternatives/x-www-browser
73
	TARGET="$("$BROWSERPATH" --version 2> /dev/null |
74
	    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
    set_browserpath "$(which $TARGET)"
81
fi
82

    
83
TEST_BROWSER="${TEST_BROWSER:-$BROWSERPATH}"
84

    
85
# Check and standardize target
86
case "$TARGET" in
87
    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
esac
93

    
94
# 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
# Write record.conf (LEAVE SRCDIR FIRST)
110
echo srcdir = "$SRCDIR" > record.conf
111
echo default_target = "$TARGET" >> record.conf
112
echo DESTDIR = "$DESTDIR" >> record.conf
113
echo PYTEST = "${PYTEST:-$(which pytest)}" >> record.conf
114
echo PYTHON = "${PYTHON:-$(which python3)}" >> record.conf
115
echo UPDATE_URL = "$UPDATE_URL" >> record.conf
116

    
117
# (Re-)write testing.conf
118
rm -f testing.conf
119
[ "x$TEST_BROWSER" != x ] && echo BINARY "$TEST_BROWSER" >> testing.conf
120
[ "x$TEST_PROFILE" != x ] && echo TEST_PROFILE "$TEST_PROFILE" >> testing.conf
121
[ "x$TEST_PORT" != x ] && echo TEST_PORT "$TEST_PORT" >> testing.conf
122

    
123
# Prepare and run write_makefile.sh (as config.status)
124
if [ ! -e config.status ]; then
125
    cp "$SRCDIR"/write_makefile.sh config.status
126
fi
127

    
128
./config.status
(7-7/16)