diff options
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 2780 |
1 files changed, 2780 insertions, 0 deletions
diff --git a/configure b/configure new file mode 100755 index 00000000..50a52cf4 --- /dev/null +++ b/configure @@ -0,0 +1,2780 @@ +#!/bin/sh +# +# MPD configure script +# adapted from Libav +# +# Copyright (c) 2000-2002 Fabrice Bellard +# Copyright (c) 2005-2008 Diego Biurrun +# Copyright (c) 2005-2008 Mans Rullgard +# + +# Prevent locale nonsense from breaking basic text processing. +LC_ALL=C +export LC_ALL + +# make sure we are running under a compatible shell +# try to make this part work with most shells + +try_exec(){ + echo "Trying shell $1" + type "$1" > /dev/null 2>&1 && exec "$@" +} + +unset foo +(: ${foo%%bar}) 2> /dev/null +E1="$?" + +(: ${foo?}) 2> /dev/null +E2="$?" + +if test "$E1" != 0 || test "$E2" = 0; then + echo "Broken shell detected. Trying alternatives." + export FF_CONF_EXEC + if test "0$FF_CONF_EXEC" -lt 1; then + FF_CONF_EXEC=1 + try_exec bash "$0" "$@" + fi + if test "0$FF_CONF_EXEC" -lt 2; then + FF_CONF_EXEC=2 + try_exec ksh "$0" "$@" + fi + if test "0$FF_CONF_EXEC" -lt 3; then + FF_CONF_EXEC=3 + try_exec /usr/xpg4/bin/sh "$0" "$@" + fi + echo "No compatible shell script interpreter found." + echo "This configure script requires a POSIX-compatible shell" + echo "such as bash or ksh." + echo "THIS IS NOT A BUG IN MPD, DO NOT REPORT IT AS SUCH." + echo "Instead, install a working POSIX-compatible shell." + echo "Disabling this configure test will create a broken MPD" + if test "$BASH_VERSION" = '2.04.0(1)-release'; then + echo "This bash version ($BASH_VERSION) is broken on your platform." + echo "Upgrade to a later version if available." + fi + exit 1 +fi + +test -d /usr/xpg4/bin && PATH=/usr/xpg4/bin:$PATH + +show_help(){ + cat <<EOF +Usage: configure [options] +Options: [defaults in brackets after descriptions] + +Help options: + --help print this message + --list-archives show all available archive sources + --list-encoders show all available encoders + --list-inputs show all available input sources + --list-outputs show all available audio outputs + +Standard options: + --logfile=FILE log tests and output to FILE [config.log] + --disable-logging do not log configure debug information + --prefix=PREFIX install in PREFIX [$prefix] + --bindir=DIR install binaries in DIR [PREFIX/bin] + --confdir=DIR install the configuration files in DIR [/etc] + --datadir=DIR install data files in DIR [PREFIX/share/mpd] + --mandir=DIR install man page in DIR [PREFIX/share/man] + +Configuration options: + --enable-small optimize for size instead of speed + --enable-ud enable connection through unix domain sockets [no] + --enable-inotify enable automatic database update using inotify [no] + +Component options: + --disable-doc do not build documentation + +Individual component options: + --disable-everything disable all components listed below + --enable-archive=NAME enable archive NAME + --disable-archive=NAME disable archive NAME + --disable-archives disable all archives + --disable-encoder=NAME disable encoder NAME + --enable-encoder=NAME enable encoder NAME + --disable-encoders disable all encoders + --disable-output=NAME disable audio output NAME + --enable-output=NAME enable audio output NAME + --disable-outputs disable all audio outputs + --enable-input=NAME enable input NAME + --disable-input=NAME disable input NAME + --disable-inputs disable all inputs + +External library support: + --enable-bzlib enable bzlib [autodetect] + --enable-libcdio enable audio CD grabbing with libcdio + --enable-libmp3lame enable MP3 encoding via libmp3lame [no] + --enable-libpulse enable Pulseaudio input via libpulse [no] + --enable-libvorbis enable Vorbis encoding via libvorbis [no] + --enable-zlib enable zlib [autodetect] + +Advanced options (experts only): + --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix] + --enable-cross-compile assume a cross-compiler is used + --sysroot=PATH root of cross-build tree + --sysinclude=PATH location of cross-build system headers + --target-os=OS compiler targets OS [$target_os] + --target-exec=CMD command to run executables on target + --target-path=DIR path to view of build directory on target + --toolchain=NAME set tool defaults according to NAME + --nm=NM use nm tool + --cc=CC use C compiler CC [$cc_default] + --dep-cc=DEPCC use dependency generator DEPCC [$cc_default] + --ld=LD use linker LD + --host-cc=HOSTCC use host C compiler HOSTCC + --host-cflags=HCFLAGS use HCFLAGS when compiling for host + --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host + --host-ld=HOSTLD use host linker HOSTLD + --host-ldflags=HLDFLAGS use HLDFLAGS when linking for host + --host-libs=HLIBS use libs HLIBS when linking for host + --host-os=OS compiler host OS [$target_os] + --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] + --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS] + --extra-libs=ELIBS add ELIBS [$ELIBS] + --extra-version=STRING version string suffix [] + --optflags=OPTFLAGS override optimization-related compiler flags + --build-suffix=SUFFIX library name suffix [] + --malloc-prefix=PREFIX prefix malloc and related names with PREFIX + --arch=ARCH select architecture [$arch] + --cpu=CPU select the minimum required CPU (affects + instruction selection, may crash on older CPUs) + --enable-pic build position-independent code + --enable-thumb compile for Thumb instruction set + --enable-lto use link-time optimization + +Developer options (useful when working on MPD itself): + --disable-debug disable debugging symbols + --enable-debug=LEVEL set the debug level [$debuglevel] + --disable-optimizations disable compiler optimizations + --enable-extra-warnings enable more compiler warnings + +NOTE: Object files are built at the place where configure is launched. +EOF + exit 0 +} + +quotes='""' + +log(){ + echo "$@" >> $logfile +} + +log_file(){ + log BEGIN $1 + pr -n -t $1 >> $logfile + log END $1 +} + +echolog(){ + log "$@" + echo "$@" +} + +warn(){ + log "WARNING: $*" + WARNINGS="${WARNINGS}WARNING: $*\n" +} + +die(){ + echolog "$@" + cat <<EOF + +If you think configure made a mistake, make sure you are using the latest +version from Git. If the latest version fails, report the problem to the +developers +EOF + if disabled logging; then + cat <<EOF +Rerun configure with logging enabled (do not use --disable-logging), and +include the log this produces with your report. +EOF + else + cat <<EOF +Include the log file "$logfile" produced by configure as this will help +solving the problem. +EOF + fi + exit 1 +} + +# Avoid locale weirdness, besides we really just want to translate ASCII. +toupper(){ + echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ +} + +tolower(){ + echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz +} + +c_escape(){ + echo "$*" | sed 's/["\\]/\\\0/g' +} + +sh_quote(){ + v=$(echo "$1" | sed "s/'/'\\\\''/g") + test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'" + echo "$v" +} + +cleanws(){ + echo "$@" | sed 's/^ *//;s/ */ /g;s/ *$//' +} + +filter(){ + pat=$1 + shift + for v; do + eval "case $v in $pat) echo $v ;; esac" + done +} + +filter_out(){ + pat=$1 + shift + for v; do + eval "case $v in $pat) ;; *) echo $v ;; esac" + done +} + +map(){ + m=$1 + shift + for v; do eval $m; done +} + +add_suffix(){ + suffix=$1 + shift + for v; do echo ${v}${suffix}; done +} + +set_all(){ + value=$1 + shift + for var in $*; do + eval $var=$value + done +} + +set_weak(){ + value=$1 + shift + for var; do + eval : \${$var:=$value} + done +} + +sanitize_var_name(){ + echo $@ | sed 's/[^A-Za-z0-9_]/_/g' +} + +set_safe(){ + var=$1 + shift + eval $(sanitize_var_name "$var")='$*' +} + +get_safe(){ + eval echo \$$(sanitize_var_name "$1") +} + +pushvar(){ + for var in $*; do + eval level=\${${var}_level:=0} + eval ${var}_${level}="\$$var" + eval ${var}_level=$(($level+1)) + done +} + +popvar(){ + for var in $*; do + eval level=\${${var}_level:-0} + test $level = 0 && continue + eval level=$(($level-1)) + eval $var="\${${var}_${level}}" + eval ${var}_level=$level + eval unset ${var}_${level} + done +} + +enable(){ + set_all yes $* +} + +disable(){ + set_all no $* +} + +enable_weak(){ + set_weak yes $* +} + +disable_weak(){ + set_weak no $* +} + +enable_safe(){ + for var; do + enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g') + done +} + +disable_safe(){ + for var; do + disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g') + done +} + +do_enable_deep(){ + for var; do + enabled $var && continue + eval sel="\$${var}_select" + eval sgs="\$${var}_suggest" + pushvar var sgs + enable_deep $sel + popvar sgs + enable_deep_weak $sgs + popvar var + done +} + +enable_deep(){ + do_enable_deep $* + enable $* +} + +enable_deep_weak(){ + do_enable_deep $* + enable_weak $* +} + +enabled(){ + test "${1#!}" = "$1" && op== || op=!= + eval test "x\$${1#!}" $op "xyes" +} + +disabled(){ + test "${1#!}" = "$1" && op== || op=!= + eval test "x\$${1#!}" $op "xno" +} + +enabled_all(){ + for opt; do + enabled $opt || return 1 + done +} + +disabled_all(){ + for opt; do + disabled $opt || return 1 + done +} + +enabled_any(){ + for opt; do + enabled $opt && return 0 + done +} + +disabled_any(){ + for opt; do + disabled $opt && return 0 + done + return 1 +} + +set_default(){ + for opt; do + eval : \${$opt:=\$${opt}_default} + done +} + +is_in(){ + value=$1 + shift + for var in $*; do + [ $var = $value ] && return 0 + done + return 1 +} + +do_check_deps(){ + for cfg; do + cfg="${cfg#!}" + enabled ${cfg}_checking && die "Circular dependency for $cfg." + disabled ${cfg}_checking && continue + enable ${cfg}_checking + append allopts $cfg + + eval dep_all="\$${cfg}_deps" + eval dep_any="\$${cfg}_deps_any" + eval dep_sel="\$${cfg}_select" + eval dep_sgs="\$${cfg}_suggest" + eval dep_ifa="\$${cfg}_if" + eval dep_ifn="\$${cfg}_if_any" + + pushvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn + do_check_deps $dep_all $dep_any $dep_sel $dep_sgs $dep_ifa $dep_ifn + popvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn + + [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; } + [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; } + enabled_all $dep_all || disable $cfg + enabled_any $dep_any || disable $cfg + disabled_any $dep_sel && disable $cfg + + if enabled $cfg; then + enable_deep $dep_sel + enable_deep_weak $dep_sgs + fi + + disable ${cfg}_checking + done +} + +check_deps(){ + unset allopts + + do_check_deps "$@" + + for cfg in $allopts; do + enabled $cfg || continue + eval dep_extralibs="\$${cfg}_extralibs" + test -n "$dep_extralibs" && add_extralibs $dep_extralibs + done +} + +print_config(){ + pfx=$1 + files=$2 + shift 2 + map 'eval echo "$v \${$v:-no}"' "$@" | + awk "BEGIN { split(\"$files\", files) } + { + c = \"$pfx\" toupper(\$1); + v = \$2; + sub(/yes/, 1, v); + sub(/no/, 0, v); + for (f in files) { + file = files[f]; + if (file ~ /\\.h\$/) { + printf(\"#define %s %d\\n\", c, v) >>file; + } else if (file ~ /\\.asm\$/) { + printf(\"%%define %s %d\\n\", c, v) >>file; + } else if (file ~ /\\.mak\$/) { + n = -v ? \"\" : \"!\"; + printf(\"%s%s=yes\\n\", n, c) >>file; + } + } + }" +} + +print_enabled(){ + suf=$1 + shift + for v; do + enabled $v && printf "%s\n" ${v%$suf}; + done +} + +append(){ + var=$1 + shift + eval "$var=\"\$$var $*\"" +} + +prepend(){ + var=$1 + shift + eval "$var=\"$* \$$var\"" +} + +add_cppflags(){ + append CPPFLAGS "$@" +} + +add_cflags(){ + append CFLAGS $($cflags_filter "$@") +} + +add_ldflags(){ + append LDFLAGS $($ldflags_filter "$@") +} + +add_extralibs(){ + prepend extralibs $($ldflags_filter "$@") +} + +add_host_cppflags(){ + append host_cppflags "$@" +} + +add_host_cflags(){ + append host_cflags $($host_cflags_filter "$@") +} + +add_host_ldflags(){ + append host_ldflags $($host_ldflags_filter "$@") +} + +add_compat(){ + append compat_objs $1 + shift + map 'add_cppflags -D$v' "$@" +} + +check_cmd(){ + log "$@" + "$@" >> $logfile 2>&1 +} + +cc_o(){ + eval printf '%s\\n' $CC_O +} + +cc_e(){ + eval printf '%s\\n' $CC_E +} + +check_cc(){ + log check_cc "$@" + cat > $TMPC + log_file $TMPC + check_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC +} + +check_cpp(){ + log check_cpp "$@" + cat > $TMPC + log_file $TMPC + check_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC +} + +ld_o(){ + eval printf '%s\\n' $LD_O +} + +check_ld(){ + log check_ld "$@" + flags=$(filter_out '-l*' "$@") + libs=$(filter '-l*' "$@") + check_cc $($cflags_filter $flags) || return + flags=$($ldflags_filter $flags) + libs=$($ldflags_filter $libs) + check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs +} + +check_code(){ + log check_code "$@" + check=$1 + headers=$2 + code=$3 + shift 3 + { + for hdr in $headers; do + echo "#include <$hdr>" + done + echo "int main(void) { $code; return 0; }" + } | check_$check "$@" +} + +check_cppflags(){ + log check_cppflags "$@" + check_cc "$@" <<EOF && append CPPFLAGS "$@" +int x; +EOF +} + +check_cflags(){ + log check_cflags "$@" + set -- $($cflags_filter "$@") + check_cc "$@" <<EOF && append CFLAGS "$@" +int x; +EOF +} + +test_ldflags(){ + log test_ldflags "$@" + check_ld "$@" <<EOF +int main(void){ return 0; } +EOF +} + +check_ldflags(){ + log check_ldflags "$@" + test_ldflags "$@" && add_ldflags "$@" +} + +check_header(){ + log check_header "$@" + header=$1 + shift + disable_safe $header + check_cpp "$@" <<EOF && enable_safe $header +#include <$header> +int x; +EOF +} + +check_func(){ + log check_func "$@" + func=$1 + shift + disable $func + check_ld "$@" <<EOF && enable $func +extern int $func(); +int main(void){ $func(); } +EOF +} + +check_mathfunc(){ + log check_mathfunc "$@" + func=$1 + narg=$2 + shift 2 + test $narg = 2 && args="f, g" || args="f" + disable $func + check_ld "$@" <<EOF && enable $func +#include <math.h> +float foo(float f, float g) { return $func($args); } +int main(void){ return 0; } +EOF +} + +check_func_headers(){ + log check_func_headers "$@" + headers=$1 + funcs=$2 + shift 2 + { + for hdr in $headers; do + echo "#include <$hdr>" + done + for func in $funcs; do + echo "long check_$func(void) { return (long) $func; }" + done + echo "int main(void) { return 0; }" + } | check_ld "$@" && enable $funcs && enable_safe $headers +} + +check_cpp_condition(){ + log check_cpp_condition "$@" + header=$1 + condition=$2 + shift 2 + check_cpp "$@" <<EOF +#include <$header> +#if !($condition) +#error "unsatisfied condition: $condition" +#endif +EOF +} + +check_lib(){ + log check_lib "$@" + header="$1" + func="$2" + shift 2 + check_header $header && check_func $func "$@" && add_extralibs "$@" +} + +check_lib2(){ + log check_lib2 "$@" + headers="$1" + funcs="$2" + shift 2 + check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@" +} + +check_pkg_config(){ + log check_pkg_config "$@" + pkg="$1" + headers="$2" + funcs="$3" + shift 3 + $pkg_config --exists $pkg || return + pkg_cflags=$($pkg_config --cflags $pkg) + pkg_libs=$($pkg_config --libs $pkg) + check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" && + set_safe ${pkg}_cflags $pkg_cflags && + set_safe ${pkg}_libs $pkg_libs + add_cflags $(get_safe ${pkg}_cflags) + add_extralibs $(get_safe ${pkg}_libs) +} + +check_exec(){ + check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; } +} + +check_exec_crash(){ + code=$(cat) + + # exit() is not async signal safe. _Exit (C99) and _exit (POSIX) + # are safe but may not be available everywhere. Thus we use + # raise(SIGTERM) instead. The check is run in a subshell so we + # can redirect the "Terminated" message from the shell. SIGBUS + # is not defined by standard C so it is used conditionally. + + (check_exec "$@") >> $logfile 2>&1 <<EOF +#include <signal.h> +static void sighandler(int sig){ + raise(SIGTERM); +} +int foo(void){ + $code +} +int main(void){ + signal(SIGILL, sighandler); + signal(SIGFPE, sighandler); + signal(SIGSEGV, sighandler); +#ifdef SIGBUS + signal(SIGBUS, sighandler); +#endif + foo(); +} +EOF +} + +check_type(){ + log check_type "$@" + headers=$1 + type=$2 + shift 2 + disable_safe "$type" + check_code cc "$headers" "$type v" "$@" && enable_safe "$type" +} + +check_struct(){ + log check_struct "$@" + headers=$1 + struct=$2 + member=$3 + shift 3 + disable_safe "${struct}_${member}" + check_code cc "$headers" "const void *p = &(($struct *)0)->$member" "$@" && + enable_safe "${struct}_${member}" +} + +check_builtin(){ + log check_builtin "$@" + name=$1 + headers=$2 + builtin=$3 + shift 3 + disable "$name" + check_code ld "$headers" "$builtin" "$@" && enable "$name" +} + +require(){ + name="$1" + header="$2" + func="$3" + shift 3 + check_lib $header $func "$@" || die "ERROR: $name not found" +} + +require2(){ + name="$1" + headers="$2" + func="$3" + shift 3 + check_lib2 "$headers" $func "$@" || die "ERROR: $name not found" +} + +require_pkg_config(){ + pkg="$1" + check_pkg_config "$@" || die "ERROR: $pkg not found" + add_cflags $(get_safe ${pkg}_cflags) + add_extralibs $(get_safe ${pkg}_libs) +} + +hostcc_o(){ + eval printf '%s\\n' $HOSTCC_O +} + +check_host_cc(){ + log check_host_cc "$@" + cat > $TMPC + log_file $TMPC + check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC +} + +check_host_cppflags(){ + log check_host_cppflags "$@" + check_host_cc "$@" <<EOF && append host_cppflags "$@" +int x; +EOF +} + +check_host_cflags(){ + log check_host_cflags "$@" + set -- $($host_cflags_filter "$@") + check_host_cc "$@" <<EOF && append host_cflags "$@" +int x; +EOF +} + +apply(){ + file=$1 + shift + "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp" +} + +cp_if_changed(){ + cmp -s "$1" "$2" && echo "$2 is unchanged" && return + mkdir -p "$(dirname $2)" + $cp_f "$1" "$2" +} + +# CONFIG_LIST contains configurable options, while HAVE_LIST is for +# system-dependent things. + +COMPONENT_LIST=" + archives + encoders + inputs + outputs +" + +EXTERNAL_LIBRARY_LIST=" + bzlib + despotify + libao + libasound + libcdio_paranoia + libcurl + libffado + libflac + libiso9660 + libmp3lame + libpulse + libroar + libsamplerate + libsqlite3 + libsoup + libtwolame + libvorbis + libwrap + libyajl + zlib +" + +CONFIG_LIST=" + $COMPONENT_LIST + $EXTERNAL_LIBRARY_LIST + doc + inotify + small + ud +" + +ARCH_LIST=' + aarch64 + alpha + arm + avr32 + avr32_ap + avr32_uc + bfin + ia64 + m68k + mips + mips64 + parisc + ppc + ppc64 + s390 + sh4 + sparc + sparc64 + tilegx + tilepro + tomi + x86 + x86_32 + x86_64 +' + +ARCH_EXT_LIST_ARM=' + armv5te + armv6 + armv6t2 + neon + vfp + vfpv3 +' + +ARCH_EXT_LIST_X86=' + amd3dnow + amd3dnowext + avx + fma4 + mmx + mmxext + sse + sse2 + sse3 + sse4 + sse42 + ssse3 +' + +ARCH_EXT_LIST=" + $ARCH_EXT_LIST_ARM + $ARCH_EXT_LIST_X86 + altivec + ppc4xx + vis +" + +MATH_FUNCS=" + atanf + atan2f + cbrtf + cosf + exp2 + exp2f + expf + isinf + isnan + ldexpf + llrint + llrintf + log2 + log2f + log10f + lrint + lrintf + powf + rint + round + roundf + sinf + trunc + truncf +" + +HAVE_LIST=" + $ARCH_EXT_LIST + $(add_suffix _external $ARCH_EXT_LIST) + $(add_suffix _inline $ARCH_EXT_LIST) + $MATH_FUNCS + accept4 + alsa_asoundlib_h + arpa_inet_h + attribute_may_alias + attribute_packed + cdio_paranoia_h + cdio_paranoia_paranoia_h + closesocket + dos_paths + fork + getaddrinfo + getpeereid + getservbyport + gettimeofday + inet_aton + inotify_init + inotify_init1 + jack_port_get_latency_range + ldbrx + mkfifo + msvcrt + pipe2 + socklen_t + soundcard_h + strtok_r + struct_addrinfo + struct_group_source_req + struct_ip_mreq_source + struct_ipv6_mreq + struct_pollfd + struct_rusage_ru_maxrss + struct_sockaddr_in6 + struct_sockaddr_sa_len + struct_sockaddr_storage + struct_ucred + struct_v4l2_frmivalenum_discrete + syslog + unistd_h + windows_h + winsock2_h +" + +# options emitted with CONFIG_ prefix but not available on the command line +CONFIG_EXTRA=" +" + +CMDLINE_SELECT=" + $ARCH_EXT_LIST + $CONFIG_LIST + cross_compile + debug + extra_warnings + logging + lto + optimizations +" + +PATHS_LIST=' + bindir + confdir + datadir + mandir + prefix +' + +CMDLINE_SET=" + $PATHS_LIST + ar + arch + build_suffix + cc + cpu + cross_prefix + dep_cc + extra_version + host_cc + host_cflags + host_ld + host_ldflags + host_libs + host_os + ld + logfile + nm + optflags + pkg_config + sysinclude + sysroot + target_exec + target_os + target_path + toolchain +" + +CMDLINE_APPEND=" + extra_cflags + host_cppflags +" + +# code dependency declarations + +# architecture extensions + +log2_deps="!msvcrt" + +# archives +iso9660_archive_deps="libiso9660" +bzip2_archive_deps="bzlib" +zzip_archive_deps="zziplib" + +# inputs +curl_input_deps="libcurl" +soup_input_deps="libsoup" +lastfm_input_deps="libcurl" +despotify_input_deps="despotify" +soundcloud_input_deps="libyajl" + +# outputs +alsa_output_deps="alsa_asoundlib_h" +roar_output_deps="libroar" +ao_output_deps="libao" +ffado_output_deps="libffado" +fifo_output_deps="mkfifo" +httpd_output_deps="encoders" +jack_output_deps="libjack" +openal_output_deps="libopenal" +oss_output_deps_any="soundcard_h sys_soundcard_h" +osx_output_deps="AudioUnit CoreAudio CoreServices" +pulse_output_deps="libpulse" +recorder_output_deps="encoders" +shout_output_deps="libshout" +solaris_output_deps="solaris" +winmm_output_deps="winmm" + +# encoders +vorbis_encoder_deps="libvorbis" +lame_encoder_deps="libmp3lame" +twolame_encoder_deps="libtwolame" +flac_encoder_deps="libflac" + +# default parameters + +logfile="config.log" + +# installation paths +prefix_default="/usr/local" +bindir_default='${prefix}/bin' +datadir_default='${prefix}/share/mpd' +mandir_default='${prefix}/share/man' +confdir_default='/etc' + +# toolchain +cc_default="gcc" +host_cc_default="gcc" +cp_f="cp -f" +ln_s="ln -s -f" +nm_default="nm -g" +objformat="elf" +pkg_config_default=pkg-config +ranlib="ranlib" + +nogas=":" + +# machine +arch_default=$(uname -m) +cpu="generic" + +# OS +target_os_default=$(tolower $(uname -s)) +host_os=$target_os_default + +# configurable options +enable debug +enable doc +enable optimizations + +# build settings +FULLNAME='$(NAME)$(BUILDSUF)' + +cflags_filter=echo +ldflags_filter=echo + +CC_C='-c' +CC_E='-E -o $@' +CC_O='-o $@' +LD_O='-o $@' +LD_LIB='-l%' +LD_PATH='-L' +HOSTCC_C='-c' +HOSTCC_O='-o $@' +HOSTLD_O='-o $@' + +host_cflags='-O3 -g' +host_cppflags='-D_ISOC99_SOURCE -D_XOPEN_SOURCE=600' +host_libs='-lm' +host_cflags_filter=echo +host_ldflags_filter=echo + +target_path='$(CURDIR)' + +# since the object filename is not given with the -MM flag, the compiler +# is only able to print the basename, and we must add the path ourselves +DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)' +DEPFLAGS='-MM' + +# find source path +if test -f configure; then + source_path=. +else + source_path=$(cd $(dirname "$0"); pwd) + echo "$source_path" | grep -q '[[:blank:]]' && + die "Out of tree builds are impossible with whitespace in source path." + test -e "$source_path/config.h" && + die "Out of tree builds are impossible with config.h in source dir." +fi + +for v in "$@"; do + r=${v#*=} + l=${v%"$r"} + r=$(sh_quote "$r") + MPD_CONFIGURATION="${MPD_CONFIGURATION# } ${l}${r}" +done + +find_things(){ + thing=$1 + pattern=$2 + file=$source_path/$3 + sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file" +} + +#FIXME +ARCHIVE_LIST=" + bz2_archive + iso9660_archive + zzip_archive +" +ENCODER_LIST=" + flac_encoder + lame_encoder + twolame_encoder + vorbis_encoder + wave_encoder +" +OUTPUT_LIST=" + alsa_output + ao_output + ffado_output + fifo_output + httpd_output + jack_output + mvp_output + null_output + openal_output + oss_output + osx_output + pipe_output + pulse_output + recorder_output + roar_output + shout_output + solaris_output + winmm_output +" + +INPUT_LIST=" + cdio_paranoia_input + curl_input + despotify_input + ffmpeg_input + file_input + rewind_input + soup_input +" + +ALL_COMPONENTS=" + $ARCHIVE_LIST + $ENCODER_LIST + $OUTPUT_LIST + $INPUT_LIST +" + +for n in $COMPONENT_LIST; do + v=$(toupper ${n%s})_LIST + eval enable \$$v + eval ${n}_if_any="\$$v" +done + +enable $ARCH_EXT_LIST + +die_unknown(){ + echo "Unknown option \"$1\"." + echo "See $0 --help for available options." + exit 1 +} + +print_3_columns() { + cat | tr ' ' '\n' | sort | pr -r -3 -t +} + +show_list() { + suffix=_$1 + shift + echo $* | sed s/$suffix//g | print_3_columns + exit 0 +} + +for opt do + optval="${opt#*=}" + case "$opt" in + --extra-ldflags=*) + add_ldflags $optval + ;; + --extra-libs=*) + add_extralibs $optval + ;; + --disable-devices) + disable $INDEV_LIST $OUTDEV_LIST + ;; + --enable-debug=*) + debuglevel="$optval" + ;; + --disable-everything) + map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST + ;; + --disable-all) + map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST + disable $PROGRAM_LIST doc + ;; + --enable-*=*|--disable-*=*) + eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/') + is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt" + eval list=\$$(toupper $thing)_LIST + name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing} + $action $(filter "$name" $list) + ;; + --enable-?*|--disable-?*) + eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g') + if is_in $option $COMPONENT_LIST; then + test $action = disable && action=unset + eval $action \$$(toupper ${option%s})_LIST + elif is_in $option $CMDLINE_SELECT; then + $action $option + else + die_unknown $opt + fi + ;; + --list-*) + NAME="${opt#--list-}" + is_in $NAME $COMPONENT_LIST || die_unknown $opt + NAME=${NAME%s} + eval show_list $NAME \$$(toupper $NAME)_LIST + ;; + --help|-h) show_help + ;; + *) + optname="${opt%%=*}" + optname="${optname#--}" + optname=$(echo "$optname" | sed 's/-/_/g') + if is_in $optname $CMDLINE_SET; then + eval $optname='$optval' + elif is_in $optname $CMDLINE_APPEND; then + append $optname "$optval" + else + die_unknown $opt + fi + ;; + esac +done + +disabled logging && logfile=/dev/null + +echo "# $0 $MPD_CONFIGURATION" > $logfile +set >> $logfile + +test -n "$cross_prefix" && enable cross_compile + +if enabled cross_compile; then + test -n "$arch" && test -n "$target_os" || + die "Must specify target arch and OS when cross-compiling" +fi + +cc_default="${cross_prefix}${cc_default}" +nm_default="${cross_prefix}${nm_default}" +pkg_config_default="${cross_prefix}${pkg_config_default}" +ranlib="${cross_prefix}${ranlib}" + +sysinclude_default="${sysroot}/usr/include" + +case "$toolchain" in + clang-asan) + cc_default="clang" + add_cflags -fsanitize=address + add_ldflags -fsanitize=address + ;; + clang-tsan) + cc_default="clang" + add_cflags -fsanitize=thread -pie + add_ldflags -fsanitize=thread -pie + ;; + msvc) + cc_default="c99wrap cl" + ld_default="c99wrap link" + nm_default="dumpbin -symbols" + target_os_default="win32" + ;; + gcov) + add_cflags -fprofile-arcs -ftest-coverage + add_ldflags -fprofile-arcs -ftest-coverage + ;; + ?*) + die "Unknown toolchain $toolchain" + ;; +esac + +set_default arch cc pkg_config sysinclude target_os +enabled cross_compile || host_cc_default=$cc +set_default host_cc + +if ! $pkg_config --version >/dev/null 2>&1; then + warn "$pkg_config not found, library detection may fail." + pkg_config=false +fi + +exesuf() { + case $1 in + mingw32|win32|win64|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;; + esac +} + +EXESUF=$(exesuf $target_os) +HOSTEXESUF=$(exesuf $host_os) + +# set temporary file name +: ${TMPDIR:=$TEMPDIR} +: ${TMPDIR:=$TMP} +: ${TMPDIR:=/tmp} + +if ! check_cmd mktemp -u XXXXXX; then + # simple replacement for missing mktemp + # NOT SAFE FOR GENERAL USE + mktemp(){ + echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$" + } +fi + +tmpfile(){ + tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 && + (set -C; exec > $tmp) 2>/dev/null || + die "Unable to create temporary file in $TMPDIR." + append TMPFILES $tmp + eval $1=$tmp +} + +trap 'rm -f -- $TMPFILES' EXIT + +tmpfile TMPASM .asm +tmpfile TMPC .c +tmpfile TMPE $EXESUF +tmpfile TMPH .h +tmpfile TMPO .o +tmpfile TMPS .S +tmpfile TMPSH .sh +tmpfile TMPV .ver + +unset -f mktemp + +chmod +x $TMPE + +# make sure we can execute files in $TMPDIR +cat > $TMPSH 2>> $logfile <<EOF +#! /bin/sh +EOF +chmod +x $TMPSH >> $logfile 2>&1 +if ! $TMPSH >> $logfile 2>&1; then + cat <<EOF +Unable to create and execute files in $TMPDIR. Set the TMPDIR environment +variable to another directory and make sure that it is not mounted noexec. +EOF + die "Sanity test failed." +fi + +ccc_flags(){ + for flag; do + case $flag in + -std=c99) echo -c99 ;; + -mcpu=*) echo -arch ${flag#*=} ;; + -mieee) echo -ieee ;; + -O*|-fast) echo $flag ;; + -fno-math-errno) echo -assume nomath_errno ;; + -g) echo -g3 ;; + -Wall) echo -msg_enable level2 ;; + -Wno-pointer-sign) echo -msg_disable ptrmismatch1 ;; + -Wl,*) echo $flag ;; + -f*|-W*) ;; + *) echo $flag ;; + esac + done +} + +msvc_flags(){ + for flag; do + case $flag in + -fomit-frame-pointer) echo -Oy ;; + -g) echo -Z7 ;; + -Wall) echo -W4 -wd4244 -wd4127 -wd4018 -wd4389 \ + -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \ + -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \ + -wd4996 -wd4273 ;; + -std=c99) ;; + -fno-math-errno) ;; + -fno-common) ;; + -fno-signed-zeros) ;; + -fPIC) ;; + -lz) echo zlib.lib ;; + -lavifil32) echo vfw32.lib ;; + -lavicap32) echo vfw32.lib user32.lib ;; + -l*) echo ${flag#-l}.lib ;; + *) echo $flag ;; + esac + done +} + +pgi_flags(){ + for flag; do + case $flag in + -flto) echo -Mipa=fast,libopt,libinline,vestigial ;; + -fomit-frame-pointer) echo -Mnoframe ;; + -g) echo -gopt ;; + *) echo $flag ;; + esac + done +} + +suncc_flags(){ + for flag; do + case $flag in + -march=*|-mcpu=*) + case "${flag#*=}" in + native) echo -xtarget=native ;; + v9|niagara) echo -xarch=sparc ;; + ultrasparc) echo -xarch=sparcvis ;; + ultrasparc3|niagara2) echo -xarch=sparcvis2 ;; + i586|pentium) echo -xchip=pentium ;; + i686|pentiumpro|pentium2) echo -xtarget=pentium_pro ;; + pentium3*|c3-2) echo -xtarget=pentium3 ;; + pentium-m) echo -xarch=sse2 -xchip=pentium3 ;; + pentium4*) echo -xtarget=pentium4 ;; + prescott|nocona) echo -xarch=sse3 -xchip=pentium4 ;; + *-sse3) echo -xarch=sse3 ;; + core2) echo -xarch=ssse3 -xchip=core2 ;; + corei7) echo -xarch=sse4_2 -xchip=nehalem ;; + corei7-avx) echo -xarch=avx -xchip=sandybridge ;; + amdfam10|barcelona|bdver*) echo -xarch=sse4_1 ;; + athlon-4|athlon-[mx]p) echo -xarch=ssea ;; + k8|opteron|athlon64|athlon-fx) + echo -xarch=sse2a ;; + athlon*) echo -xarch=pentium_proa ;; + esac + ;; + -std=c99) echo -xc99 ;; + -fomit-frame-pointer) echo -xregs=frameptr ;; + -fPIC) echo -KPIC -xcode=pic32 ;; + -W*,*) echo $flag ;; + -f*-*|-W*|-mimpure-text) ;; + -shared) echo -G ;; + *) echo $flag ;; + esac + done +} + +tms470_flags(){ + for flag; do + case $flag in + -march=*|-mcpu=*) + case "${flag#*=}" in + armv7-a|cortex-a*) echo -mv=7a8 ;; + armv7-r|cortex-r*) echo -mv=7r4 ;; + armv7-m|cortex-m*) echo -mv=7m3 ;; + armv6*|arm11*) echo -mv=6 ;; + armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) + echo -mv=5e ;; + armv4*|arm7*|arm9[24]*) echo -mv=4 ;; + esac + ;; + -mfpu=neon) echo --float_support=vfpv3 --neon ;; + -mfpu=vfp) echo --float_support=vfpv2 ;; + -mfpu=vfpv3) echo --float_support=vfpv3 ;; + -mfpu=vfpv3-d16) echo --float_support=vfpv3d16 ;; + -msoft-float) echo --float_support=vfplib ;; + -O[0-3]|-mf=*) echo $flag ;; + -g) echo -g -mn ;; + -pds=*) echo $flag ;; + -D*|-I*) echo $flag ;; + --gcc|--abi=*) echo $flag ;; + -me) echo $flag ;; + esac + done +} + +probe_cc(){ + pfx=$1 + _cc=$2 + + unset _type _ident _cc_c _cc_e _cc_o _flags _cflags + unset _ld_o _ldflags _ld_lib _ld_path + unset _depflags _DEPCMD _DEPFLAGS + _flags_filter=echo + + if $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then + _type=llvm_gcc + gcc_extra_ver=$(expr "$($_cc --version | head -n1)" : '.*\((.*)\)') + _ident="llvm-gcc $($_cc -dumpversion) $gcc_extra_ver" + _depflags='-MMD -MF $(@:.o=.d) -MT $@' + _cflags_speed='-O3' + _cflags_size='-Os' + elif $_cc -v 2>&1 | grep -qi ^gcc; then + _type=gcc + gcc_version=$($_cc --version | head -n1) + gcc_basever=$($_cc -dumpversion) + gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)') + gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)") + _ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver") + if ! $_cc -dumpversion | grep -q '^2\.'; then + _depflags='-MMD -MF $(@:.o=.d) -MT $@' + fi + _cflags_speed='-O3' + _cflags_size='-Os' + elif $_cc --version 2>/dev/null | grep -q ^icc; then + _type=icc + _ident=$($_cc --version | head -n1) + _depflags='-MMD' + _cflags_speed='-O3' + _cflags_size='-Os' + _cflags_noopt='-O1' + elif $_cc -v 2>&1 | grep -q xlc; then + _type=xlc + _ident=$($_cc -qversion 2>/dev/null | head -n1) + _cflags_speed='-O5' + _cflags_size='-O5 -qcompact' + elif $_cc -V 2>/dev/null | grep -q Compaq; then + _type=ccc + _ident=$($_cc -V | head -n1 | cut -d' ' -f1-3) + _DEPFLAGS='-M' + _cflags_speed='-fast' + _cflags_size='-O1' + _flags_filter=ccc_flags + elif $_cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then + test -d "$sysroot" || die "No valid sysroot specified." + _type=armcc + _ident=$($_cc --vsn | head -n1) + armcc_conf="$PWD/armcc.conf" + $_cc --arm_linux_configure \ + --arm_linux_config_file="$armcc_conf" \ + --configure_sysroot="$sysroot" \ + --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 || + die "Error creating armcc configuration file." + $_cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc + _flags="--arm_linux_config_file=$armcc_conf --translate_gcc" + as_default="${cross_prefix}gcc" + _depflags='-MMD' + _cflags_speed='-O3' + _cflags_size='-Os' + elif $_cc -version 2>/dev/null | grep -Eq 'TMS470|TI ARM'; then + _type=tms470 + _ident=$($_cc -version | head -n1 | tr -s ' ') + _flags='--gcc --abi=eabi -me' + _cc_e='-ppl -fe=$@' + _cc_o='-fe=$@' + _depflags='-ppa -ppd=$(@:.o=.d)' + _cflags_speed='-O3 -mf=5' + _cflags_size='-O3 -mf=2' + _flags_filter=tms470_flags + elif $_cc -v 2>&1 | grep -q clang; then + _type=clang + _ident=$($_cc --version | head -n1) + _depflags='-MMD' + _cflags_speed='-O3' + _cflags_size='-Os' + elif $_cc -V 2>&1 | grep -q Sun; then + _type=suncc + _ident=$($_cc -V 2>&1 | head -n1 | cut -d' ' -f 2-) + _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)' + _DEPFLAGS='-xM1 -xc99' + _ldflags='-std=c99' + _cflags_speed='-O5' + _cflags_size='-O5 -xspace' + _flags_filter=suncc_flags + elif $_cc -v 2>&1 | grep -q 'PathScale\|Path64'; then + _type=pathscale + _ident=$($_cc -v 2>&1 | head -n1 | tr -d :) + _depflags='-MMD -MF $(@:.o=.d) -MT $@' + _cflags_speed='-O2' + _cflags_size='-Os' + _flags_filter='filter_out -Wdisabled-optimization' + elif $_cc -v 2>&1 | grep -q Open64; then + _type=open64 + _ident=$($_cc -v 2>&1 | head -n1 | tr -d :) + _depflags='-MMD -MF $(@:.o=.d) -MT $@' + _cflags_speed='-O2' + _cflags_size='-Os' + _flags_filter='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros' + elif $_cc -V 2>&1 | grep -q Portland; then + _type=pgi + _ident="PGI $($_cc -V 2>&1 | awk '/^pgcc/ { print $2; exit }')" + opt_common='-alias=ansi -Mdse -Mlre -Mpre' + _cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common" + _cflags_size="-O2 -Munroll=c:1 $opt_common" + _cflags_noopt="-O1" + _flags_filter=pgi_flags + elif $_cc 2>&1 | grep -q Microsoft; then + _type=msvc + _ident=$($cc 2>&1 | head -n1) + _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)' + _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs' + _cflags_speed="-O2" + _cflags_size="-O1" + # Nonstandard output options, to avoid msys path conversion issues, relies on wrapper to remap it + if $_cc 2>&1 | grep -q Linker; then + _ld_o='-out $@' + else + _ld_o='-Fe$@' + fi + _cc_o='-Fo $@' + _cc_e='-P -Fi $@' + _flags_filter=msvc_flags + _ld_lib='lib%.a' + _ld_path='-libpath:' + _flags='-nologo' + _cflags='-D_USE_MATH_DEFINES -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64' + if [ $pfx = hostcc ]; then + append _cflags -Dsnprintf=_snprintf + fi + fi + + eval ${pfx}_type=\$_type + eval ${pfx}_ident=\$_ident +} + +set_ccvars(){ + eval ${1}_C=\${_cc_c-\${${1}_C}} + eval ${1}_E=\${_cc_e-\${${1}_E}} + eval ${1}_O=\${_cc_o-\${${1}_O}} + + if [ -n "$_depflags" ]; then + eval ${1}_DEPFLAGS=\$_depflags + else + eval ${1}DEP=\${_DEPCMD:-\$DEPCMD} + eval ${1}DEP_FLAGS=\${_DEPFLAGS:-\$DEPFLAGS} + eval DEP${1}FLAGS=\$_flags + fi +} + +probe_cc cc "$cc" +cflags_filter=$_flags_filter +cflags_speed=$_cflags_speed +cflags_size=$_cflags_size +cflags_noopt=$_cflags_noopt +add_cflags $_flags $_cflags +add_cflags -I$source_path/src +cc_ldflags=$_ldflags +set_ccvars CC + +probe_cc hostcc "$host_cc" +host_cflags_filter=$_flags_filter +add_host_cflags $_flags $_cflags +set_ccvars HOSTCC + +test -n "$cc_type" && enable $cc_type || + warn "Unknown C compiler $cc, unable to select optimal CFLAGS" + +: ${as_default:=$cc} +: ${dep_cc_default:=$cc} +: ${ld_default:=$cc} +: ${host_ld_default:=$host_cc} +set_default ar as dep_cc ld host_ld + +probe_cc as "$as" +set_ccvars AS + +probe_cc ld "$ld" +ldflags_filter=$_flags_filter +add_ldflags $_flags $_ldflags +test "$cc_type" != "$ld_type" && add_ldflags $cc_ldflags +LD_O=${_ld_o-$LD_O} +LD_LIB=${_ld_lib-$LD_LIB} +LD_PATH=${_ld_path-$LD_PATH} + +probe_cc hostld "$host_ld" +host_ldflags_filter=$_flags_filter +add_host_ldflags $_flags $_ldflags +HOSTLD_O=${_ld_o-$HOSTLD_O} + +if [ -z "$CC_DEPFLAGS" ] && [ "$dep_cc" != "$cc" ]; then + probe_cc depcc "$dep_cc" + CCDEP=${_DEPCMD:-$DEPCMD} + CCDEP_FLAGS=${_DEPFLAGS:=$DEPFLAGS} + DEPCCFLAGS=$_flags +fi + +if $ar 2>&1 | grep -q Microsoft; then + arflags="-nologo" + ar_o='-out:$@' +elif $ar 2>&1 | grep -q 'Texas Instruments'; then + arflags="rq" + ar_o='$@' +else + arflags="rc" + ar_o='$@' +fi + +add_cflags $extra_cflags + +if test -n "$sysroot"; then + case "$cc_type" in + gcc|llvm_gcc|clang) + add_cppflags --sysroot="$sysroot" + add_ldflags --sysroot="$sysroot" + ;; + tms470) + add_cppflags -I"$sysinclude" + add_ldflags --sysroot="$sysroot" + ;; + esac +fi + +if test "$cpu" = host; then + enabled cross_compile && die "--cpu=host makes no sense when cross-compiling." + + case "$cc_type" in + gcc|llvm_gcc) + check_native(){ + $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return + sed -n "/cc1.*$1=/{ + s/.*$1=\\([^ ]*\\).*/\\1/ + p + q + }" $TMPE + } + cpu=$(check_native -march || check_native -mcpu) + ;; + esac + + test "${cpu:-host}" = host && die "--cpu=host not supported with compiler $cc" +fi + +# Deal with common $arch aliases +case "$arch" in + aarch64|arm64) + arch="aarch64" + ;; + arm*) + arch="arm" + ;; + mips*|IP*) + arch="mips" + ;; + parisc*|hppa*) + arch="parisc" + ;; + "Power Macintosh"|ppc*|powerpc*) + arch="ppc" + ;; + s390|s390x) + arch="s390" + ;; + sh4|sh) + arch="sh4" + ;; + sun4u|sparc*) + arch="sparc" + ;; + tilegx|tile-gx) + arch="tilegx" + ;; + i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64) + arch="x86" + ;; +esac + +is_in $arch $ARCH_LIST || warn "unknown architecture $arch" +enable $arch + +# Add processor-specific flags +if enabled aarch64; then + + case $cpu in + armv*) + cpuflags="-march=$cpu" + ;; + *) + cpuflags="-mcpu=$cpu" + ;; + esac + +elif enabled alpha; then + + cpuflags="-mcpu=$cpu" + +elif enabled arm; then + + check_arm_arch() { + check_cpp_condition stddef.h \ + "defined __ARM_ARCH_${1}__ || defined __TARGET_ARCH_${2:-$1}" \ + $cpuflags + } + + probe_arm_arch() { + if check_arm_arch 4; then echo armv4; + elif check_arm_arch 4T; then echo armv4t; + elif check_arm_arch 5; then echo armv5; + elif check_arm_arch 5E; then echo armv5e; + elif check_arm_arch 5T; then echo armv5t; + elif check_arm_arch 5TE; then echo armv5te; + elif check_arm_arch 5TEJ; then echo armv5te; + elif check_arm_arch 6; then echo armv6; + elif check_arm_arch 6J; then echo armv6j; + elif check_arm_arch 6K; then echo armv6k; + elif check_arm_arch 6Z; then echo armv6z; + elif check_arm_arch 6ZK; then echo armv6zk; + elif check_arm_arch 6T2; then echo armv6t2; + elif check_arm_arch 7; then echo armv7; + elif check_arm_arch 7A 7_A; then echo armv7-a; + elif check_arm_arch 7R 7_R; then echo armv7-r; + elif check_arm_arch 7M 7_M; then echo armv7-m; + elif check_arm_arch 7EM 7E_M; then echo armv7-m; + elif check_arm_arch 8A 8_A; then echo armv8-a; + fi + } + + [ "$cpu" = generic ] && cpu=$(probe_arm_arch) + + case $cpu in + armv*) + cpuflags="-march=$cpu" + subarch=$(echo $cpu | sed 's/[^a-z0-9]//g') + ;; + *) + cpuflags="-mcpu=$cpu" + case $cpu in + cortex-a*) subarch=armv7a ;; + cortex-r*) subarch=armv7r ;; + cortex-m*) enable thumb; subarch=armv7m ;; + arm11*) subarch=armv6 ;; + arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) subarch=armv5te ;; + armv4*|arm7*|arm9[24]*) subarch=armv4 ;; + *) subarch=$(probe_arm_arch) ;; + esac + ;; + esac + + case "$subarch" in + armv5t*) enable fast_clz ;; + armv[6-8]*) enable fast_clz fast_unaligned ;; + esac + +elif enabled avr32; then + + case $cpu in + ap7[02]0[0-2]) + subarch="avr32_ap" + cpuflags="-mpart=$cpu" + ;; + ap) + subarch="avr32_ap" + cpuflags="-march=$cpu" + ;; + uc3[ab]*) + subarch="avr32_uc" + cpuflags="-mcpu=$cpu" + ;; + uc) + subarch="avr32_uc" + cpuflags="-march=$cpu" + ;; + esac + +elif enabled bfin; then + + cpuflags="-mcpu=$cpu" + +elif enabled mips; then + + cpuflags="-march=$cpu" + +elif enabled ppc; then + + case $(tolower $cpu) in + 601|ppc601|powerpc601) + cpuflags="-mcpu=601" + disable altivec + ;; + 603*|ppc603*|powerpc603*) + cpuflags="-mcpu=603" + disable altivec + ;; + 604*|ppc604*|powerpc604*) + cpuflags="-mcpu=604" + disable altivec + ;; + g3|75*|ppc75*|powerpc75*) + cpuflags="-mcpu=750" + disable altivec + ;; + g4|745*|ppc745*|powerpc745*) + cpuflags="-mcpu=7450" + ;; + 74*|ppc74*|powerpc74*) + cpuflags="-mcpu=7400" + ;; + g5|970|ppc970|powerpc970) + cpuflags="-mcpu=970" + ;; + power[3-7]*) + cpuflags="-mcpu=$cpu" + ;; + cell) + cpuflags="-mcpu=cell" + enable ldbrx + ;; + e500mc) + cpuflags="-mcpu=e500mc" + disable altivec + ;; + e500v2) + cpuflags="-mcpu=8548 -mhard-float -mfloat-gprs=double" + disable altivec + ;; + e500) + cpuflags="-mcpu=8540 -mhard-float" + disable altivec + ;; + esac + +elif enabled sparc; then + + case $cpu in + cypress|f93[04]|tsc701|sparcl*|supersparc|hypersparc|niagara|v[789]) + cpuflags="-mcpu=$cpu" + disable vis + ;; + ultrasparc*|niagara[234]) + cpuflags="-mcpu=$cpu" + ;; + esac + +elif enabled x86; then + + case $cpu in + i[345]86|pentium) + cpuflags="-march=$cpu" + disable mmx + ;; + # targets that do NOT support conditional mov (cmov) + pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3) + cpuflags="-march=$cpu" + disable cmov + ;; + # targets that do support conditional mov (cmov) + i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64*|k8*|opteron*|athlon-fx|core2|corei7*|amdfam10|barcelona|atom|bdver*) + cpuflags="-march=$cpu" + enable cmov + enable fast_cmov + ;; + # targets that do support conditional mov but on which it's slow + pentium4|pentium4m|prescott|nocona) + cpuflags="-march=$cpu" + enable cmov + disable fast_cmov + ;; + esac + +fi + +if [ "$cpu" != generic ]; then + add_cflags $cpuflags +fi + +# compiler sanity check +check_exec <<EOF +int main(void){ return 0; } +EOF +if test "$?" != 0; then + echo "$cc is unable to create an executable file." + if test -z "$cross_prefix" && ! enabled cross_compile ; then + echo "If $cc is a cross-compiler, use the --enable-cross-compile option." + echo "Only do this if you know what cross compiling means." + fi + die "C compiler test failed." +fi + +#FIXME add_cppflags -D_ISOC99_SOURCE +check_cflags -std=gnu99 +check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64 +#include <stdlib.h> +EOF +check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE +#include <stdlib.h> +EOF + +check_host_cflags -std=gnu99 +check_host_cflags -Wall + +check_64bit(){ + arch32=$1 + arch64=$2 + expr=$3 + check_code cc "" "int test[2*($expr) - 1]" && + subarch=$arch64 || subarch=$arch32 +} + +case "$arch" in + aarch64|alpha|ia64) + spic=$shared + ;; + mips) + check_64bit mips mips64 '_MIPS_SIM > 1' + spic=$shared + ;; + parisc) + check_64bit parisc parisc64 'sizeof(void *) > 4' + spic=$shared + ;; + ppc) + check_64bit ppc ppc64 'sizeof(void *) > 4' + spic=$shared + ;; + sparc) + check_64bit sparc sparc64 'sizeof(void *) > 4' + spic=$shared + ;; + x86) + check_64bit x86_32 x86_64 'sizeof(void *) > 4' + if test "$subarch" = "x86_64"; then + spic=$shared + fi + ;; +esac + +enable $subarch +enabled spic && enable pic + +# OS specific +case $target_os in + haiku) + prefix_default="/boot/common" + network_extralibs="-lnetwork" + host_libs= + ;; + sunos) + network_extralibs="-lsocket -lnsl" + add_cppflags -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 + # When using suncc to build, the Solaris linker will mark + # an executable with each instruction set encountered by + # the Solaris assembler. As our libraries contain their own + # guards for processor-specific code, instead suppress + # generation of the HWCAPS ELF section on Solaris x86 only. + enabled_all suncc x86 && echo "hwcap_1 = OVERRIDE;" > mapfile && add_ldflags -Wl,-M,mapfile + nm_default='nm -P -g' + ;; + netbsd) + oss_output_extralibs="-lossaudio" + ;; + openbsd|bitrig) + SLIB_INSTALL_NAME='$(SLIBNAME).$(LIBMAJOR).$(LIBMINOR)' + SLIB_INSTALL_LINKS= + oss_output_extralibs="-lossaudio" + ;; + dragonfly) + ;; + freebsd) + ;; + bsd/os) + add_extralibs -lpoll -lgnugetopt + ;; + darwin) + gas="gas-preprocessor.pl $cc" + add_ldflags -Wl,-dynamic,-search_paths_first + SLIBSUF=".dylib" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)' + objformat="macho" + enabled x86_64 && objformat="macho64" + ;; + mingw32) + LIBTARGET=i386 + if enabled x86_64; then + LIBTARGET="i386:x86-64" + elif enabled arm; then + LIBTARGET=arm-wince + fi + shlibdir_default="$bindir_default" + SLIBPREF="" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' + SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)' + SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' + SLIB_INSTALL_LINKS= + SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)' + SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)' + objformat="win32" + dlltool="${cross_prefix}dlltool" + ranlib=: + enable dos_paths + ;; + win32|win64) + if enabled shared; then + # Link to the import library instead of the normal static library + # for shared libs. + LD_LIB='%.lib' + # Cannot build shared and static libraries at the same time with + # MSVC. + disable static + fi + shlibdir_default="$bindir_default" + SLIBPREF="" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' + SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)' + SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' + SLIB_INSTALL_LINKS= + SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)' + SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)' + objformat="win32" + ranlib=: + enable dos_paths + ;; + cygwin*) + target_os=cygwin + shlibdir_default="$bindir_default" + SLIBPREF="cyg" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' + SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' + SLIB_INSTALL_LINKS= + SLIB_INSTALL_EXTRA_LIB='lib$(FULLNAME).dll.a' + objformat="win32" + enable dos_paths + ;; + *-dos|freedos|opendos) + network_extralibs="-lsocket" + objformat="coff" + enable dos_paths + add_cppflags -U__STRICT_ANSI__ + ;; + linux) + enable dv1394 + ;; + irix*) + target_os=irix + ranlib="echo ignoring ranlib" + ;; + os/2*) + ln_s="cp -f" + objformat="aout" + add_cppflags -D_GNU_SOURCE + add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap + LIBSUF="_s.a" + SLIBPREF="" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)' + SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(NAME).def; \ + echo PROTMODE >> $(SUBDIR)$(NAME).def; \ + echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(NAME).def; \ + echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(NAME).def; \ + echo EXPORTS >> $(SUBDIR)$(NAME).def; \ + emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def' + SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \ + emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;' + SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib' + enable dos_paths + ;; + gnu/kfreebsd) + add_cppflags -D_BSD_SOURCE + ;; + gnu) + ;; + qnx) + add_cppflags -D_QNX_SOURCE + network_extralibs="-lsocket" + ;; + symbian) + SLIBSUF=".dll" + enable dos_paths + add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default + add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS + add_ldflags -Wl,--target1-abs,--no-undefined \ + -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \ + -Wl,--entry=_E32Startup -Wl,-u,_E32Startup + add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \ + -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \ + -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib + ;; + osf1) + add_cppflags -D_OSF_SOURCE -D_POSIX_PII -D_REENTRANT + ;; + minix) + ;; + plan9) + add_cppflags -D_C99_SNPRINTF_EXTENSION \ + -D_REENTRANT_SOURCE \ + -D_RESEARCH_SOURCE \ + -DFD_SETSIZE=96 \ + -DHAVE_SOCK_OPTS + add_compat strtod.o strtod=avpriv_strtod + network_extralibs='-lbsd' + exeobjs=compat/plan9/main.o + disable avserver + cp_f='cp' + ;; + none) + ;; + *) + die "Unknown OS '$target_os'." + ;; +esac + +# determine libc flavour + +# uclibc defines __GLIBC__, so it needs to be checked before glibc. +if check_cpp_condition features.h "defined __UCLIBC__"; then + libc_type=uclibc + add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 +elif check_cpp_condition features.h "defined __GLIBC__"; then + libc_type=glibc + add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 +# MinGW headers can be installed on Cygwin, so check for newlib first. +elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then + libc_type=newlib + add_cppflags -U__STRICT_ANSI__ +elif check_header _mingw.h; then + libc_type=mingw + check_cpp_condition _mingw.h \ + "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) || \ + (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" || + die "ERROR: MinGW runtime version must be >= 3.15." + add_cppflags -U__STRICT_ANSI__ +elif check_func_headers stdlib.h _get_doserrno; then + libc_type=msvcrt + add_compat strtod.o strtod=avpriv_strtod + add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf \ + _snprintf=avpriv_snprintf \ + vsnprintf=avpriv_vsnprintf +elif check_cpp_condition stddef.h "defined __KLIBC__"; then + libc_type=klibc +fi + +test -n "$libc_type" && enable $libc_type + +# hacks for compiler/libc/os combinations + +if enabled_all tms470 glibc; then + CPPFLAGS="-I${source_path}/compat/tms470 ${CPPFLAGS}" + add_cppflags -D__USER_LABEL_PREFIX__= + add_cppflags -D__builtin_memset=memset + add_cppflags -D__gnuc_va_list=va_list -D_VA_LIST_DEFINED + add_cflags -pds=48 # incompatible redefinition of macro +fi + +if enabled_all ccc glibc; then + add_ldflags -Wl,-z,now # calls to libots crash without this +fi + +esc(){ + echo "$*" | sed 's/%/%25/g;s/:/%3a/g' +} + +check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic + +set_default $PATHS_LIST +set_default nm + +disabled optimizations || check_cflags -fomit-frame-pointer + +enable_pic() { + enable pic + add_cppflags -DPIC + add_cflags -fPIC +} + +enabled pic && enable_pic + +check_cc <<EOF || die "Symbol mangling check failed." +int ff_extern; +EOF +sym=$($nm $TMPO | awk '/ff_extern/{ print substr($0, match($0, /[^ \t]*ff_extern/)) }') +extern_prefix=${sym%%ff_extern*} + +_restrict= +for restrict_keyword in restrict __restrict__ __restrict; do + check_cc <<EOF && _restrict=$restrict_keyword && break +void foo(char * $restrict_keyword p); +EOF +done + +check_cc <<EOF && enable attribute_packed +struct { int x; } __attribute__((packed)) x; +EOF + +check_cc <<EOF && enable attribute_may_alias +union { int x; } __attribute__((may_alias)) x; +EOF + +if enabled alpha; then + + check_cflags -mieee + +elif enabled arm; then + + check_cpp_condition stddef.h "defined __thumb__" && enable_weak thumb + enabled thumb && check_cflags -mthumb || check_cflags -marm + nogas=die + + if check_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then + enable vfp_args + elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then + case "${cross_prefix:-$cc}" in + *hardfloat*) enable vfp_args; fpabi=vfp ;; + *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;; +__asm__ (".eabi_attribute 28, 1"); +int main(void) { return 0; } +EOF + esac + warn "Compiler does not indicate floating-point ABI, guessing $fpabi." + fi + + [ $target_os = linux ] || + map 'enabled_any ${v}_external ${v}_inline || disable $v' \ + $ARCH_EXT_LIST_ARM + + enabled_all armv6t2 shared !pic && enable_pic + +elif enabled parisc; then + if enabled gcc; then + case $($cc -dumpversion) in + 4.[3-8].*) check_cflags -fno-optimize-sibling-calls ;; + esac + fi +fi + +check_ldflags -Wl,--as-needed + +if check_func dlopen; then + ldl= +elif check_func dlopen -ldl; then + ldl=-ldl +fi + +check_lib libavcodec/avcodec.h avcodec_alloc_context3 -lavcodec && + check_cpp_condition libavcodec/avcodec.h "LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 0, 0)" || + die "ERROR: libavcodec not found" +check_lib libavformat/avformat.h avformat_open_input -lavformat && + check_cpp_condition libavformat/avformat.h "LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(55, 0, 0)" || + die "ERROR: libavformat not found" +check_lib libavutil/avutil.h avutil_configuration -lavutil && + check_cpp_condition libavutil/avutil.h "LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(52, 8, 0)" || + die "ERROR: libavutil not found" +check_lib libavresample/avresample.h avresample_open -lavresample && + check_cpp_condition libavresample/avresample.h "LIBAVRESAMPLE_VERSION_INT >= AV_VERSION_INT(1, 0, 0)" || + die "ERROR: libavresample not found" + +check_pkg_config glib-2.0 glib.h g_main_loop_new || die "ERROR: glib not found" +check_pkg_config gthread-2.0 glib.h g_thread_init || die "ERROR: gthread not found" + +check_type "sys/types.h sys/socket.h" socklen_t +check_type netdb.h "struct addrinfo" +check_type netinet/in.h "struct group_source_req" -D_BSD_SOURCE +check_type netinet/in.h "struct ip_mreq_source" -D_BSD_SOURCE +check_type netinet/in.h "struct ipv6_mreq" -D_DARWIN_C_SOURCE +check_type netinet/in.h "struct sockaddr_in6" +check_type poll.h "struct pollfd" +check_type "sys/types.h sys/socket.h" "struct sockaddr_storage" +check_struct "sys/types.h sys/socket.h" "struct sockaddr" sa_len +check_type "sys/socket.h" "struct ucred" -D_GNU_SOURCE +check_type netinet/sctp.h "struct sctp_event_subscribe" +check_func getpeereid $network_extralibs +check_func getaddrinfo $network_extralibs +check_func getservbyport $network_extralibs +# Prefer arpa/inet.h over winsock2 +if check_header arpa/inet.h ; then + check_func closesocket +elif check_header winsock2.h ; then + check_func_headers winsock2.h closesocket -lws2 && + network_extralibs="-lws2" || + { check_func_headers winsock2.h closesocket -lws2_32 && + network_extralibs="-lws2_32"; } + check_func_headers ws2tcpip.h getaddrinfo $network_extralibs + check_type ws2tcpip.h socklen_t + check_type ws2tcpip.h "struct addrinfo" + check_type ws2tcpip.h "struct group_source_req" + check_type ws2tcpip.h "struct ip_mreq_source" + check_type ws2tcpip.h "struct ipv6_mreq" + check_type winsock2.h "struct pollfd" + check_type ws2tcpip.h "struct sockaddr_in6" + check_type ws2tcpip.h "struct sockaddr_storage" + check_struct winsock2.h "struct sockaddr" sa_len +else + die "ERROR: no usable networking implementation could be found" +fi + +check_func accept4 +check_func fork +check_func gettimeofday +check_func inet_aton $network_extralibs +check_func inotify_init +check_func inotify_init1 +check_func mkfifo +check_func pipe2 +check_func strtok_r + +for lib in -lbsd -linet -lsocket; do + check_func syslog $lib && break +done + +disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib +disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib + + +check_lib math.h sin -lm && LIBM="-lm" + +atan2f_args=2 +ldexpf_args=2 +powf_args=2 + +for func in $MATH_FUNCS; do + eval check_mathfunc $func \${${func}_args:-1} +done + +texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html + +check_header sys/soundcard.h +check_header soundcard.h + +check_lib2 ao/ao.h ao_open_live -lao && enable libao +check_lib2 alsa/asoundlib.h snd_pcm_open -lasound && enable libasound +check_pkg_config roar roaraudio.h roar_simple_connect && enable libroar +check_lib2 jack/jack.h jack_client_open -ljack && check_func jack_port_get_latency_range -ljack && enable libjack +check_lib2 libffado/ffado.h ffado_streaming_init -lffado && enable libffado +check_lib2 shout/shout.h shout_init -lshout && enable libshout +check_header OpenAL/al.h && check_header OpenAL/alc.h && enable libopenal +check_pkg_config libpulse-simple pulse/simple.h pa_simple_new && enable libpulse +check_lib2 windows.h waveOutOpen -lwinmm && enable winmm + +check_lib2 FLAC/stream_encoder.h FLAC__stream_encoder_new -lFLAC && enable libflac +check_lib vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg && enable libvorbis +check_lib lame/lame.h lame_set_VBR_quality -lmp3lame && enable libmp3lame +check_lib twolame.h twolame_init -ltwolame && enable libtwolame + +check_lib2 "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio || check_lib2 "cdio/paranoia/cdda.h cdio/paranoia/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio && enable libcdio_paranoia +check_lib2 "cdio/cdio.h cdio/iso9660.h" iso9660_open -liso9660 -lcdio && enable libiso9660 +check_pkg_config zziplib zzip/zzip.h zzip_dir_open && enable zziplib + +check_pkg_config curl libcurl curl/curl.h curl_global_init && enable libcurl +check_pkg_config soup "libsoup/soup-uri.h libsoup/soup-session-async.h" soup_message_new && enable libsoup +check_pkg_config despotify despotify.h despotify_play && enable despotify +check_pkg_config yajl yajl/yajl_parse.h yajl_parse && enable libyajl + +check_lib samplerate.h src_new -lsamplerate && enable libsamplerate +check_lib sqlite3.h sqlite3_open -lsqlite3 && enable libsqlite3 + +check_lib tcpd.h hosts_access -lwrap && enable libwrap + +enabled debug && add_cflags -g"$debuglevel" + +# add some useful compiler flags if supported +check_cflags -Wdeclaration-after-statement +check_cflags -Wall +check_cflags -Wno-parentheses +check_cflags -Wno-switch +check_cflags -Wno-format-zero-length +check_cflags -Wdisabled-optimization +check_cflags -Wpointer-arith +check_cflags -Wredundant-decls +check_cflags -Wno-pointer-sign +check_cflags -Wcast-qual +check_cflags -Wwrite-strings +check_cflags -Wtype-limits +check_cflags -Wundef +check_cflags -Wmissing-prototypes +check_cflags -Wstrict-prototypes +enabled extra_warnings && check_cflags -Winline + +# add some linker flags +check_ldflags -Wl,--warn-common + +if [ -z "$optflags" ]; then + if enabled small; then + optflags=$cflags_size + elif enabled optimizations; then + optflags=$cflags_speed + else + optflags=$cflags_noopt + fi +fi + +check_optflags(){ + check_cflags "$@" + enabled lto && check_ldflags "$@" +} + + +if enabled lto; then + test "$cc_type" != "$ld_type" && die "LTO requires same compiler and linker" + check_cflags -flto + check_ldflags -flto $cpuflags +fi + +check_optflags $optflags +check_optflags -fno-math-errno +check_optflags -fno-signed-zeros + +if enabled icc; then + # Just warnings, no remarks + check_cflags -w1 + # -wd: Disable following warnings + # 144, 167, 556: -Wno-pointer-sign + # 1292: attribute "foo" ignored + # 1419: external declaration in primary source file + # 10006: ignoring unknown option -fno-signed-zeros + # 10148: ignoring unknown option -Wno-parentheses + # 10156: ignoring option '-W'; no argument required + check_cflags -wd144,167,556,1292,1419,10006,10148,10156 + # 11030: Warning unknown option --as-needed + # 10156: ignoring option '-export'; no argument required + check_ldflags -wd10156,11030 + # icc 11.0 and 11.1 work with ebp_available, but don't pass the test + enable ebp_available + if enabled x86_32; then + icc_version=$($cc -dumpversion) + test ${icc_version%%.*} -ge 11 && + check_cflags -falign-stack=maintain-16-byte || + disable aligned_stack + fi +elif enabled ccc; then + # disable some annoying warnings + add_cflags -msg_disable bitnotint + add_cflags -msg_disable mixfuncvoid + add_cflags -msg_disable nonstandcast + add_cflags -msg_disable unsupieee +elif enabled gcc; then + check_optflags -fno-tree-vectorize + check_cflags -Werror=implicit-function-declaration + check_cflags -Werror=missing-prototypes + check_cflags -Werror=return-type + #FIXME check_cflags -Werror=declaration-after-statement + #FIXME check_cflags -Werror=vla +elif enabled llvm_gcc; then + check_cflags -mllvm -stack-alignment=16 +elif enabled clang; then + check_cflags -mllvm -stack-alignment=16 + check_cflags -Qunused-arguments + check_cflags -Werror=implicit-function-declaration + check_cflags -Werror=missing-prototypes + check_cflags -Werror=return-type +elif enabled armcc; then + # 2523: use of inline assembler is deprecated + add_cflags -W${armcc_opt},--diag_suppress=2523 + add_cflags -W${armcc_opt},--diag_suppress=1207 + add_cflags -W${armcc_opt},--diag_suppress=1293 # assignment in condition + add_cflags -W${armcc_opt},--diag_suppress=3343 # hardfp compat + add_cflags -W${armcc_opt},--diag_suppress=167 # pointer sign + add_cflags -W${armcc_opt},--diag_suppress=513 # pointer sign +elif enabled tms470; then + add_cflags -pds=824 -pds=837 +elif enabled pathscale; then + add_cflags -fstrict-overflow -OPT:wrap_around_unsafe_opt=OFF +elif enabled msvc; then + enabled x86_32 && disable aligned_stack +fi + +case $target_os in + osf1) + enabled ccc && add_ldflags '-Wl,-expect_unresolved,*' + ;; + plan9) + add_cppflags -Dmain=plan9_main + ;; +esac + +enabled ud && { enabled struct_ucred || enabled getpeereid || die "ERROR: cannot enable Unix domain sockets"; } + +enabled inotify && enabled inotify_init || die "ERROR: inotify_init() not found" + +enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; } + +check_deps $CONFIG_LIST \ + $CONFIG_EXTRA \ + $HAVE_LIST \ + $ALL_COMPONENTS \ + +echo "install prefix $prefix" +echo "source path $source_path" +echo "C compiler $cc" +echo "ARCH $arch ($cpu)" +if test "$build_suffix" != ""; then + echo "build suffix $build_suffix" +fi +if test "$extra_version" != ""; then + echo "version string suffix $extra_version" +fi +echo "debug symbols ${debug-no}" +echo "optimize for size ${small-no}" +echo "optimizations ${optimizations-no}" +echo "Unix domain sockets ${ud-no}" +echo "Inotify DB updates ${inotify-no}" + +echo "External libraries:" +print_enabled '' $EXTERNAL_LIBRARY_LIST | print_3_columns +echo + +for type in encoder input output archive; do + echo "Enabled ${type}s:" + eval list=\$$(toupper $type)_LIST + print_enabled '_*' $list | print_3_columns + echo +done + +echo "Creating config.mak and config.h..." + +test -e Makefile || $ln_s "$source_path/Makefile" . + +config_files="$TMPH config.mak" + +cat > config.mak <<EOF +# Automatically generated by configure - do not modify! +MPD_CONFIGURATION=$MPD_CONFIGURATION +prefix=$prefix +BINDIR=\$(DESTDIR)$bindir +DATADIR=\$(DESTDIR)$datadir +MANDIR=\$(DESTDIR)$mandir +CONFDIR=\$(DESTDIR)$confdir +SRC_PATH=$source_path +CC_IDENT=$cc_ident +ARCH=$arch +CC=$cc +LD=$ld +DEPCC=$dep_cc +DEPCCFLAGS=$DEPCCFLAGS \$(CPPFLAGS) +DEPASFLAGS=$DEPASFLAGS \$(CPPFLAGS) +AR=$ar +ARFLAGS=$arflags +AR_O=$ar_o +RANLIB=$ranlib +LN_S=$ln_s +CPPFLAGS=$CPPFLAGS +CFLAGS=$CFLAGS +CC_C=$CC_C +CC_E=$CC_E +CC_O=$CC_O +LD_O=$LD_O +LD_LIB=$LD_LIB +LD_PATH=$LD_PATH +LDFLAGS=$LDFLAGS +BUILDSUF=$build_suffix +FULLNAME=$FULLNAME +EXESUF=$EXESUF +EXTRA_VERSION=$extra_version +CCDEP=$CCDEP +CCDEP_FLAGS=$CCDEP_FLAGS +CC_DEPFLAGS=$CC_DEPFLAGS +HOSTCC=$host_cc +HOSTLD=$host_ld +HOSTCFLAGS=$host_cflags +HOSTCPPFLAGS=$host_cppflags +HOSTEXESUF=$HOSTEXESUF +HOSTLDFLAGS=$host_ldflags +HOSTLIBS=$host_libs +DEPHOSTCC=$host_cc +DEPHOSTCCFLAGS=$DEPHOSTCCFLAGS \$(HOSTCCFLAGS) +HOSTCCDEP=$HOSTCCDEP +HOSTCCDEP_FLAGS=$HOSTCCDEP_FLAGS +HOSTCC_DEPFLAGS=$HOSTCC_DEPFLAGS +HOSTCC_C=$HOSTCC_C +HOSTCC_O=$HOSTCC_O +HOSTLD_O=$HOSTLD_O +TARGET_EXEC=$target_exec +TARGET_PATH=$target_path +ZLIB=$($ldflags_filter -lz) +EXTRALIBS=$extralibs +COMPAT_OBJS=$compat_objs +EXEOBJS=$exeobjs +INSTALL=install +EOF + +cat > $TMPH <<EOF +/* Automatically generated by configure - do not modify! */ +#ifndef MPD_CONFIG_H +#define MPD_CONFIG_H +#define MPD_CONFIGURATION "$(c_escape $MPD_CONFIGURATION)" +#define PROTOCOL_VERSION "0.17.0" +#define MPD_DATADIR "$(eval c_escape $datadir)" +#define PACKAGE "MPD" +#define VERSION "c--" +#define SYSTEM_CONFIG_FILE_LOCATION "$(eval c_escape $confdir)" +#define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})" +#define restrict $_restrict +#define EXTERN_PREFIX "${extern_prefix}" +EOF + +test -n "$malloc_prefix" && + echo "#define MALLOC_PREFIX $malloc_prefix" >>$TMPH + +print_config ARCH_ "$config_files" $ARCH_LIST +print_config HAVE_ "$config_files" $HAVE_LIST +print_config CONFIG_ "$config_files" $CONFIG_LIST \ + $CONFIG_EXTRA \ + $ALL_COMPONENTS \ + +echo "#endif /* MPD_CONFIG_H */" >> $TMPH + +# Do not overwrite an unchanged config.h to avoid superfluous rebuilds. +cp_if_changed $TMPH config.h +touch .config + +test -n "$WARNINGS" && printf "\n$WARNINGS" |