-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure
executable file
·139 lines (122 loc) · 4 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Copyright 2018-2019 Maarten de Vries <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PROJECT_ROOT="$(cd "$(dirname "$0")"; pwd)"
die() {
local pattern="$1"
shift
printf "$pattern\n" "$@" >&2
exit 1
}
short_usage() {
echo "usage: ./configure [--help] [PARAM=value ...]"
}
usage() {
short_usage
echo
echo "Command-line options:"
echo " --help -h Show this help message."
echo
echo "Parameters:"
echo " PREFIX=/usr/local Set the installation prefix."
echo " LIBDIR=lib Set the installation path for libraries."
echo " BINDIR=bin Set the installation path for binaries."
echo " DATADIR=share Set the installation path for data files."
echo " RELY_ON_SEARCH=false Rely on the system search path for finding the preload library."
echo
echo "If LIBDIR, BINDIR or DATADIR are given as relative path, they are interpreted relative to PREFIX."
echo
echo "If RELY_ON_SEARCH is set to true, the preload library will be added to LD_PRELOAD"
echo "as \"libcurl_inject_opt.so\" without absolute path. The dynamic linker will have"
echo "to find the library on it's own. This allows the preload library to be used even"
echo "with binaries that have elevated privileges on some systems (such as Linux)."
}
parse_single_config() {
local source="$1"
local arg="$2"
if ! [[ $arg =~ ([_a-zA-Z0-9]+)\ *=\ *(.*) ]]; then
short_usage >&2
die "\nunrecognized argument: %s" "$arg"
fi
name="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
case "$name" in
PREFIX) PREFIX="$value";;
LIBDIR) LIBDIR="$value";;
BINDIR) BINDIR="$value";;
DATADIR) DATADIR="$value";;
RELY_ON_SEARCH) RELY_ON_SEARCH="$value";;
*)
short_usage >&2
die "\nunrecognized parameter in %s: %s" "$source" "$name";;
esac
}
parse_config() {
while read arg; do
parse_single_config "cache" "$arg"
done
}
parse_args() {
for arg in "$@"; do
if [[ $arg == "--help" || $arg == "-h" ]]; then
usage
exit 0
fi
parse_single_config "command line" "$arg"
done
}
generate_config() {
cat <<EOF
PREFIX = $PREFIX
LIBDIR = $LIBDIR
BINDIR = $BINDIR
DATADIR = $DATADIR
RELY_ON_SEARCH = $RELY_ON_SEARCH
EOF
}
generate_make_config() {
cat <<EOF
PROJECT_ROOT = $PROJECT_ROOT
BUILD_DIR = $PWD
EOF
}
PREFIX="/usr/local"
LIBDIR="lib"
BINDIR="bin"
DATADIR="share"
RELY_ON_SEARCH="false"
[[ -f config.cache ]] && parse_config < config.cache
parse_args "$@"
printf "PREFIX: %s\n" "$PREFIX"
printf "LIBDIR: %s\n" "$LIBDIR"
printf "BINDIR: %s\n" "$BINDIR"
printf "DATADIR: %s\n" "$DATADIR"
printf "RELY_ON_SEARCH: %s\n" "$RELY_ON_SEARCH"
echo "Generating config.cache"
generate_config > config.cache
if [[ $PWD != $PROJECT_ROOT ]]; then
echo "Generating config.make"
generate_make_config > config.make
echo "Copying Makefile"
cp "$PROJECT_ROOT/Makefile" Makefile
fi