Project

General

Profile

Download (3.27 KB) Statistics
| Branch: | Revision:

hachette / configure @ master

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

    
22
# Parse command line options
23
while [ "x$1" != x ]; do
24
    case "$1" in
25
	--srcdir=*)         SRCDIR="$(echo "$1" | cut -c 10-)";;
26
	--srcdir)                           SRCDIR="$2"; shift;;
27
	"DESTDIR"=*)        DESTDIR="$(echo "$1" | cut -c 9-)";;
28
	"UPDATE_URL"=*) UPDATE_URL="$(echo "$1" | cut -c 12-)";;
29
	--host=*)            TARGET="$(echo "$1" | cut -c 8-)";;
30
	--host)                             TARGET="$2"; shift;;
31

    
32
	# browsers
33
	chromium | chrome | google-chrome | mozilla |\
34
	firefox | librewolf | icecat | iceweasel | abrowser |\
35
	iceweasel-uxp | tor-browser)                 TARGET=$1;;
36
	*)                         echo Ignoring option "'$1'";;
37
    esac
38
    shift
39
done
40

    
41
# Autodetect srcdir
42
if [ "x$SRCDIR" = x ]; then
43
    SRCDIR=..
44
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
45
	SRCDIR=.
46
    fi
47
fi
48

    
49
# Check srcdir
50
if [ ! -f "$SRCDIR"/manifest.json ]; then
51
    echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
52
    exit 1
53
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
54
    echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
55
    exit 1
56
fi
57

    
58
# Autodetect target
59
if [ "x$TARGET" = x ]; then
60
    echo Detecting target automatically.
61
    if [ -h /etc/alternatives/x-www-browser ]; then
62
	BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
63
	TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
64
	    tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
65
    else
66
    	echo Warning: could not find target automatically. >&2
67
    	echo Some make rules may fail. >&2
68
    fi
69
else
70
    BROWSERPATH="$(realpath "$(which $TARGET)")"
71
fi
72

    
73
# Check and standardize target
74
case "$TARGET" in
75
    mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
76
    librewolf | iceweasel | gnu | tor-browser)   TARGET=mozilla;;
77
    chromium | chrome | google-chrome | google) TARGET=chromium;;
78
    "")                                                        ;;
79
    *)              echo Invalid target "'$TARGET'" >&2; exit 2;;
80
esac
81

    
82
# Autodetect DESTDIR (no check needed)
83
if [ "x$DESTDIR" = x ]; then
84
    echo Guessing installation directory.
85
    if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
86
	DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
87
	if [ $TARGET = mozilla ]; then
88
	    DESTDIR="$DESTDIR"/browser
89
	fi
90
	DESTDIR="$DESTDIR"/extensions
91
    else
92
    	echo Warning: could not guess installation directory. >&2
93
    	echo Some make rules may fail. >&2
94
    fi
95
fi
96

    
97
# Write record.conf (LEAVE SRCDIR FIRST)
98
echo srcdir = "$SRCDIR" > record.conf
99
echo default_target = "$TARGET" >> record.conf
100
echo DESTDIR = "$DESTDIR" >> record.conf
101
echo UPDATE_URL = "$UPDATE_URL" >> record.conf
102

    
103

    
104
# Prepare and run write_makefile.sh (as config.status)
105
if [ ! -e config.status ]; then
106
    cp "$SRCDIR"/write_makefile.sh config.status
107
fi
108

    
109
./config.status
(5-5/13)