-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·233 lines (191 loc) · 6.57 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/sh
# Help message
# ------------
# The command line flags for this congfigure script are inspired by the GNU
# conventions. They are documented in the following links:
# https://www.gnu.org/prep/standards/html_node/Configuration.html
# https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html
show_usage() {
cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]...
Configure the installation location and compilation options for Xjump.
By default, \`make install' will install all the files under /usr/local.
You can use the --prefix flag to choose a different location. Defaults for the
options are specified in brackets.
To set compilation variables (e.g. CC, CFLAGS), specify them as VAR=VALUE.
Most of the time it's fine to leave these in the default setting. We use
pkg-config to figure out the appropriate compilation flags for SDL.
General:
-h, --help display this help and exit
Instalation directories:
--prefix=PREFIX root installation directory [/usr/local]
--bindir=DIR where to install executables [PREFIX/bin]
--datadir=DIR where to install data files [PREFIX/share]
Compilation variables:
CC C compiler command
CFLAGS C compiler flags (-O2 -Wall ...)
CPPFLAGS C preprocessor flags (-I<dir> ...)
LDFLAGS Linker flags (-L<dir> ...)
LIBS Libraries (-l<library> ...)
SDL_CFLAGS Additional flags for compiling with SDL2
SDL_LIBS Additional flags for linking with SDL2
EOF
}
# Default values
# --------------
# Note that all the following strings are single quoted. The idea is that we
# will pass the "$vars" as-is to the makefile, which will in turn perform macro
# and shell expansion. The GNU conventions expect this behavior so that we can
# override the installation directories when invoking make.
version='3.0.4'
# shellcheck disable=SC2016
{
prefix='/usr/local'
bindir='${prefix}/bin'
datadir='${prefix}/share'
appname='br.com.gualandi.Xjump'
othervars=
}
set_sdl_cflags=no
set_sdl_libs=no
set_othervars=no
# Command-line parsing
# --------------------
nl='
'
while test $# -gt 0; do
key=${1%%=*}
val=${1#*=}
case "$1" in
-h|--help)
show_usage
exit 0
;;
--prefix) prefix=$2; shift;;
--bindir) bindir=$2; shift;;
--datadir) datadir=$2; shift;;
--prefix=*|prefix=*) prefix=$val;;
--bindir=*|bindir=*) bindir=$val;;
--datadir=*|datadir=*) datadir=$val;;
--*|-*)
echo >&2 "ERROR: Unrecognized option $1"
exit 1
;;
SDL_CFLAGS=*)
SDL_CFLAGS=$val
set_sdl_cflags=yes
;;
SDL_LIBS=*)
SDL_LIBS=$val
set_sdl_libs=yes
;;
*=*)
othervars="${othervars}${key} = ${val}${nl}"
set_othervars=yes
;;
esac
shift
done
# Check for absolute directories
# ------------------------------
# The installation directories will be hardcoded into the executable so it is
# important that they be absolute directories. We also forbid any paths that
# start with a "~". They can be problematic because shell tilde expansion only
# happens if the tilde is at the start of the word. The end result is that
# the tilde would be expanded when we present the installation paths to the
# user but it not when those paths are used in other places.
# shellcheck disable=SC2154
for varname in prefix bindir datadir; do
eval "value=\$$varname"
case "$value" in
/*)
# Is an absolute path
;;
\$*)
# Assume that variable references expand to an absolute path
;;
\~*)
echo >&2 "ERROR: Please write \$HOME instead of ~ for the --$varname."
exit 1
;;
*)
echo >&2 "ERROR: Please specify an absolute path for --$varname."
echo >&2 " $value is not an absolute path."
exit 1
;;
esac
done
# Find where SDL is installed
# ---------------------------
if [ "$set_sdl_cflags" != yes ] || [ "$set_sdl_libs" != yes ]; then
# 1) Is SDL2 installed at all?
# ----------------------------
# Prefer pkg-config over sdl2-config
# See https://github.com/libsdl-org/SDL/issues/6140
if command -v pkg-config >/dev/null && pkg-config sdl2 --exists; then
config="pkg-config sdl2"
elif command -v sdl2-config >/dev/null; then
config="sdl2-config"
else
cat >&2 <<EOF
ERROR: We can't find the header files for SDL2. If the dev package for SDL is
not already installed, please install it. If you are certain that it is already
installed then you can avoid this error by manually specifying the SDL_CFLAGS
and SDL_LIBS environment variables before calling this configure script.
EOF
exit 1
fi
# 2) Find the header files
# ------------------------
if [ "$set_sdl_cflags" != "yes" ]; then
SDL_CFLAGS=$($config --cflags)
fi
if [ "$set_sdl_libs" != "yes" ]; then
SDL_LIBS=$($config --libs)
fi
fi
# Generate the config.mk
# ----------------------
# Store the information where the makefile can see it. The advantage of using
# an include file for the configuration, as opposed to generating the entire
# mkefile from a template, is that we don't need to rerun the configure script
# if we make changes to the makefile.
cat > config.mk <<EOF
# Generated by the ./configure script
version = $version
prefix = $prefix
bindir = $bindir
datadir = $datadir
appname = $appname
SDL_CFLAGS = $SDL_CFLAGS
SDL_LIBS = $SDL_LIBS
EOF
if [ "$set_othervars" = yes ]; then
printf "%s" "$othervars" >> config.mk
fi
# Report the results
# ------------------
# Finally, tell the user where things are going to be installed, showing the
# actual directories without the ${} indirections. The evals here are on
# purpose. Remember that the contents of these variables are subject to
# parameter expansion when they finally hit the shell inside the makefile.
eval prefix="$prefix"
eval bindir="$bindir"
eval datadir="$datadir"
cat <<EOF
Configuration sucessful.
Run \`make\` and \`sudo make install\` to proceed with the installation.
Xjump will be installed to : ${prefix}
Xjump will install executables in: ${bindir}
Xjump will install data files in : ${datadir}
EOF
if [ "$set_sdl_cflags" = yes ]; then
echo "SDL_CFLAGS = $SDL_CFLAGS"
fi
if [ "$set_sdl_libs" = yes ]; then
echo "SDL_LIBS = $SDL_LIBS"
fi
if [ "$set_othervars" = yes ]; then
printf "%s" "$othervars"
fi
exit 0