| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# vim:set ts=4 et: |
| 4 |
# |
| 5 |
# generate config.mk for gbsplay Makefile |
| 6 |
# |
| 7 |
# 2003-2025 (C) by Christian Garbs <[email protected]> |
| 8 |
# Tobias Diedrich <[email protected]> |
| 9 |
# |
| 10 |
# Licensed under GNU GPL v1 or, at your option, any later version. |
| 11 |
# |
| 12 |
|
| 13 |
## initialize interpreter parameters |
| 14 |
|
| 15 |
set -u # bail on use of uninitialized variables |
| 16 |
trap 'exit_trap' EXIT |
| 17 |
|
| 18 |
## initialize variables |
| 19 |
|
| 20 |
EXTRA_ALL= |
| 21 |
EXTRA_INSTALL= |
| 22 |
EXTRA_SRCS= |
| 23 |
EXTRA_UNINSTALL= |
| 24 |
EXTRA_I18NFLAGS= |
| 25 |
CC="${CC-gcc}" # use gcc by default |
| 26 |
CONFIGURE_FLAGS="${CONFIGURE_FLAGS- }" |
| 27 |
CFLAGS="${CFLAGS-}" |
| 28 |
LDFLAGS="${LDFLAGS-}" |
| 29 |
HOSTCC="$CC" |
| 30 |
HOSTOS=$(uname) |
| 31 |
HOSTARCH=$(uname -m) |
| 32 |
BUILDCC="$HOSTCC" |
| 33 |
BUILDOS="$HOSTOS" |
| 34 |
BUILDARCH="$HOSTARCH" |
| 35 |
TMPDIR=${TMPDIR-/tmp} |
| 36 |
|
| 37 |
package=gbsplay |
| 38 |
prefix=/usr/local |
| 39 |
exec_prefix= |
| 40 |
bindir= |
| 41 |
libdir= |
| 42 |
mandir= |
| 43 |
docdir= |
| 44 |
localedir= |
| 45 |
mimedir= |
| 46 |
appdir= |
| 47 |
includedir= |
| 48 |
pkgconfigdir= |
| 49 |
sysconfdir= |
| 50 |
buildalias= |
| 51 |
hostalias= |
| 52 |
windows_build= |
| 53 |
windows_libprefix= |
| 54 |
|
| 55 |
EXTRA_INCLUDEDIRS_TO_CHECK= |
| 56 |
EXTRA_LIBDIRS_TO_CHECK= |
| 57 |
|
| 58 |
## define sane environment |
| 59 |
unset LC_ALL LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ |
| 60 |
LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ |
| 61 |
LC_MEASUREMENT LC_IDENTIFICATION |
| 62 |
LANG=C |
| 63 |
export LANG |
| 64 |
|
| 65 |
## set default version number to unknown |
| 66 |
# will be overwritten on git build or tar.gz export using 'make dist' |
| 67 |
VERSION=0.0.102 |
| 68 |
|
| 69 |
##### begin of subroutines |
| 70 |
|
| 71 |
exit_trap() |
| 72 |
{ |
| 73 |
EXIT_CODE=$? |
| 74 |
test $EXIT_CODE -ne 0 && tail config.err |
| 75 |
exit $EXIT_CODE |
| 76 |
} |
| 77 |
|
| 78 |
## die with error |
| 79 |
die() |
| 80 |
{ |
| 81 |
test -n "$1" && echo "$1" |
| 82 |
rm -rf "$TEMPDIR" |
| 83 |
exit 1 |
| 84 |
} |
| 85 |
|
| 86 |
## guesstimate most recent gbsplay release |
| 87 |
get_version_from_history() |
| 88 |
{ |
| 89 |
local date dash version |
| 90 |
while read -r date dash version _; do |
| 91 |
if [ "$dash" = - ] \ |
| 92 |
&&[[ $date =~ ^[0-9]{4}/[0-9]{2}/[0-9]{2} ]] \ |
| 93 |
&& [[ $version =~ [0-9]+.[0-9]+.[0-9]+ ]]; then |
| 94 |
# fix linebreaks on MSYS and MINGW builds - yuck! |
| 95 |
version=$(echo "${version}" | tr -d $'\r') |
| 96 |
echo "${version}ish" |
| 97 |
return |
| 98 |
fi |
| 99 |
done < HISTORY |
| 100 |
echo "undetermined" |
| 101 |
} |
| 102 |
|
| 103 |
## check for presense of include files |
| 104 |
check_include() |
| 105 |
{ |
| 106 |
local include="$1" |
| 107 |
local includedirs="${2-} /usr/local/include /opt/local/include ${EXTRA_INCLUDEDIRS_TO_CHECK}" |
| 108 |
local extraline="${3-}" |
| 109 |
local includename="$(echo "$include" | sed -e 's@[/\.-]@_@g')" |
| 110 |
eval "value=\${have_${includename}-}" |
| 111 |
test -z "$value" || return |
| 112 |
|
| 113 |
local flags="" |
| 114 |
for dir in "" $includedirs; do |
| 115 |
msg="checking for $include" |
| 116 |
test -z "$dir" || msg="$msg in $dir" |
| 117 |
test -z "$dir" || flags="-I$dir" |
| 118 |
if cc_check "$msg" "have_$includename" "$flags" ok <<EOF; then |
| 119 |
$extraline |
| 120 |
#include <$include> |
| 121 |
int main(int argc, char **argv) { |
| 122 |
return 0; |
| 123 |
} |
| 124 |
EOF |
| 125 |
eval "include_${includename}_path=\"$dir \"" |
| 126 |
return 0 |
| 127 |
fi |
| 128 |
done |
| 129 |
return 1 |
| 130 |
} |
| 131 |
|
| 132 |
## find library path needed for lib |
| 133 |
find_lib() |
| 134 |
{ |
| 135 |
local INFILE="$TEMPDIR/fl.c" |
| 136 |
local lib="$1" |
| 137 |
local libname="$(echo "$lib" | sed -e 's@[/\.-]@_@g')" |
| 138 |
local libdirs="${2-} /usr/local/lib /opt/local/lib ${EXTRA_LIBDIRS_TO_CHECK}" |
| 139 |
|
| 140 |
cat > "$INFILE" |
| 141 |
|
| 142 |
eval "val=\"\${lib${libname}_path-}\"" |
| 143 |
if [ ! -z "$val" ]; then |
| 144 |
return 0 |
| 145 |
else |
| 146 |
for dir in "" $libdirs; do |
| 147 |
msg="looking for -l$lib" |
| 148 |
flags="-l$lib" |
| 149 |
test -z "$dir" || msg="$msg in $dir" |
| 150 |
test -z "$dir" || flags="$flags -L$dir" |
| 151 |
if cc_check "$msg" "" "$flags" ok < "$INFILE"; then |
| 152 |
eval "lib${libname}_path=\"$dir \"" |
| 153 |
return 0 |
| 154 |
fi |
| 155 |
done |
| 156 |
fi |
| 157 |
return 1 |
| 158 |
} |
| 159 |
|
| 160 |
## remove duplicate flags |
| 161 |
remove_dupes() |
| 162 |
{ |
| 163 |
local flags="$1" |
| 164 |
local newflags="" |
| 165 |
for i in $flags; do |
| 166 |
local dupe=0 |
| 167 |
for j in $newflags; do |
| 168 |
test "$i" = "$j" && dupe=1 |
| 169 |
done |
| 170 |
if [ $dupe -eq 0 ]; then |
| 171 |
newflags="$(test -z "$newflags" || printf "%s " "$newflags")$i" |
| 172 |
fi |
| 173 |
done |
| 174 |
echo "$newflags" |
| 175 |
} |
| 176 |
|
| 177 |
append_nodupe() |
| 178 |
{ |
| 179 |
local varname="$1" |
| 180 |
local dupe=0 |
| 181 |
|
| 182 |
while [ -n "${2-}" ]; do |
| 183 |
eval "flags=\"\$$varname\"" |
| 184 |
local append="$2" |
| 185 |
|
| 186 |
if [ -n "$flags" ]; then |
| 187 |
for i in $flags; do |
| 188 |
test "$i" = "$append" && dupe=1 |
| 189 |
done |
| 190 |
fi |
| 191 |
|
| 192 |
if [ $dupe -eq 0 ]; then |
| 193 |
if [ -z "$flags" ]; then |
| 194 |
eval "${varname}=\"$append\"" |
| 195 |
else |
| 196 |
eval "${varname}=\"$flags $append\"" |
| 197 |
fi |
| 198 |
fi |
| 199 |
shift |
| 200 |
done |
| 201 |
} |
| 202 |
|
| 203 |
## check for needed extra libraries and library paths for a lib |
| 204 |
check_libs() |
| 205 |
{ |
| 206 |
local INFILE="$TEMPDIR/cl.c" |
| 207 |
local OUTFILE="$TEMPDIR/cl" |
| 208 |
local checklib="$1" |
| 209 |
local libname="$(echo "$checklib" | sed -e 's@[/\.-]@_@g' -e 's/ //g')" |
| 210 |
local extralibs="${checklib} ${2-}" |
| 211 |
local extralibdirs="${3-}" |
| 212 |
local name="${4-}" |
| 213 |
local extraflags="${5-}" |
| 214 |
local msg="${6-$checklib}" |
| 215 |
local cflags="$CFLAGS $LDFLAGS" |
| 216 |
|
| 217 |
# don't let -pedantic mess with our checks |
| 218 |
cflags="$(sed -E 's/-pedantic ?//g'<<<"$cflags")" |
| 219 |
|
| 220 |
eval "lib${libname}_flags=" |
| 221 |
|
| 222 |
cat > "$INFILE" |
| 223 |
|
| 224 |
cc_check "checking if we need additional libs for $msg" "" "$extraflags" "no" "yes" < "$INFILE" |
| 225 |
test $? -eq 0 && return 0 |
| 226 |
|
| 227 |
for extralib in $extralibs; do |
| 228 |
local libname="$(echo "$extralib" | sed -e 's@[/\.-]@_@g')" |
| 229 |
find_lib "$extralib" "$extralibdirs" < "$INFILE" |
| 230 |
test $? -ne 0 && return 1 |
| 231 |
eval "val=\"\$lib${libname}_path\"" |
| 232 |
if [ "$val" != " " ]; then |
| 233 |
append_nodupe extraflags "-L$val" |
| 234 |
fi |
| 235 |
done |
| 236 |
|
| 237 |
local minerrs=$($BUILDCC -o "$OUTFILE" "$INFILE" $cflags $extraflags 2>&1 | wc -l) |
| 238 |
for extralib in $extralibs; do |
| 239 |
local errs=$($BUILDCC -o "$OUTFILE" "$INFILE" $cflags "-l$extralib" $extraflags 2>&1 | wc -l) |
| 240 |
if [ "$errs" -lt "$minerrs" ]; then |
| 241 |
minerrs=$errs |
| 242 |
append_nodupe extraflags "-l$extralib" |
| 243 |
fi |
| 244 |
done |
| 245 |
|
| 246 |
if [ "$minerrs" -ne 0 ]; then |
| 247 |
echo "...but it still won't compile cleanly" |
| 248 |
# log the default result to config.err |
| 249 |
( |
| 250 |
echo "minerrs: $minerrs > 0" |
| 251 |
cat "$INFILE" |
| 252 |
$BUILDCC -o "$OUTFILE" "$INFILE" $cflags "-l$checklib" $extraflags |
| 253 |
) 1>&2 |
| 254 |
return 1 |
| 255 |
fi |
| 256 |
|
| 257 |
eval "lib${libname}_flags=\"$extraflags\"" |
| 258 |
return 0 |
| 259 |
} |
| 260 |
|
| 261 |
## generalized 'does it compile' check |
| 262 |
cc_check() |
| 263 |
{ |
| 264 |
local INFILE="$TEMPDIR/cc.c" |
| 265 |
local OUTFILE="$TEMPDIR/cc" |
| 266 |
local name="$1" |
| 267 |
local varname="$2" |
| 268 |
local flags="$CFLAGS $LDFLAGS ${3-}" |
| 269 |
local okmsg="${4-ok}" |
| 270 |
local errmsg="${5-not found}" |
| 271 |
|
| 272 |
test "$name" && printf "%s: " "$name" |
| 273 |
|
| 274 |
cat > "$INFILE" |
| 275 |
|
| 276 |
if "$BUILDCC" -o "$OUTFILE" "$INFILE" $flags; then |
| 277 |
test "$name" && echo "$okmsg" |
| 278 |
test "$varname" && eval "$varname=yes" |
| 279 |
return 0 |
| 280 |
else |
| 281 |
test "$name" && echo "$errmsg" |
| 282 |
test "$varname" && eval "$varname=no" |
| 283 |
return 1 |
| 284 |
fi |
| 285 |
} |
| 286 |
|
| 287 |
cc_has_flag() |
| 288 |
{ |
| 289 |
local flag="$1" |
| 290 |
cc_check "checking if cc supports ${flag}" "" "${flag} -Werror" yes no <<EOF |
| 291 |
int main(int argc, char **argv) { return 0; } |
| 292 |
EOF |
| 293 |
} |
| 294 |
|
| 295 |
need_include() { |
| 296 |
if ! check_include "$1"; then |
| 297 |
die "Could not find $1, which is needed for compilation." |
| 298 |
fi |
| 299 |
} |
| 300 |
|
| 301 |
## config.h helper |
| 302 |
have_x() { |
| 303 |
local localvar="have_$(echo $1 | tr A-Z a-z)" |
| 304 |
eval "result=\$$localvar" |
| 305 |
if [ "$result" = "yes" ]; then |
| 306 |
echo "#define HAVE_$1 1" |
| 307 |
else |
| 308 |
echo "/* #undef HAVE_$1 */" |
| 309 |
fi |
| 310 |
} |
| 311 |
|
| 312 |
plugout_x() { |
| 313 |
local localvar="use_$(echo $1 | tr A-Z a-z)" |
| 314 |
eval "result=\$$localvar" |
| 315 |
if [ "$result" = "yes" ]; then |
| 316 |
echo "#define PLUGOUT_$1 1" |
| 317 |
else |
| 318 |
echo "/* #undef PLUGOUT_$1 */" |
| 319 |
fi |
| 320 |
} |
| 321 |
|
| 322 |
use_x() { |
| 323 |
local localvar="use_$(echo $1 | tr A-Z a-z)" |
| 324 |
eval "result=\$$localvar" |
| 325 |
if [ "$result" = "yes" ]; then |
| 326 |
echo "#define USE_$1 1" |
| 327 |
else |
| 328 |
echo "/* #undef USE_$1 */" |
| 329 |
fi |
| 330 |
} |
| 331 |
|
| 332 |
# set variable to default value if empty |
| 333 |
# really the same as $var="${var-$default}" |
| 334 |
setdefault() |
| 335 |
{ |
| 336 |
eval "value=\$$1" |
| 337 |
if [ -z "$value" ]; then |
| 338 |
eval "$1=$2" |
| 339 |
fi |
| 340 |
} |
| 341 |
|
| 342 |
# check if $1 is a known feature |
| 343 |
isknown() |
| 344 |
{ |
| 345 |
for i in $OPTS; do |
| 346 |
if [ "$i" = "$1" ]; then |
| 347 |
return 0 |
| 348 |
fi |
| 349 |
done |
| 350 |
|
| 351 |
if [ "${1#use_}" != "$1" ]; then |
| 352 |
echo "unknown feature '${1#use_}'" |
| 353 |
elif [ "${1#build_}" != "$1" ]; then |
| 354 |
echo "unknown module '${1#build_}'" |
| 355 |
else |
| 356 |
echo "unknown option '$2'" |
| 357 |
fi |
| 358 |
echo |
| 359 |
return 1 |
| 360 |
} |
| 361 |
|
| 362 |
# list enabled $1 (modules, features) |
| 363 |
# of type $2 (build, use) |
| 364 |
printoptional() |
| 365 |
{ |
| 366 |
printf "%s %s:" "${3-optional}" "$1" |
| 367 |
for i in $OPTS; do |
| 368 |
eval "val=\$$i" |
| 369 |
if [ "${i#${2}_}" != "$i" ]; then |
| 370 |
if [ "$val" = "yes" ]; then |
| 371 |
printf " +%s" "${i#${2}_}" |
| 372 |
elif [ "$val" = "no" ]; then |
| 373 |
printf " -%s" "${i#${2}_}" |
| 374 |
fi |
| 375 |
fi |
| 376 |
done |
| 377 |
echo |
| 378 |
} |
| 379 |
|
| 380 |
# remember state of use_$1 |
| 381 |
remember_use() |
| 382 |
{ |
| 383 |
eval "remembered=\$use_$1" |
| 384 |
} |
| 385 |
|
| 386 |
# check state of use_$1 against remembered state |
| 387 |
# error out if option was requested but can't be satisfied after checks |
| 388 |
recheck_use() |
| 389 |
{ |
| 390 |
eval "val=\$use_$1" |
| 391 |
if [ "$remembered" = 'yes' ] && [ "$val" != 'yes' ]; then |
| 392 |
die "error: --enable-$1 was requested but is not available" |
| 393 |
fi |
| 394 |
} |
| 395 |
|
| 396 |
# parse option $1 |
| 397 |
parseoption() |
| 398 |
{ |
| 399 |
case $1 in |
| 400 |
--prefix=*) |
| 401 |
prefix="${1#--prefix=}" |
| 402 |
;; |
| 403 |
--exec-prefix=*) |
| 404 |
exec_prefix="${1#--exec-prefix=}" |
| 405 |
;; |
| 406 |
--bindir=*) |
| 407 |
bindir="${1#--bindir=}" |
| 408 |
;; |
| 409 |
--mandir=*) |
| 410 |
mandir="${1#--mandir=}" |
| 411 |
;; |
| 412 |
--docdir=*) |
| 413 |
docdir="${1#--docdir=}" |
| 414 |
;; |
| 415 |
--localedir=*) |
| 416 |
localedir="${1#--localedir=}" |
| 417 |
;; |
| 418 |
--mimedir=*) |
| 419 |
mimedir="${1#--mimedir=}" |
| 420 |
;; |
| 421 |
--appdir=*) |
| 422 |
appdir="${1#--appdir=}" |
| 423 |
;; |
| 424 |
--includedir=*) |
| 425 |
includedir="${1#--includedir=}" |
| 426 |
;; |
| 427 |
--pkgconfigdir=*) |
| 428 |
pkgconfigdir="${1#--pkgconfigdir=}" |
| 429 |
;; |
| 430 |
--sysconfdir=*) |
| 431 |
sysconfdir="${1#--sysconfdir=}" |
| 432 |
;; |
| 433 |
--infodir=*) |
| 434 |
infodir="${1#--infodir=}" |
| 435 |
;; |
| 436 |
--datadir=*) |
| 437 |
datadir="${1#--datadir=}" |
| 438 |
;; |
| 439 |
--localstatedir=*) |
| 440 |
localstatedir="${1#--localstatedir=}" |
| 441 |
;; |
| 442 |
--host=*) |
| 443 |
hostalias="${1#--host=}" |
| 444 |
HOSTCC="${hostalias}-${CC}" |
| 445 |
;; |
| 446 |
--build=*) |
| 447 |
buildalias="${1#--build=}" |
| 448 |
BUILDCC="${buildalias}-${CC}" |
| 449 |
;; |
| 450 |
--have-*) |
| 451 |
eval "have_${1#--have-}=yes" |
| 452 |
isknown "have_${1#--have-}" "$1" || usage 1 |
| 453 |
;; |
| 454 |
--donthave-*) |
| 455 |
eval "have_${1#--donthave-}=no" |
| 456 |
isknown "have_${1#--donthave-}" "$1" || usage 1 |
| 457 |
;; |
| 458 |
--enable-*) |
| 459 |
eval "use_${1#--enable-}=yes" |
| 460 |
isknown "use_${1#--enable-}" || usage 1 |
| 461 |
;; |
| 462 |
--disable-*) |
| 463 |
eval "use_${1#--disable-}=no" |
| 464 |
isknown "use_${1#--disable-}" || usage 1 |
| 465 |
;; |
| 466 |
--with-*) |
| 467 |
eval "build_${1#--with-}=yes" |
| 468 |
isknown "build_${1#--with-}" || usage 1 |
| 469 |
;; |
| 470 |
--without-*) |
| 471 |
eval "build_${1#--without-}=no" |
| 472 |
isknown "build_${1#--without-}" || usage 1 |
| 473 |
;; |
| 474 |
CFLAGS=*) |
| 475 |
CFLAGS="${1#CFLAGS=}" |
| 476 |
;; |
| 477 |
LDFLAGS=*) |
| 478 |
LDFLAGS="${1#LDFLAGS=}" |
| 479 |
;; |
| 480 |
--help) |
| 481 |
usage 0 |
| 482 |
;; |
| 483 |
*) |
| 484 |
echo "unknown option '$1'" |
| 485 |
echo |
| 486 |
usage 1 |
| 487 |
;; |
| 488 |
esac |
| 489 |
} |
| 490 |
##### end of subroutines |
| 491 |
|
| 492 |
## enable logging of errors |
| 493 |
|
| 494 |
ERRORLOG=config.err |
| 495 |
exec 2> $ERRORLOG |
| 496 |
|
| 497 |
## find a path for tmp directory |
| 498 |
|
| 499 |
TMPPATH="/tmp" |
| 500 |
if [ "$TMPDIR" ]; then |
| 501 |
TMPPATH="$TMPDIR" |
| 502 |
fi |
| 503 |
|
| 504 |
if [ ! -d "$TMPPATH" ]; then |
| 505 |
TMPPATH="." |
| 506 |
fi |
| 507 |
|
| 508 |
## generate tmp directory |
| 509 |
|
| 510 |
BASENAME="$(basename "$0")" |
| 511 |
if command -v mktemp >/dev/null; then |
| 512 |
TEMPDIR="$(mktemp -d "$TMPPATH/$BASENAME.XXXXXXXXXX")" |
| 513 |
RESULT=$? |
| 514 |
else |
| 515 |
TEMPDIR="$TMPPATH/$BASENAME.$$" |
| 516 |
mkdir "$TEMPDIR" |
| 517 |
RESULT=$? |
| 518 |
fi |
| 519 |
if [ $RESULT -ne 0 ]; then |
| 520 |
echo "can't create temporary directory at <$TMPPATH>!" |
| 521 |
exit 1; |
| 522 |
fi |
| 523 |
|
| 524 |
usage() |
| 525 |
{ |
| 526 |
cat<<EOF |
| 527 |
Usage: $0 [OPTION]... |
| 528 |
|
| 529 |
Configuration: |
| 530 |
--help display this help and exit |
| 531 |
|
| 532 |
Installation directories: |
| 533 |
--prefix=PREFIX install architecture-independent files in PREFIX |
| 534 |
[/usr/local] |
| 535 |
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX |
| 536 |
[PREFIX] |
| 537 |
--bindir=BINDIR install binaries in BINDIR |
| 538 |
[EPREFIX/bin] |
| 539 |
--libdir=BINDIR install binaries in LIBDIR |
| 540 |
[EPREFIX/lib] |
| 541 |
--mandir=MANDIR install manpages in MANDIR |
| 542 |
[PREFIX/man] |
| 543 |
--docdir=DOCDIR install documentation in DOCDIR |
| 544 |
[PREFIX/share/doc/$package] |
| 545 |
--sysconfdir=SCONFDIR look for system-wide configuration file in SCONFDIR |
| 546 |
[/etc] |
| 547 |
|
| 548 |
Optional Features: |
| 549 |
--disable-i18n omit libintl support |
| 550 |
--disable-hardening disable hardening flags |
| 551 |
--disable-zlib disable transparent gzip decompression |
| 552 |
--enable-debug build with debug code |
| 553 |
--enable-sharedlibgbs build libgbs as a shared library |
| 554 |
--enable-verbosebuild give verbose output during build |
| 555 |
|
| 556 |
Optional Modules: |
| 557 |
--with-xgbsplay build graphical frontend xgbsplay |
| 558 |
--without-contrib don't install contrib scripts |
| 559 |
--without-test don't test gbsplay output during build |
| 560 |
|
| 561 |
Output Plugins: |
| 562 |
--disable-alsa omit ALSA sound output plugin |
| 563 |
--disable-devdsp omit /dev/dsp sound output plugin |
| 564 |
--disable-dsound omit Direct Sound output plugin |
| 565 |
--disable-iodumper omit iodumper plugin |
| 566 |
--disable-midi omit MIDI file writer plugin |
| 567 |
--disable-altmidi omit alternative MIDI file writer plugin |
| 568 |
--disable-nas omit NAS sound output plugin |
| 569 |
--disable-pipewire omit PipeWire sound output plugin |
| 570 |
--disable-pulse omit PulseAudio sound output plugin |
| 571 |
--disable-sdl omit SDL sound output plugin |
| 572 |
--disable-stdout omit stdout file writer plugin |
| 573 |
--disable-vgm omit VGM file writer plugin |
| 574 |
--disable-wav omit WAV file writer plugin |
| 575 |
EOF |
| 576 |
exit "$1" |
| 577 |
} |
| 578 |
|
| 579 |
OPTS="" |
| 580 |
OPTS="${OPTS} build_contrib" |
| 581 |
OPTS="${OPTS} build_test" |
| 582 |
OPTS="${OPTS} build_xgbsplay" |
| 583 |
OPTS="${OPTS} use_alsa" |
| 584 |
OPTS="${OPTS} use_debug" |
| 585 |
OPTS="${OPTS} use_devdsp" |
| 586 |
OPTS="${OPTS} use_dsound" |
| 587 |
OPTS="${OPTS} use_hardening" |
| 588 |
OPTS="${OPTS} use_i18n" |
| 589 |
OPTS="${OPTS} use_iodumper" |
| 590 |
OPTS="${OPTS} use_midi" |
| 591 |
OPTS="${OPTS} use_altmidi" |
| 592 |
OPTS="${OPTS} use_nas" |
| 593 |
OPTS="${OPTS} use_pipewire" |
| 594 |
OPTS="${OPTS} use_pulse" |
| 595 |
OPTS="${OPTS} use_sdl" |
| 596 |
OPTS="${OPTS} use_sharedlibgbs" |
| 597 |
OPTS="${OPTS} use_stdout" |
| 598 |
OPTS="${OPTS} use_vgm" |
| 599 |
OPTS="${OPTS} use_wav" |
| 600 |
OPTS="${OPTS} use_verbosebuild" |
| 601 |
OPTS="${OPTS} use_zlib" |
| 602 |
for OPT in $OPTS; do |
| 603 |
eval "${OPT}=" |
| 604 |
done |
| 605 |
|
| 606 |
## load user config |
| 607 |
if [ -f config.conf ]; then |
| 608 |
printf "loading config.conf... " |
| 609 |
while read -r line; do |
| 610 |
parseoption "$line" |
| 611 |
done < config.conf |
| 612 |
echo ok |
| 613 |
fi |
| 614 |
|
| 615 |
## flags from CONFIGURE_FLAGS env (for travis-ci) |
| 616 |
for flag in ${CONFIGURE_FLAGS}; do |
| 617 |
parseoption "$flag" |
| 618 |
done |
| 619 |
|
| 620 |
## commandline flags |
| 621 |
while [ "${1-}" ]; do |
| 622 |
parseoption "$1" |
| 623 |
shift |
| 624 |
done |
| 625 |
|
| 626 |
case "$BUILDOS" in |
| 627 |
Linux) |
| 628 |
if { [ "$BUILDARCH" = "i386" ] \ |
| 629 |
|| [ "$BUILDARCH" = "i486" ] \ |
| 630 |
|| [ "$BUILDARCH" = "i586" ] \ |
| 631 |
|| [ "$BUILDARCH" = "i686" ] \ |
| 632 |
|| [ "$BUILDARCH" = "x86_64" ]; \ |
| 633 |
}; then |
| 634 |
setdefault build_test yes |
| 635 |
else |
| 636 |
# expected test failures: |
| 637 |
# MD5 sum mismatch due to floating point discrepancies in libimpulse |
| 638 |
setdefault build_test no |
| 639 |
fi |
| 640 |
;; |
| 641 |
|
| 642 |
Darwin) |
| 643 |
setdefault build_test yes |
| 644 |
append_nodupe CFLAGS "-D_DARWIN_C_SOURCE=1" |
| 645 |
EXTRA_INCLUDEDIRS_TO_CHECK=/opt/homebrew/include |
| 646 |
EXTRA_LIBDIRS_TO_CHECK=/opt/homebrew/lib |
| 647 |
;; |
| 648 |
|
| 649 |
MSYS_*) |
| 650 |
setdefault build_test yes |
| 651 |
;; |
| 652 |
|
| 653 |
MINGW32_*|MINGW64_*) |
| 654 |
# known test failure: |
| 655 |
# - util.c does not test-compile properly |
| 656 |
# - srand(0) in test_shuffle() in util.c gives a different order |
| 657 |
setdefault build_test no |
| 658 |
;; |
| 659 |
|
| 660 |
*) |
| 661 |
setdefault build_test no |
| 662 |
;; |
| 663 |
esac |
| 664 |
|
| 665 |
## more defaults |
| 666 |
setdefault build_xgbsplay no |
| 667 |
setdefault build_contrib yes |
| 668 |
## disable test when cross-compiling |
| 669 |
if [ -n "$buildalias" ] && [ "$buildalias" != "$hostalias" ]; then |
| 670 |
build_test=no |
| 671 |
fi |
| 672 |
|
| 673 |
## determine version that is built |
| 674 |
|
| 675 |
if [ -f .git/HEAD ]; then |
| 676 |
# from git if the build happens in a repository |
| 677 |
if ! VERSION=$(git describe --tags); then |
| 678 |
# no tags available (we might be in a GitHub CI build), so cobble something together |
| 679 |
if ! gitversion=$(git describe --tags --always); then |
| 680 |
# we might be in a GitHub CI build where no git command is available (eg. the FreeBSD build VM) |
| 681 |
if [ "$GITHUB_SHA" ]; then |
| 682 |
gitversion="${GITHUB_SHA::7}" |
| 683 |
else |
| 684 |
gitversion="unknown" |
| 685 |
fi |
| 686 |
fi |
| 687 |
VERSION="$(get_version_from_history)-git-${gitversion}" |
| 688 |
fi |
| 689 |
elif [ "$VERSION" = unknown ]; then |
| 690 |
# get a rough version number based on HISTORY file |
| 691 |
VERSION="$(get_version_from_history)" |
| 692 |
fi |
| 693 |
echo "configure gbsplay $VERSION" |
| 694 |
|
| 695 |
## check for C compiler |
| 696 |
|
| 697 |
printf "checking for working compiler: " |
| 698 |
INFILE="$TEMPDIR/cc.c" |
| 699 |
OUTFILE="$TEMPDIR/cc" |
| 700 |
|
| 701 |
cat > "$INFILE" <<EOF |
| 702 |
int main(int argc, char **argv) { |
| 703 |
return 0; |
| 704 |
} |
| 705 |
EOF |
| 706 |
$BUILDCC -o "$OUTFILE" "$INFILE" $CFLAGS $LDFLAGS |
| 707 |
RESULT=$? |
| 708 |
if [ $RESULT -eq 0 ]; then |
| 709 |
if [ "$buildalias" ] && [ "$buildalias" != "$hostalias" ]; then |
| 710 |
echo "cross-compiling, skipping execute check" |
| 711 |
else |
| 712 |
if [ -s "$OUTFILE" ]; then |
| 713 |
if "$OUTFILE"; then |
| 714 |
echo "ok" |
| 715 |
else |
| 716 |
die "can't execute generated code" |
| 717 |
fi |
| 718 |
else |
| 719 |
die "no code generated" |
| 720 |
fi |
| 721 |
fi |
| 722 |
else |
| 723 |
die "error executing '$BUILDCC'" |
| 724 |
fi |
| 725 |
|
| 726 |
## check for windows environment |
| 727 |
|
| 728 |
# see http://msys2.org/wiki/Porting/ |
| 729 |
cc_check "checking if target is windows" windows_build "" yes no <<EOF |
| 730 |
int main(int argc, char **argv) |
| 731 |
{ |
| 732 |
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) |
| 733 |
return 0; |
| 734 |
#else |
| 735 |
not windows, fail compile |
| 736 |
#endif |
| 737 |
} |
| 738 |
EOF |
| 739 |
if [ "$windows_build" = yes ]; then |
| 740 |
# stack-protector has some bugs on Windows |
| 741 |
setdefault use_hardening no |
| 742 |
# don't look for audio libs that are unavailable on Windows |
| 743 |
setdefault use_alsa no |
| 744 |
setdefault use_nas no |
| 745 |
setdefault use_pipewire no |
| 746 |
setdefault use_pulse no |
| 747 |
if cc_check "" "" "" <<EOF; then |
| 748 |
int main(int argc, char **argv) |
| 749 |
{ |
| 750 |
#if defined(__MSYS__) |
| 751 |
return 0; |
| 752 |
#else |
| 753 |
not msys, fail compile |
| 754 |
#endif |
| 755 |
} |
| 756 |
EOF |
| 757 |
windows_libprefix=msys2 |
| 758 |
elif cc_check "" "" "" <<EOF; then |
| 759 |
int main(int argc, char **argv) |
| 760 |
{ |
| 761 |
#if defined(__CYGWIN__) |
| 762 |
return 0; |
| 763 |
#else |
| 764 |
not cygwin, fail compile |
| 765 |
#endif |
| 766 |
} |
| 767 |
EOF |
| 768 |
windows_libprefix=cyg |
| 769 |
else |
| 770 |
# mingw |
| 771 |
windows_libprefix=lib |
| 772 |
fi |
| 773 |
else |
| 774 |
# not windows |
| 775 |
setdefault use_hardening yes |
| 776 |
fi |
| 777 |
|
| 778 |
## check for various headers |
| 779 |
|
| 780 |
need_include inttypes.h |
| 781 |
|
| 782 |
if [ "$use_zlib" != no ]; then |
| 783 |
remember_use zlib |
| 784 |
check_include zlib.h |
| 785 |
retval1=$? |
| 786 |
retval2=1 |
| 787 |
if [ $retval1 -eq 0 ]; then |
| 788 |
check_libs "z" <<EOF |
| 789 |
#include <zlib.h> |
| 790 |
int main(int argc, char** argv) { |
| 791 |
z_stream strm = {0}; |
| 792 |
inflateInit(&strm); |
| 793 |
return 0; |
| 794 |
} |
| 795 |
EOF |
| 796 |
retval2=$? |
| 797 |
fi |
| 798 |
use_zlib=no |
| 799 |
if [ "$retval1" -eq 0 ] && [ "$retval2" -eq 0 ]; then |
| 800 |
use_zlib="$have_zlib_h" |
| 801 |
append_nodupe LDFLAGS "-lz" |
| 802 |
fi |
| 803 |
recheck_use zlib |
| 804 |
fi |
| 805 |
|
| 806 |
if [ "$use_devdsp" != no ]; then |
| 807 |
remember_use devdsp |
| 808 |
check_include sys/soundcard.h |
| 809 |
use_devdsp="$have_sys_soundcard_h" |
| 810 |
# this check is needed for FreeBSD but it only works when the C11 flags are used |
| 811 |
C11_FLAGS="-D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L" |
| 812 |
if [ "$have_sys_soundcard_h" = yes ]; then |
| 813 |
if ! cc_check "checking if we need additional flags for sys/soundcard.h" "" "$C11_FLAGS" "no" "yes" <<EOF; then |
| 814 |
#include <sys/soundcard.h> |
| 815 |
int main(int argc, char **argv) |
| 816 |
{ |
| 817 |
#ifdef OPEN_SOUND_SYSTEM |
| 818 |
return 0; |
| 819 |
#else |
| 820 |
return 1; |
| 821 |
#endif |
| 822 |
} |
| 823 |
EOF |
| 824 |
|
| 825 |
if cc_check "checking if we need __BSD_VISIBLE for sys/soundcard.h" "" "$C11_FLAGS -D__BSD_VISIBLE" "yes" "no" <<EOF; then |
| 826 |
#include <sys/soundcard.h> |
| 827 |
int main(int argc, char **argv) |
| 828 |
{ |
| 829 |
#ifdef OPEN_SOUND_SYSTEM |
| 830 |
return 0; |
| 831 |
#else |
| 832 |
return 1; |
| 833 |
#endif |
| 834 |
} |
| 835 |
EOF |
| 836 |
append_nodupe CFLAGS "-D__BSD_VISIBLE" |
| 837 |
else |
| 838 |
echo "no way found to make sys/soundcard.h work" |
| 839 |
use_devdsp=no |
| 840 |
fi |
| 841 |
fi |
| 842 |
fi |
| 843 |
recheck_use devdsp |
| 844 |
fi |
| 845 |
|
| 846 |
if [ "$use_alsa" != no ]; then |
| 847 |
remember_use alsa |
| 848 |
check_include alsa/asoundlib.h |
| 849 |
use_alsa="$have_alsa_asoundlib_h" |
| 850 |
cc_check "checking for ESTRPIPE support" have_estrpipe <<EOF |
| 851 |
#include <errno.h> |
| 852 |
#include <alsa/asoundlib.h> |
| 853 |
int main(int argc, char **argv) |
| 854 |
{ |
| 855 |
if (ESTRPIPE == 0) |
| 856 |
return 1; /* Never reached. */ |
| 857 |
return 0; |
| 858 |
} |
| 859 |
EOF |
| 860 |
recheck_use alsa |
| 861 |
fi |
| 862 |
|
| 863 |
if [ "$use_dsound" != no ]; then |
| 864 |
remember_use dsound |
| 865 |
check_include dsound.h /usr/include/w32api "#include <windows.h>" |
| 866 |
retval1=$? |
| 867 |
retval2=1 |
| 868 |
if [ $retval1 -eq 0 ]; then |
| 869 |
check_libs dsound <<EOF |
| 870 |
#include <windows.h> |
| 871 |
#include <dsound.h> |
| 872 |
int main(int argc, char** argv) { |
| 873 |
LPDIRECTSOUND8 lp; |
| 874 |
HRESULT hr = DirectSoundCreate8(NULL, &lp, NULL); |
| 875 |
if (SUCCEEDED(hr)) IDirectSound8_Release(lp); |
| 876 |
return 0; |
| 877 |
} |
| 878 |
EOF |
| 879 |
retval2=$? |
| 880 |
fi |
| 881 |
use_dsound=no |
| 882 |
if [ "$retval1" -eq 0 ] && [ "$retval2" -eq 0 ]; then |
| 883 |
use_dsound="$have_dsound_h" |
| 884 |
fi |
| 885 |
recheck_use dsound |
| 886 |
fi |
| 887 |
|
| 888 |
if [ "$use_pipewire" != no ]; then |
| 889 |
remember_use pipewire |
| 890 |
|
| 891 |
pipewire_version='libpipewire-0.3' |
| 892 |
if command -v pkg-config >/dev/null && pkg-config ${pipewire_version}; then |
| 893 |
pipewire_have_pkg_config=yes |
| 894 |
else |
| 895 |
pipewire_have_pkg_config=no |
| 896 |
fi |
| 897 |
|
| 898 |
if [ "$pipewire_have_pkg_config" = yes ]; then |
| 899 |
pipewire_include_flags="$(pkg-config --cflags-only-I ${pipewire_version})" |
| 900 |
pipewire_cflags="$(pkg-config --cflags-only-other ${pipewire_version})" |
| 901 |
else |
| 902 |
pipewire_include_flags='-I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2' |
| 903 |
pipewire_cflags='' |
| 904 |
fi |
| 905 |
pipewire_include_path="$(sed -e 's/^-I//' -e 's/ -I/ /g' <<<"${pipewire_include_flags}")" |
| 906 |
|
| 907 |
check_include spa/support/plugin.h "$pipewire_include_path" |
| 908 |
if [ "$have_spa_support_plugin_h" = yes ]; then |
| 909 |
append_nodupe CFLAGS "-I${include_spa_support_plugin_h_path}" |
| 910 |
check_include pipewire/pipewire.h "$pipewire_include_path" |
| 911 |
if [ "$have_pipewire_pipewire_h" = yes ]; then |
| 912 |
append_nodupe CFLAGS "-I${include_pipewire_pipewire_h_path} ${pipewire_cflags}" |
| 913 |
|
| 914 |
if [ "$pipewire_have_pkg_config" = yes ]; then |
| 915 |
pipewire_ldpath_flags="$(pkg-config --libs-only-L ${pipewire_version})" |
| 916 |
pipewire_libname_flags="$(pkg-config --libs-only-l ${pipewire_version})" |
| 917 |
pipewire_ldflags="$(pkg-config --libs-only-other ${pipewire_version})" |
| 918 |
else |
| 919 |
pipewire_ldpath_flags='' |
| 920 |
pipewire_libname_flags='-lpipewire-0.3' |
| 921 |
pipewire_ldflags='' |
| 922 |
fi |
| 923 |
pipewire_ldpath="$(sed -e 's/^-L//' -e 's/ -L/ /g' <<<"${pipewire_ldpath_flags}")" |
| 924 |
pipewire_libname="${pipewire_libname_flags#*-l}" |
| 925 |
|
| 926 |
check_libs "${pipewire_libname}" "" "${pipewire_ldpath}" "" "${pipewire_ldflags}" <<EOF |
| 927 |
#include <pipewire/pipewire.h> |
| 928 |
int main(int argc, char **argv) { |
| 929 |
pw_init(0, NULL); |
| 930 |
pw_deinit(); |
| 931 |
return 0; |
| 932 |
} |
| 933 |
EOF |
| 934 |
if [ "$?" -eq 0 ]; then |
| 935 |
use_pipewire=yes |
| 936 |
fi |
| 937 |
fi |
| 938 |
fi |
| 939 |
|
| 940 |
recheck_use pipewire |
| 941 |
fi |
| 942 |
|
| 943 |
if [ "$use_pulse" != no ]; then |
| 944 |
remember_use pulse |
| 945 |
check_include pulse/simple.h |
| 946 |
use_pulse="$have_pulse_simple_h" |
| 947 |
recheck_use pulse |
| 948 |
fi |
| 949 |
|
| 950 |
if [ "$use_nas" != no ]; then |
| 951 |
remember_use nas |
| 952 |
check_include audio/audiolib.h "/usr/X11R6/include" |
| 953 |
retval1=$? |
| 954 |
retval2=1 |
| 955 |
if [ $retval1 -eq 0 ]; then |
| 956 |
check_libs audio "X11 Xt m" "/usr/X11R6/lib /usr/X11/lib /usr/lib/X11" <<EOF |
| 957 |
int main(int argc, char **argv) { return 0; } |
| 958 |
EOF |
| 959 |
retval2=$? |
| 960 |
fi |
| 961 |
use_nas=no |
| 962 |
if [ "$retval1" -eq 0 ] && [ "$retval2" -eq 0 ]; then |
| 963 |
if [ "$include_audio_audiolib_h_path" != " " ]; then |
| 964 |
append_nodupe CFLAGS "-I$include_audio_audiolib_h_path" |
| 965 |
fi |
| 966 |
use_nas=yes |
| 967 |
fi |
| 968 |
recheck_use nas |
| 969 |
fi |
| 970 |
|
| 971 |
if [ "$use_sdl" != no ]; then |
| 972 |
remember_use sdl |
| 973 |
|
| 974 |
if command -v sdl2-config >/dev/null; then |
| 975 |
sdl2_include_path="$(sdl2-config --cflags)" |
| 976 |
sdl2_include_path="${sdl2_include_path#*-I}" |
| 977 |
sdl2_include_path="${sdl2_include_path%% -*}" |
| 978 |
else |
| 979 |
sdl2_include_path='/usr/include/SDL2 /usr/local/include/SDL2 /opt/local/include/SDL2 /opt/homebrew/include/SDL2' |
| 980 |
fi |
| 981 |
|
| 982 |
check_include SDL.h "$sdl2_include_path" "#define SDL_MAIN_HANDLED" |
| 983 |
if [ "$have_SDL_h" = yes ]; then |
| 984 |
if [ "$include_SDL_h_path" != ' ' ]; then |
| 985 |
append_nodupe CFLAGS "-I$include_SDL_h_path" |
| 986 |
fi |
| 987 |
if command -v sdl2-config >/dev/null; then |
| 988 |
sdl2_lib_path="$(sdl2-config --libs)" |
| 989 |
sdl2_lib_path="${sdl2_lib_path#*-L}" |
| 990 |
sdl2_lib_path="${sdl2_lib_path%% -*}" |
| 991 |
else |
| 992 |
sdl2_lib_path="/usr/lib /usr/local/lib /opt/local/lib /opt/homebrew/lib" |
| 993 |
fi |
| 994 |
check_libs SDL2 "" "$sdl2_lib_path" <<EOF |
| 995 |
#define SDL_MAIN_HANDLED |
| 996 |
#include <SDL.h> |
| 997 |
int main(int argc, char **argv) { |
| 998 |
SDL_Init(0); |
| 999 |
return 0; |
| 1000 |
} |
| 1001 |
EOF |
| 1002 |
if [ "$?" -eq 0 ]; then |
| 1003 |
use_sdl=yes |
| 1004 |
fi |
| 1005 |
fi |
| 1006 |
|
| 1007 |
recheck_use sdl |
| 1008 |
fi |
| 1009 |
|
| 1010 |
# plugout_stdout produces garbage if stdout writes in text mode and converts LF to CRLF |
| 1011 |
if [ "$use_stdout" != no ]; then |
| 1012 |
remember_use stdout |
| 1013 |
printf "checking if stdout converts line endings: " |
| 1014 |
cc_check "" "" <<EOF |
| 1015 |
#include <stdio.h> |
| 1016 |
int main(int argc, char **argv) { |
| 1017 |
fputs("\n", stdout); |
| 1018 |
return 0; |
| 1019 |
} |
| 1020 |
EOF |
| 1021 |
bytes_written="$("$TEMPDIR/cc" | wc -c)" |
| 1022 |
if [ "$bytes_written" -eq 1 ]; then |
| 1023 |
echo "no" |
| 1024 |
else |
| 1025 |
echo "yes" |
| 1026 |
# LF/CRLF conversion should only happen on Windows and setmode() should be available to fix it |
| 1027 |
if cc_check "checking for setmode() in fcntl.h" have_setmode <<EOF; then |
| 1028 |
#include <fcntl.h> |
| 1029 |
#include <unistd.h> |
| 1030 |
int main(int argc, char **argv) { |
| 1031 |
return setmode(STDOUT_FILENO, O_BINARY); |
| 1032 |
} |
| 1033 |
EOF |
| 1034 |
have_setmode=yes |
| 1035 |
else |
| 1036 |
have_setmode=no |
| 1037 |
use_stdout=no |
| 1038 |
fi |
| 1039 |
fi |
| 1040 |
recheck_use stdout |
| 1041 |
fi |
| 1042 |
|
| 1043 |
if [ "$use_i18n" != no ]; then |
| 1044 |
remember_use i18n |
| 1045 |
check_include locale.h |
| 1046 |
check_include libintl.h |
| 1047 |
|
| 1048 |
## check for gettext |
| 1049 |
|
| 1050 |
printf "checking for gettext tools: " |
| 1051 |
have_xgettext=yes |
| 1052 |
for i in xgettext msgmerge msgfmt msgen; do |
| 1053 |
if ! command -v $i >/dev/null; then |
| 1054 |
test "$have_xgettext" = "yes" && echo "not ok" |
| 1055 |
have_xgettext=no |
| 1056 |
echo "$i is missing" |
| 1057 |
fi |
| 1058 |
done |
| 1059 |
test "$have_xgettext" = "yes" && echo "ok" |
| 1060 |
|
| 1061 |
use_i18n=no |
| 1062 |
if [ "$have_locale_h" = "yes" ] && [ "$have_libintl_h" = "yes" ]; then |
| 1063 |
if [ "$include_locale_h_path" != " " ]; then |
| 1064 |
append_nodupe CFLAGS "-I$include_locale_h_path" |
| 1065 |
EXTRA_I18NFLAGS="$EXTRA_I18NFLAGS -I$include_locale_h_path" |
| 1066 |
fi |
| 1067 |
if [ "$include_libintl_h_path" != " " ]; then |
| 1068 |
append_nodupe CFLAGS "-I$include_libintl_h_path" |
| 1069 |
EXTRA_I18NFLAGS="$EXTRA_I18NFLAGS -I$include_libintl_h_path" |
| 1070 |
fi |
| 1071 |
|
| 1072 |
check_libs intl "" "" "" "$EXTRA_I18NFLAGS" <<EOF |
| 1073 |
#include <libintl.h> |
| 1074 |
int main(int argc, char **argv) |
| 1075 |
{ |
| 1076 |
bindtextdomain("foo", "bar"); |
| 1077 |
textdomain("foo"); |
| 1078 |
gettext("msg"); |
| 1079 |
return 0; |
| 1080 |
} |
| 1081 |
EOF |
| 1082 |
if [ $? -eq 0 ]; then |
| 1083 |
use_i18n=yes |
| 1084 |
if [ "$libintl_flags" != "" ]; then |
| 1085 |
append_nodupe LDFLAGS "$libintl_flags" |
| 1086 |
fi |
| 1087 |
fi |
| 1088 |
fi |
| 1089 |
recheck_use i18n |
| 1090 |
fi |
| 1091 |
|
| 1092 |
printf "checking for doxygen: " |
| 1093 |
if command -v doxygen >/dev/null; then |
| 1094 |
echo "ok" |
| 1095 |
have_doxygen=yes |
| 1096 |
else |
| 1097 |
echo "not found" |
| 1098 |
have_doxygen=no |
| 1099 |
fi |
| 1100 |
|
| 1101 |
## can xgbsplay be built? |
| 1102 |
|
| 1103 |
if [ "$build_xgbsplay" != "no" ]; then |
| 1104 |
## check for XCB |
| 1105 |
|
| 1106 |
check_include xcb/xcb.h \ |
| 1107 |
&& check_include xcb/xcb_icccm.h "" "#include <xcb/xcb.h>" \ |
| 1108 |
&& check_include "cairo/cairo-xcb.h" |
| 1109 |
retval1=$? |
| 1110 |
retval2=1 |
| 1111 |
if [ $retval1 -eq 0 ]; then |
| 1112 |
check_libs xcb <<EOF |
| 1113 |
#include <xcb/xcb.h> |
| 1114 |
#include <stdio.h> |
| 1115 |
int main(int argc, char **argv) { |
| 1116 |
printf("%d\n", xcb_connect != NULL); |
| 1117 |
return 0; |
| 1118 |
} |
| 1119 |
EOF |
| 1120 |
retval2=$? |
| 1121 |
check_libs xcb-icccm <<EOF |
| 1122 |
#include <xcb/xcb.h> |
| 1123 |
#include <xcb/xcb_icccm.h> |
| 1124 |
#include <stdio.h> |
| 1125 |
int main(int argc, char **argv) { |
| 1126 |
printf("%d\n", xcb_icccm_set_wm_name != NULL); |
| 1127 |
return 0; |
| 1128 |
} |
| 1129 |
EOF |
| 1130 |
retval3=$? |
| 1131 |
check_libs cairo <<EOF |
| 1132 |
#include <xcb/xcb.h> |
| 1133 |
#include <cairo/cairo-xcb.h> |
| 1134 |
#include <stdio.h> |
| 1135 |
int main(int argc, char **argv) { |
| 1136 |
printf("%d\n", cairo_create != NULL); |
| 1137 |
return 0; |
| 1138 |
} |
| 1139 |
EOF |
| 1140 |
retval4=$? |
| 1141 |
|
| 1142 |
# combine returncodes for next if block |
| 1143 |
if [ $retval3 -ne 0 ] || [ $retval4 -ne 0 ]; then |
| 1144 |
retval2=1 |
| 1145 |
fi |
| 1146 |
fi |
| 1147 |
if [ $retval1 -eq 0 ] && [ $retval2 -eq 0 ]; then |
| 1148 |
if [ "$include_xcb_xcb_h_path" != " " ]; then |
| 1149 |
append_nodupe CFLAGS "-I$include_xcb_xcb_h_path" |
| 1150 |
fi |
| 1151 |
if [ "$include_xcb_xcb_icccm_h_path" != " " ]; then |
| 1152 |
append_nodupe CFLAGS "-I$include_xcb_xcb_icccm_h_path" |
| 1153 |
fi |
| 1154 |
if [ "$include_cairo_cairo_xcb_h_path" != " " ]; then |
| 1155 |
append_nodupe CFLAGS "-I$include_cairo_cairo_xcb_h_path" |
| 1156 |
fi |
| 1157 |
EXTRA_INSTALL="$EXTRA_INSTALL xgbsplay" |
| 1158 |
EXTRA_UNINSTALL="$EXTRA_UNINSTALL xgbsplay" |
| 1159 |
else |
| 1160 |
build_xgbsplay=no |
| 1161 |
fi |
| 1162 |
fi |
| 1163 |
|
| 1164 |
## enable a slightly more modern c dialect (C11 or C17) |
| 1165 |
|
| 1166 |
if cc_has_flag "-std=c17"; then |
| 1167 |
# C17 only has bugfixes and is otherwise identical to C11 |
| 1168 |
append_nodupe CFLAGS "-std=c17" |
| 1169 |
else |
| 1170 |
if cc_has_flag "-std=c11"; then |
| 1171 |
append_nodupe CFLAGS "-std=c11" |
| 1172 |
fi |
| 1173 |
fi |
| 1174 |
|
| 1175 |
## check compiler features |
| 1176 |
|
| 1177 |
if cc_has_flag "-Wdeclaration-after-statement"; then |
| 1178 |
append_nodupe CFLAGS "-Wdeclaration-after-statement" |
| 1179 |
fi |
| 1180 |
if cc_has_flag "-Wvla"; then |
| 1181 |
append_nodupe CFLAGS "-Wvla" |
| 1182 |
fi |
| 1183 |
if cc_has_flag "-Wimplicit-fallthrough"; then |
| 1184 |
append_nodupe CFLAGS "-Wimplicit-fallthrough" |
| 1185 |
fi |
| 1186 |
if cc_has_flag "-Wswitch-unreachable"; then |
| 1187 |
append_nodupe CFLAGS "-Wswitch-unreachable" |
| 1188 |
fi |
| 1189 |
|
| 1190 |
if [ "$use_hardening" != "no" ]; then |
| 1191 |
append_nodupe CFLAGS -D_FORTIFY_SOURCE=2 |
| 1192 |
if cc_has_flag "-Wl,-z,relro"; then |
| 1193 |
append_nodupe LDFLAGS "-Wl,-z,relro" |
| 1194 |
fi |
| 1195 |
|
| 1196 |
if cc_has_flag "-Wl,-z,now"; then |
| 1197 |
append_nodupe LDFLAGS "-Wl,-z,now" |
| 1198 |
fi |
| 1199 |
|
| 1200 |
if cc_has_flag "-Wl,-pie"; then |
| 1201 |
append_nodupe LDFLAGS "-Wl,-pie" |
| 1202 |
elif cc_has_flag "-pie"; then |
| 1203 |
append_nodupe LDFLAGS "-pie" |
| 1204 |
fi |
| 1205 |
|
| 1206 |
if cc_has_flag "-fstack-protector-strong" \ |
| 1207 |
&& cc_check "checking if -fstack-protector-strong actually works" "" "-fstack-protector-strong" "yes" "no" <<EOF; then |
| 1208 |
int main(int argc, char **argv) |
| 1209 |
{ |
| 1210 |
char buf[65536]; |
| 1211 |
return 0; |
| 1212 |
} |
| 1213 |
EOF |
| 1214 |
append_nodupe CFLAGS "-fstack-protector-strong" |
| 1215 |
append_nodupe LDFLAGS "-fstack-protector-strong" |
| 1216 |
elif cc_has_flag "-fstack-protector" \ |
| 1217 |
&& cc_check "checking if working -fstack-protector actually works" "" "-fstack-protector" "yes" "no" <<EOF; then |
| 1218 |
int main(int argc, char **argv) |
| 1219 |
{ |
| 1220 |
char buf[65536]; |
| 1221 |
return 0; |
| 1222 |
} |
| 1223 |
EOF |
| 1224 |
append_nodupe CFLAGS "-fstack-protector" |
| 1225 |
append_nodupe LDFLAGS "-fstack-protector" |
| 1226 |
append_nodupe CFLAGS "--param=ssp-buffer-size=4" |
| 1227 |
fi |
| 1228 |
if cc_has_flag "-fstack-clash-protection" \ |
| 1229 |
&& cc_check "checking if -fstack-clash-protection actually works" "" "-fstack-clash-protection" "yes" "no" <<EOF; then |
| 1230 |
int main(int argc, char **argv) |
| 1231 |
{ |
| 1232 |
char buf[65536]; |
| 1233 |
return 0; |
| 1234 |
} |
| 1235 |
EOF |
| 1236 |
append_nodupe CFLAGS "-fstack-clash-protection" |
| 1237 |
append_nodupe LDFLAGS "-fstack-clash-protection" |
| 1238 |
fi |
| 1239 |
fi |
| 1240 |
|
| 1241 |
## set variables we have no test for to default values if not set |
| 1242 |
|
| 1243 |
setdefault exec_prefix "$prefix" |
| 1244 |
setdefault bindir "$exec_prefix/bin" |
| 1245 |
setdefault libdir "$exec_prefix/lib" |
| 1246 |
setdefault mandir "$prefix/man" |
| 1247 |
setdefault docdir "$prefix/share/doc/$package" |
| 1248 |
setdefault localedir "$prefix/share/locale" |
| 1249 |
setdefault mimedir "$prefix/share/mime" |
| 1250 |
setdefault appdir "$prefix/share/applications" |
| 1251 |
setdefault includedir "$prefix/include/libgbs" |
| 1252 |
setdefault pkgconfigdir "$prefix/share/pkgconfig" |
| 1253 |
setdefault sysconfdir "/etc" |
| 1254 |
|
| 1255 |
setdefault use_sharedlibgbs no |
| 1256 |
setdefault use_verbosebuild no |
| 1257 |
setdefault use_debug no |
| 1258 |
|
| 1259 |
setdefault use_midi yes |
| 1260 |
setdefault use_altmidi yes |
| 1261 |
setdefault use_stdout yes |
| 1262 |
setdefault use_vgm yes |
| 1263 |
setdefault use_wav yes |
| 1264 |
setdefault use_iodumper yes |
| 1265 |
|
| 1266 |
printoptional modules build |
| 1267 |
printoptional features use |
| 1268 |
|
| 1269 |
append_nodupe CFLAGS -Wall -fsigned-char |
| 1270 |
|
| 1271 |
if [ "$use_debug" = "yes" ]; then |
| 1272 |
append_nodupe CFLAGS -g3 |
| 1273 |
else |
| 1274 |
append_nodupe CFLAGS -Os -pipe -fomit-frame-pointer |
| 1275 |
fi |
| 1276 |
|
| 1277 |
EXTRA_CFLAGS="$CFLAGS" |
| 1278 |
EXTRA_LDFLAGS="$LDFLAGS" |
| 1279 |
echo "EXTRA_CFLAGS=$EXTRA_CFLAGS" |
| 1280 |
echo "EXTRA_LDFLAGS=$EXTRA_LDFLAGS" |
| 1281 |
|
| 1282 |
## generate pkg-config configuration |
| 1283 |
# can't be done in Makefile because $DESTDIR would show up in the paths |
| 1284 |
|
| 1285 |
cat > libgbs.pc << __EOF__ |
| 1286 |
Name: libgbs |
| 1287 |
Description: The Gameboy sound player library |
| 1288 |
Version: ${VERSION} |
| 1289 |
Cflags: -I${includedir}/libgbs |
| 1290 |
Libs: -L${libdir} -lgbs -lm |
| 1291 |
__EOF__ |
| 1292 |
|
| 1293 |
## write configuration |
| 1294 |
|
| 1295 |
( |
| 1296 |
set +u # Allow uninitialised vars here |
| 1297 |
while read -r var; do |
| 1298 |
eval "echo \"$var := \$$var\"" |
| 1299 |
done << __EOF__ |
| 1300 |
EXTRA_ALL |
| 1301 |
EXTRA_CFLAGS |
| 1302 |
EXTRA_INSTALL |
| 1303 |
EXTRA_LDFLAGS |
| 1304 |
EXTRA_SRCS |
| 1305 |
EXTRA_UNINSTALL |
| 1306 |
VERSION |
| 1307 |
prefix |
| 1308 |
exec_prefix |
| 1309 |
bindir |
| 1310 |
libdir |
| 1311 |
mandir |
| 1312 |
docdir |
| 1313 |
localedir |
| 1314 |
mimedir |
| 1315 |
appdir |
| 1316 |
includedir |
| 1317 |
pkgconfigdir |
| 1318 |
sysconfdir |
| 1319 |
CC |
| 1320 |
BUILDCC |
| 1321 |
HOSTCC |
| 1322 |
build_contrib |
| 1323 |
build_test |
| 1324 |
build_xgbsplay |
| 1325 |
have_doxygen |
| 1326 |
have_xgettext |
| 1327 |
use_i18n |
| 1328 |
use_sharedlibgbs |
| 1329 |
use_verbosebuild |
| 1330 |
windows_build |
| 1331 |
windows_libprefix |
| 1332 |
libaudio_flags |
| 1333 |
libpipewire_0_3_flags |
| 1334 |
libSDL2_flags |
| 1335 |
__EOF__ |
| 1336 |
echo plugout_alsa := $use_alsa |
| 1337 |
echo plugout_devdsp := $use_devdsp |
| 1338 |
echo plugout_dsound := $use_dsound |
| 1339 |
echo plugout_iodumper := $use_iodumper |
| 1340 |
echo plugout_midi := $use_midi |
| 1341 |
echo plugout_altmidi := $use_altmidi |
| 1342 |
echo plugout_nas := $use_nas |
| 1343 |
echo plugout_pipewire := $use_pipewire |
| 1344 |
echo plugout_pulse := $use_pulse |
| 1345 |
echo plugout_sdl := $use_sdl |
| 1346 |
echo plugout_stdout := $use_stdout |
| 1347 |
echo plugout_vgm := $use_vgm |
| 1348 |
echo plugout_wav := $use_wav |
| 1349 |
echo configured := yes |
| 1350 |
) > config.mk |
| 1351 |
|
| 1352 |
( |
| 1353 |
set +u # Allow uninitialised vars here |
| 1354 |
echo "#ifndef _CONFIG_H_" |
| 1355 |
echo "#define GBS_VERSION \"$VERSION\"" |
| 1356 |
echo "#define LOCALE_PREFIX \"$localedir\"" |
| 1357 |
echo "#define SYSCONF_PREFIX \"$sysconfdir\"" |
| 1358 |
plugout_x ALSA |
| 1359 |
plugout_x DEVDSP |
| 1360 |
plugout_x DSOUND |
| 1361 |
plugout_x IODUMPER |
| 1362 |
plugout_x MIDI |
| 1363 |
plugout_x ALTMIDI |
| 1364 |
plugout_x NAS |
| 1365 |
plugout_x PIPEWIRE |
| 1366 |
plugout_x PULSE |
| 1367 |
plugout_x STDOUT |
| 1368 |
plugout_x SDL |
| 1369 |
plugout_x VGM |
| 1370 |
plugout_x WAV |
| 1371 |
use_x I18N |
| 1372 |
use_x ZLIB |
| 1373 |
have_x ESTRPIPE |
| 1374 |
have_x SETMODE |
| 1375 |
echo "#endif" |
| 1376 |
) > config.h |
| 1377 |
|
| 1378 |
( |
| 1379 |
echo "s|%%%VERSION%%%|$VERSION|g" |
| 1380 |
) > config.sed |
| 1381 |
|
| 1382 |
# show configuration if verbose |
| 1383 |
|
| 1384 |
if [ "$use_verbosebuild" = yes ]; then |
| 1385 |
for file in config.mk config.h config.sed libgbs.pc; do |
| 1386 |
echo |
| 1387 |
echo "content of generated $file:" |
| 1388 |
echo "--------" |
| 1389 |
cat $file |
| 1390 |
echo "--------" |
| 1391 |
done |
| 1392 |
fi |
| 1393 |
|
| 1394 |
## end |
| 1395 |
|
| 1396 |
rm -rf "$TEMPDIR" |
| 1397 |
test -s $ERRORLOG || rm $ERRORLOG |