aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: 40f69708d42f827b4e7f430dec6ed9a7cb86165f (plain)
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/sh
cd "$(dirname $0)"

# ---
# Defaults.
# ---

# Project variables.

[ -f Makefile.cfg ] && mv Makefile.cfg Makefile.cfg.tmp
name="$(make -s getname)"
version="$(make -s getversion)"
indev="$(make -s isindev)"
maintainer="$(make -s getmaintainer)"
[ -f Makefile.cfg.tmp ] && mv Makefile.cfg.tmp Makefile.cfg

# Platform.

platform="$(command -v gcc 1>/dev/null && gcc --print-multiarch)"
platform="$([ "$platform" ] && echo "/$platform")"

# Make options.

make_full_log=
more_warnings=

# Build options.

target=
no_file=
no_libusb=
static=
windows=
optimize_size=
no_log=
loglevel=none # none, info, warn, error, fatal

default_zoom=8
default_storage=fls0

# Installation directories.

root=''
prefix='${root}/usr'
prefix_set=
hprefix='${root}/usr'
bindir='${prefix}/bin'
hbindir='${hprefix}/bin'
libdir='${prefix}/lib'"$platform"
includedir='${prefix}/include'"$platform"
pkgdir='${libdir}/pkgconfig'
mandir='${prefix}/share/man'

# Installation options.

install_devel=yes
install_manpages=yes

# Tweaks.

cflags=
ldflags=

# ---
# Help message.
# ---

usage() {
cat <<EOF
\`configure\` configures ${name} to adapt to systems that aren't mine.
Usage: $0 [OPTION]

Defaults for the options are specified in brackets.

General options:
  --help                    display this help and exit
  --version                 display version information and quit
  --make-full-log           display full commands while making
  --maintainer              enable maintainer mode

Build options:
  --target=TARGET           the target (if none, native)
  --static                  build a static library (by default, dynamic)
  --windows                 build DLLs and .libs instead of ELF and archives
  --optimize-size           optimize size instead of speed

  --no-file                 do not use the libc FILE interface
  --no-libusb               do not use libusb
  --no-log                  disable logging
  --loglevel=LOGLEVEL       default library log level [$loglevel]

  --default-zoom=ZOOM       the default zoom for p7screen [$default_zoom]
  --default-storage=STOR    the default storage device for p7 [$default_storage]

Installation options:
  --no-devel                do not install developement files
  --no-manpages             do not install manpages

Installation directories:
  --root=ROOT               installation root [$root]
  --prefix=PREFIX           main installation prefix [$prefix]
  --hprefix=HOSTPREFIX      host installation prefix [$hprefix]

Fine tuning of the installation directories:
  --hbindir=HOSTBINDIR      host executables [$hbindir]
  --bindir=BINDIR           target executables [$bindir]
  --pkgdir=PKGDIR           pkg-config configurations directory [$pkgdir]
  --libdir=LIBDIR           library files of the linker [$libdir]
  --includedir=INCDIR       include files for the compiler [$includedir]
  --mandir=MANDIR           man root [$mandir]

Other tweaks:
  CFLAGS=CFLAGS             some more compilation flags
  LDFLAGS=LDFLAGS           some more linker flags

Report bugs to ${maintainer}.
EOF
exit 0
}

# ---
# Version message.
# ---

version() {
cat <<EOF
${name} configure script v${version}
Hand-written by Thomas "Cakeisalie5" Touhey.

This configure script is free software.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
}

# ---
# Check for help and version.
# ---

put_version=
put_help=
for arg ; do case "$arg" in
--help|-h) put_help=1 ;;
--version|-v) put_version=1 ;;
esac; done
[ $put_version ] && version
[ $put_help ] && usage

# ---
# Parse arguments.
# ---

for arg ; do case "$arg" in
--make-full-log) make_full_log=yes ;;
--maintainer) more_warnings=yes; loglevel=info ;;
--target=*) target="${arg#*=}" ;;
--static) static=y ;;
--windows) windows=y ;;
--optimize-size) optimize_size=y ;;
--no-file) no_file=y ;;
--no-libusb) no_libusb=y ;;
--no-log) no_log=y ;;
--loglevel=*)
	level="${arg#*=}"
	# check if is in array
	if ! [ $level = "info" ] && ! [ $level = "warn" ] \
	&& ! [ $level = "error" ] && ! [ $level = "fatal" ] \
	&& ! [ $level = "none" ]; then
		echo \
"$0 : --loglevel: expected one of [info, warn, error, fatal, none], \
got '$level'"
		continue
	fi
	# then set
	loglevel=$level ;;
--default-zoom=*)
	zoom="${arg#*=}"
	if ! [ $zoom -eq $zoom 2>/dev/null ]; then
		echo "--default-zoom: a number is expected (got \"$zoom\")" >&2
	elif [ $zoom -lt 1 ]; then
		echo "--default-zoom: should be 1 or more (got $zoom)" >&2
	elif [ $zoom -gt 16 ]; then
		echo "--default-zoom: should be 16 or less (got $zoom)" >&2
	else default_zoom=$zoom; fi ;;
--default-storage=*)
	storage="${arg#*=}"
	# check if 4 chars long
	if [ ! $(echo "$storage" | wc -c ) -eq 5 ]; then
		echo "$0: --default-storage: must be 4 characters long"
		continue
	fi
	# then set
	default_storage="$storage" ;;
--no-devel) install_devel= ;;
--no-manpages) install_manpages= ;;
--root=*) root="${arg#*=}" ;;
--hprefix=*) hprefix="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}"; prefix_set=y ;;
--hbindir=*) hbindir="${arg#*=}" ;;
--bindir=*) bindir="${arg#*=}" ;;
--pkgdir=*) pkgdir="${arg#*=}" ;;
--libdir=*) libdir="${arg#*=}" ;;
--includedir=*) includedir="${arg#*=}" ;;
--mandir=*) mandir="${arg#*=}" ;;
CFLAGS=*) cflags="${arg#*=}" ;;
LDFLAGS=*) ldflags="${arg#*=}" ;;
*) echo "$arg: didn't read" ;;
esac; done

# ---
# Checks and tweaks.
# ---

# Cross-compilation things.

if [ ! $prefix_set ] && [ $target ]; then
	prefix="$prefix"/"$target"
fi

# Check MS-Windows targets.

win_target=
case "$target" in *-mingw32) if [ ! "$static" ]; then
	windows=y; win_target=y
fi;; esac

# Evaluate variables.

vars="prefix bindir libdir pkgdir includedir hprefix hbindir mandir"
for var in $vars; do
	eval $var'='$(eval 'echo $'$var)
done

# Check that static and MS-Windows are not asked.

if [ "$static" ] && [ "$windows" ]; then
cat >&2 <<EOF
Sadly, there is no equivalent of MSVC's LIB.EXE for GNU/Linux.
If you know one, contact the maintainer: see \`./configure --help\`.
EOF
exit 1
fi

# Check that MS-Windows has a target.

if [ "$windows" ] && [ ! "$target" ]; then
cat >&2 <<EOF
You have selected the --windows option, but have selected no target.
If you want to build for native use, use a mingw32/mingw64 target.
If you want to build for a cross-compiling use, specify an other target!
EOF
exit 1
fi

# Check if is on Cygwin.

[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ] && windows=y

# Check that MS-Windows has a mingw* target.

if [ "$windows" ] && [ ! "$win_target" ]; then
cat >&2 <<EOF
You have selected the --windows option, but have not selected a
mingw32/mingw64 target. We supposed that it is because you are compiling
libcasio for a cross-compiler compiled for MS-Windows
(that's why configuration won't fail).

If it is not, please reconfigure to use a mingw32/mingw64 toolchain!

EOF
fi

# ---
# Create Makefile configuration.
# ---

# Clean before.

make mrproper MAKE_FULL_LOG=y 1>/dev/null 2>/dev/null

# Create the configuration header.

tools/write-header-config --version=${version} \
	--maintainer="$(echo ${maintainer} | sed 's/"/\\"/g')" \
	$([ "$no_file" ] && echo --no-file) \
	$([ "$no_libusb" ] && echo --no-libusb) \
	$([ "$no_log" ] && echo --no-log) \
	>include/libcasio/config.h

# Do it!

exec 3>&1 1>Makefile.cfg
cat <<EOF
#!/usr/bin/make -f
#*****************************************************************************#
# Makefile configuration generated by ./configure                             #
#*****************************************************************************#
# Configuration version and messages configuration
 CONFIG_VERSION = $version
 MAKE_FULL_LOG = $make_full_log
 MORE_WARNINGS := $more_warnings
 FOR_WINDOWS := $windows

# Build options
 STATIC := $static
 TARGET = $target
 OPTIMIZE_SIZE := $optimize_size
 LOG_LEVEL = $loglevel
 NO_LIBUSB = $no_libusb
 DEFAULT_ZOOM := $default_zoom
 DEFAULT_STORAGE := $default_storage

# Installation directories
 HBINDIR = $hbindir
 IBINDIR = $bindir
 IPKGDIR = $pkgdir
 ILIBDIR = $libdir
 IINCDIR = $includedir
 IMANDIR = $mandir

# Installation options
 INSTALL_DEVEL = $install_devel
 INSTALL_MANPAGES = $install_manpages

# Other tweaks
 CMOREFLAGS := $cflags
 LDMOREFLAGS := $ldflags

# End of file.
EOF
exec 1>&3 3>&-
chmod +x Makefile.cfg

# Print the end message.

echo "Configuration loaded, you can make now."

# End of file.