#!/bin/sh

#     Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
#
# This file is part of roard a part of RoarAudio,
# a cross-platform sound system for both, home and professional use.
# See README for details.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# RoarAudio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

# This code sets up $ROAR_BUILDSYSTEM_DIR
if [ "$1" = '--buildsystem' ]
then
 ROAR_BUILDSYSTEM_DIR="$2"
 shift 2
fi

if [ "$ROAR_BUILDSYSTEM_DIR" = '' ]
then
 for dir in `roar-config --path prefix-buildsystem 2> /dev/null` \
             /usr/lib/roaraudio/build-system/ \
             /usr/local/lib/roaraudio/build-system/
 do
  if [ -d "$dir" ]
  then
   ROAR_BUILDSYSTEM_DIR="$dir"
   break
  fi
 done
fi

if [ "$ROAR_BUILDSYSTEM_DIR" = '' ]
then
 echo 'Can not find build system. Try --buildsystem /path/to/build-system/' >&2
 exit 1
fi

# now we include the build system.
. "$ROAR_BUILDSYSTEM_DIR/configure.all"


# the real configure starts here:

# Bad libxml-2.0 hack:
CFLAGS="$CFLAGS -I/usr/include/libxml2"

test_libroar '1.0.11' || exit 1
test_pkgversion
test_buildstamp
test_cc
test_ranlib
test_pkgconfig
test_sysname

while [ "$1" != '' ]
do
 parse_option "$@"
 shift $SHIFT_COUNT
 $HANDLED && continue;

 case "$1" in
  '--help')
   write_help
   echo 'OPTIONS:'
   exit 0;
  ;;
  *)
   echo "Error: unknown option: $1" >&2;
   echo "Try: $0 --help" >&2;
   exit 1;
  ;;
 esac;

 shift;
done

open_configure_files
update_target
test_crosscompile
update_prefixes
update_ccft
update_cc
test_wextra

write_header _CONFIG_H_

test_bin_format
test_linkdeps
test_cp_v


echo -n 'checking for user id of root/superuser... '
if [ "$ROOT_UID" = '(none)' ]
then
 echo "none (disabled by user)"
elif [ "$ROOT_UID" = '' ]
then
 ROOT_USER='root'
 ROOT_UID=`id -u $ROOT_USER`
 if [ "$ROOT_UID" = '' ]
 then
  echo "none (please report this)"
 else
  echo "$ROOT_UID($ROOT_USER)"
  echo "ROOT_UID=$ROOT_UID" >&4
 fi
else
 echo "$ROOT_UID"
 echo "ROOT_UID=$ROOT_UID" >&4
fi

test_func_defmake HAVE_FUNC_UALARM    ualarm    'ualarm(0, 0)'               -- unistd.h
test_func_defmake HAVE_FUNC_SIGINTERRUPT siginterrupt 'siginterrupt(0, 0)' -- signal.h
test_lib_defmake  HAVE_H_STDINT      %            stdint.h   c             -- stdint.h
test_lib_defmake  HAVE_LIB_WSOCK32   %            WinSockP0  wsock32       -- winsock2.h
test_lib_defmake  HAVE_LIB_WS2_32    %            WinSockP1  ws2_32        -- winsock2.h
test_lib_defmake  HAVE_LIB_SLP       %            OpenSLP    slp           -- slp.h
test_lib_defmake  HAVE_LIB_XML2      %            libxml-2   xml2          -- libxml/tree.h libxml/parser.h libxml/xmlreader.h libxml/xpath.h libxml/xpathInternals.h libxml/uri.h
test_lib_defmake  HAVE_LIB_ROAR      %            RoarAudio  roar          -- roaraudio.h
if [ "$?" != '0' ]
then
 echo "Error: can not find libroar" >&2
 exit 1
fi

write_vars_configh_literal ROOT_UID
write_vars_configh_string VERSION BUILD_STAMP DISTRIBUTION_VERSION_STRING

cleanup_ccft

write_footer

#ll
