diff acinclude.m4 @ 30:fde5167bb736

Updated to have macros for detecting libSIDPlay 1 and 2
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Jun 2003 23:54:00 +0000
parents 183e7cbc1036
children ca6dab6c4ead
line wrap: on
line diff
--- a/acinclude.m4	Sat Jun 07 23:52:00 2003 +0000
+++ b/acinclude.m4	Sat Jun 07 23:54:00 2003 +0000
@@ -1,167 +1,523 @@
-dnl Some handy functions
+dnl *** These m4-macros are directly ripped from XSIDPlay's acinclude.m4
+dnl *** (C) Copyright 2002 Michael Schwendt, licensed under GNU GPL v2.
+
+dnl -------------------------------------------------------------------------
+dnl Try to find a file (or one of more files in a list of dirs).
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_FIND_FILE,
+[
+    $3=""
+    for i in $2;
+    do
+        for j in $1;
+        do
+	        if test -r "$i/$j"; then
+		        $3=$i
+                break 2
+            fi
+        done
+    done
+])
+
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_SUBST,
+dnl Substitute an instance of @$1@ with value "$2".
+dnl Example: MY_SUBST(FOO,BAR) <-> @FOO@ => BAR
+[
+    eval "$1=$2"
+    AC_SUBST($1)
+])
+
+AC_DEFUN(MY_SUBST_DEF,
+dnl Substitute an instance of @$1@ with value "#define $1".
+dnl Example: MY_SUBST_DEF(FOO) <-> @FOO@ => #define FOO
+[
+    eval "$1=\"#define $1\""
+    AC_SUBST($1)
+])
+
+AC_DEFUN(MY_SUBST_UNDEF,
+dnl Substitute an instance of @$1@ with value "#undef $1".
+dnl Example: MY_SUBST_UNDEF(FOO) <-> @FOO@ => #undef FOO
+[
+    eval "$1=\"#undef $1\""
+    AC_SUBST($1)
+])
+
+dnl -------------------------------------------------------------------------
+dnl Check whether compiler has a working ``bool'' type.
+dnl -------------------------------------------------------------------------
 
-dnl Try a list of directories, set the first one found
-dnl Usage: AC_CHECK_DIRS(DIRECTORY..., ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
+AC_DEFUN(MY_CHECK_BOOL,
+[
+    AC_MSG_CHECKING([for bool])
+    AC_CACHE_VAL(my_cv_have_bool,
+    [
+        AC_TRY_COMPILE(
+            [],
+            [bool aBool = true;],
+            [my_cv_have_bool=yes],
+            [my_cv_have_bool=no]
+        )
+    ])
+    AC_MSG_RESULT($my_cv_have_bool)
+    if test "$my_cv_have_bool" = yes; then
+        AC_DEFINE(XSID_HAVE_BOOL)
+    fi 
+])
+
+dnl -------------------------------------------------------------------------
+dnl Check whether C++ library has openmode ios::bin instead of ios::binary.
+dnl Will define XSID_HAVE_IOS_BIN if ios::binary is not available.
+dnl -------------------------------------------------------------------------
 
-AC_DEFUN(AC_CHECK_DIRS,
+AC_DEFUN(MY_CHECK_IOS_BIN,
+[
+    AC_MSG_CHECKING(whether standard openmode ios::binary is available)
+    AC_CACHE_VAL(my_cv_have_ios_binary,
+    [
+        AC_TRY_COMPILE(
+            [#include <fstream.h>],
+		    [ifstream myTest("test",ios::in|ios::binary);],
+		    [my_cv_have_ios_binary=yes],
+		    [my_cv_have_ios_binary=no]
+	    )
+    ])
+    AC_MSG_RESULT($my_cv_have_ios_binary)
+    if test "$my_cv_have_ios_binary" = no; then
+        AC_DEFINE(XSID_HAVE_IOS_BIN)
+    fi
+])
+
+dnl -------------------------------------------------------------------------
+dnl Check whether C++ compiler supports the "nothrow allocator".
+dnl Will define XSID_HAVE_NOTHROW if test code compiles.
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_CHECK_NOTHROW,
+[
+    AC_MSG_CHECKING(whether nothrow allocator is available)
+    AC_CACHE_VAL(my_cv_have_nothrow,
+    [
+        AC_TRY_COMPILE(
+            [#include <new>],
+		    [char* buf = new(std::nothrow) char[1024];],
+		    [my_cv_have_nothrow=yes],
+		    [my_cv_have_nothrow=no]
+	    )
+    ])
+    AC_MSG_RESULT($my_cv_have_nothrow)
+    if test "$my_cv_have_nothrow" = yes; then
+        AC_DEFINE(XSID_HAVE_NOTHROW)
+    fi
+])
+
+dnl -------------------------------------------------------------------------
+dnl Pass C++ compiler options to libtool which supports C only.
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_PROG_LIBTOOL,
 [
-for ac_dir in $1
-do
-AC_MSG_CHECKING([for directory ${ac_dir}])
-if test -d ${ac_dir}
-then
-  AC_MSG_RESULT(yes)
-  ifelse([$2], , :, [$2])
-  break
-else
-  AC_MSG_RESULT(no)
-fi
-done
-if test ! -d ${ac_dir}
-then
-  ifelse([$3], , :, [$3])
-fi
+    my_save_cc="$CC"
+    my_save_cflags="$CFLAGS"
+    CC="$CXX"
+    CFLAGS="$CXXFLAGS"
+    AM_PROG_LIBTOOL
+    CC="$my_save_cc"
+    CFLAGS="$my_save_cflags"
+])
+
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_TRY_LINK_SAVE,
+[
+    my_cxx_save="$CXX"
+    my_cxxflags_save="$CXXFLAGS"
+    my_ldflags_save="$LDFLAGS"
+    my_libs_save="$LIBS"
+])
+
+AC_DEFUN(MY_TRY_LINK_RESTORE,
+[
+    CXX="$my_cxx_save"
+    CXXFLAGS="$my_cxxflags_save"
+    LDFLAGS="$my_ldflags_save"
+    LIBS="$my_libs_save"
+])
+
+AC_DEFUN(MY_PROG_PKGCONFIG,
+[
+    AC_PATH_PROG(PKG_CONFIG, pkg-config, "")
+])
+
+AC_DEFUN(MY_NEED_PKGCONFIG,
+[
+    AC_REQUIRE([MY_PROG_PKGCONFIG])
+    if test -z "$PKG_CONFIG"; then
+        AC_MSG_ERROR([pkg-config not found. See http://pkgconfig.sourceforge.net])
+    fi
+    if ! $PKG_CONFIG --atleast-pkgconfig-version 0.5 ; then
+        AC_MSG_ERROR([pkg-config too old; version 0.5 or better required.])
+    fi
+])
+
+dnl -------------------------------------------------------------------------
+dnl Try to find SIDPLAY library and header files.
+dnl $my_cv_have_sidplay will be "yes" or "no"
+dnl @SIDPLAY_LDADD@ will be substituted with linker parameters
+dnl @SIDPLAY_INCLUDES@ will be substituted with compiler parameters
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN(MY_PATH_LIBSIDPLAY,
+[
+    AC_MSG_CHECKING([for working SIDPLAY library and headers])
+    AC_REQUIRE([MY_ARGS_LIBSIDPLAY])
+    
+    # Use include path given by user (if any).
+    if test -n "$my_sidplay_includes"; then
+        my_sidplay_cxxflags="-I$my_sidplay_includes"
+    else
+        my_sidplay_cxxflags=""
+    fi
+
+    # Use library path given by user (if any).
+    if test -n "$my_sidplay_library"; then
+        my_sidplay_ldflags="-L$my_sidplay_library"
+    else
+        my_sidplay_ldflags=""
+    fi
+
+    AC_CACHE_VAL(my_cv_have_sidplay,
+    [
+        # Run test compilation with either standard search path
+        # or user-defined paths.
+        MY_TRY_LIBSIDPLAY
+        if test "$my_sidplay_works" = yes; then
+          my_cv_have_sidplay="my_have_sidplay=yes  \
+            my_sidplay_cxxflags=\"$my_sidplay_cxxflags\"  \
+            my_sidplay_ldflags=\"$my_sidplay_ldflags\"  "
+        else
+            MY_FIND_LIBSIDPLAY        
+        fi
+    ])
+    eval "$my_cv_have_sidplay"
+    if test "$my_have_sidplay" = yes; then
+        if test -n "$my_sidplay_cxxflags" || test -n "$my_sidplay_ldflags"; then
+            AC_MSG_RESULT([$my_sidplay_cxxflags $my_sidplay_ldflags])
+        else
+            AC_MSG_RESULT([yes])
+        fi
+    else
+        AC_MSG_RESULT([no])
+    fi
+    SIDPLAY_LDADD="$my_sidplay_ldflags -lsidplay"
+    SIDPLAY_INCLUDES="$my_sidplay_cxxflags"
+    AC_SUBST(SIDPLAY_LDADD)
+    AC_SUBST(SIDPLAY_INCLUDES)
+])
+
+dnl Functions used by MY_PATH_LIBSIDPLAY.
+
+AC_DEFUN(MY_FIND_LIBSIDPLAY,
+[
+    # Search common locations where header files might be stored.
+    my_sidplay_incdirs="$my_sidplay_includes /usr/include /usr/local/include \
+                        /usr/lib/sidplay/include /usr/local/lib/sidplay/include"
+    MY_FIND_FILE(sidplay/sidtune.h, $my_sidplay_incdirs, \
+                 my_sidplay_includes)
+
+    # Search common locations where library might be stored.
+    my_sidplay_libdirs="$my_sidplay_library /usr/lib /usr/lib/sidplay \
+                        /usr/local/lib/sidplay"
+    MY_FIND_FILE(libsidplay.a libsidplay.so libsidplay.so.1 libsidplay.so.1.36 libsidplay.so.1.37,
+                 $my_sidplaylibdirs, my_sidplay_library)
+
+    if test -z "$my_sidplay_includes" || test -z "$my_sidplay_library"; then
+        my_cv_have_sidplay="my_have_sidplay=no  \
+          my_sidplay_ldflags=\"\" my_sidplay_cxxflags=\"\"  "
+    else
+        # Test compilation with found paths.
+        my_sidplay_ldflags="-L$my_sidplay_library"
+        my_sidplay_cxxflags="-I$my_sidplay_includes"
+        MY_TRY_LIBSIDPLAY
+        my_cv_have_sidplay="my_have_sidplay=$my_sidplay_works  \
+          my_sidplay_ldflags=\"$my_sidplay_ldflags\"  \
+          my_sidplay_cxxflags=\"$my_sidplay_cxxflags\"  "
+    fi
 ])
 
-# sidplay.m4  sidplay checks
+AC_DEFUN(MY_TRY_LIBSIDPLAY,
+[
+    MY_TRY_LINK_SAVE
+
+    CXXFLAGS="$CXXFLAGS $my_sidplay_cxxflags"
+    LDFLAGS="$LDFLAGS $my_sidplay_ldflags"
+    LIBS="$LIBS -lsidplay"
 
-AC_DEFUN(AC_FIND_FILE,
-    [
-	$3=NO
-	for i in $2;
-	do
-	  for j in $1;
-	  do
-	    if test -r "$i/$j"; then
-		  $3=$i
-		  break 2
-		fi
-	  done
-	done
-    ]
-)
+    AC_TRY_LINK(
+        [#include <sidplay/sidtune.h>],
+        [sidTune* myTest = new sidTune(0);],
+        [my_sidplay_works=yes],
+        [my_sidplay_works=no]
+    )
+    MY_TRY_LINK_RESTORE
+])
 
-AC_DEFUN(AC_PATH_LIBSIDPLAY,
-[
-AC_MSG_CHECKING([for SIDPLAY includes and library])
-AC_LANG_SAVE
-AC_LANG_CPLUSPLUS
-ac_sidplay_cflags=NO
-ac_sidplay_library=NO
-sidplay_cflags=""
-sidplay_library=""
+dnl -------------------------------------------------------------------------
+dnl Try to find SIDPLAY2 library and header files.
+dnl $my_cv_have_sidplay2 will be "yes" or "no"
+dnl @SIDPLAY_LDADD@ will be substituted with linker parameters
+dnl @SIDPLAY_INCLUDES@ will be substituted with compiler parameters
+dnl -------------------------------------------------------------------------
 
-AC_ARG_WITH(sidplay-prefix,
-  [  --with-sidplay-prefix=DIR
-                          where the sidplay includes and library are located],
-  [ac_sidplay_cflags="${withval}/include"
-   ac_sidplay_library="${withval}/lib"
-  ])
-
-AC_ARG_WITH(sidplay-includes,
-  [  --with-sidplay-includes=DIR
-                          where the sidplay includes are located],
-  [ac_sidplay_cflags="$withval"
-  ])
+AC_DEFUN(MY_PATH_LIBSIDPLAY2,
+[
+    AC_MSG_CHECKING([for working SIDPLAY2 library and headers])
+    
+    AC_REQUIRE([MY_PROG_PKGCONFIG])
+    if test -n "$PKG_CONFIG" && $PKG_CONFIG --atleast-version $LIBSIDPLAY2_REQUIRED_VERSION libsidplay2; then
+        my_pkgcfg_knows=yes
+    else
+        my_pkgcfg_knows=no
+    fi
+dnl    echo "(" pkg-config knows = $my_pkgcfg_knows ")"
 
-AC_ARG_WITH(sidplay-library,
-  [  --with-sidplay-library=DIR
-                          where the sidplay library is installed],
-  [ac_sidplay_library="$withval"
-  ])
-
-if test "$ac_sidplay_cflags" = NO || test "$ac_sidplay_library" = NO; then
-#search common locations
+    AC_REQUIRE([MY_ARGS_LIBSIDPLAY])
+    # Share --with-* args with libsidplay1.
+    my_sidplay2_library="$my_sidplay_library"
+    my_sidplay2_includes="$my_sidplay_includes"
 
-AC_CACHE_VAL(ac_cv_have_sidplay,
-[
-sidplay_incdirs="$ac_sidplay_cflags /usr/include /usr/local/include /usr/lib/sidplay/include /usr/local/lib/sidplay/include"
-AC_FIND_FILE(sidplay/sidtune.h,$sidplay_incdirs,sidplay_foundincdir)
-ac_sidplay_cflags=$sidplay_foundincdir
-
-sidplay_libdirs="$ac_sidplay_library /usr/lib /usr/local/lib /usr/lib/sidplay /usr/local/lib/sidplay"
-AC_FIND_FILE(libsidplay.so libsidplay.so.1 libsidplay.so.1.36 libsidplay.so.1.37,$sidplay_libdirs,sidplay_foundlibdir)
-ac_sidplay_library=$sidplay_foundlibdir
+    # Derive sidbuilders path from libsidplay2 root.
+    if test -n "$my_sidplay2_library"; then
+        my_sidplay2_builders="$my_sidplay2_library/sidplay/builders"
+    elif test "$my_pkgcfg_knows" = yes ; then
+        my_sidplay2_builders=`$PKG_CONFIG --variable=builders libsidplay2`
+    fi
 
-if test "$ac_sidplay_cflags" = NO || test "$ac_sidplay_library" = NO; then
-  ac_cv_have_sidplay="have_sidplay=no"
-  ac_sidplay_notfound=""
-  if test "$ac_sidplay_cflags" = NO; then
-    if test "$ac_sidplay_library" = NO; then
-      ac_sidplay_notfound="(headers and library)";
+    AC_CACHE_VAL(my_cv_have_sidplay2,
+    [
+        # Run test compilation with either standard search path
+        # or user-defined paths.
+        my_sidplay2_ldadd="-lsidplay2"
+        MY_TRY_LIBSIDPLAY2
+        if test "$my_sidplay2_works" = yes; then
+          my_cv_have_sidplay2="my_have_sidplay2=yes  \
+            my_sidplay2_cxxflags=\"$my_sidplay2_cxxflags\"  \
+            my_sidplay2_ldadd=\"$my_sidplay2_ldadd\"  \
+            my_sidplay2_builders=\"$my_sidplay2_builders\"  "
+        else
+            MY_FIND_LIBSIDPLAY2
+        fi
+    ])
+    eval "$my_cv_have_sidplay2"
+    if test "$my_have_sidplay2" = yes; then
+        if test -n "$my_sidplay2_cxxflags" || test -n "$my_sidplay2_ldadd"; then
+            AC_MSG_RESULT([$my_sidplay2_cxxflags $my_sidplay2_ldadd])
+        else
+            AC_MSG_RESULT([yes])
+        fi
     else
-      ac_sidplay_notfound="(headers)";
+        AC_MSG_RESULT([no])
     fi
-  else
-    ac_sidplay_notfound="(library)";
-  fi
-  eval "$ac_cv_have_sidplay"
-  AC_MSG_RESULT([$have_sidplay])
-else
-  have_sidplay=yes
-fi
+    SIDPLAY_LDADD="$my_sidplay2_ldadd"
+    SIDPLAY_INCLUDES="$my_sidplay2_cxxflags"
+    AC_SUBST(SIDPLAY_LDADD)
+    AC_SUBST(SIDPLAY_INCLUDES)
+])
 
-])  dnl AC_CACHE_VAL(ac_cv_have_sidplay,
-else
-  have_sidplay=yes
-fi  dnl if (have_to_search)
-
-eval "$ac_cv_have_sidplay"
+dnl Functions used by MY_PATH_LIBSIDPLAY.
 
-if test "$have_sidplay" != yes; then
-  AC_MSG_RESULT([$have_sidplay]);
-else
-  ac_cv_have_sidplay="have_sidplay=yes \
-    ac_sidplay_cflags=$ac_sidplay_cflags ac_sidplay_library=$ac_sidplay_library"
-  AC_MSG_RESULT([library $ac_sidplay_library, headers $ac_sidplay_cflags])
-  
-  sidplay_library=$ac_sidplay_library
-  sidplay_cflags=$ac_sidplay_cflags
-  
-  SIDPLAY_LIBS="-L$sidplay_library -lsidplay"
-  all_libraries="$SIDPLAY_LIBS $all_libraries"
-  SIDPLAY_CFLAGS="-I$sidplay_cflags"
-  all_includes="$SIDPLAY_CFLAGS $all_includes"
-fi
-
-dnl Test compilation.
-
-AC_MSG_CHECKING([whether -lsidplay works])
-ac_cxxflags_safe=$CXXFLAGS
-ac_ldflags_safe=$LDFLAGS
-ac_libs_safe=$LIBS
-
-CXXFLAGS="$CXXFLAGS -I$sidplay_cflags"
-LDFLAGS="$LDFLAGS -L$sidplay_library"
-LIBS="-lsidplay"
-
-AC_CACHE_VAL(ac_cv_sidplay_works,
+AC_DEFUN(MY_FIND_LIBSIDPLAY2,
 [
-    AC_TRY_LINK(
-	    [#include <sidplay/sidtune.h>],
-		[sidTune* myTest;],
-		[ac_cv_sidplay_works=yes],
-		[ac_cv_sidplay_works=no]
-   )
+    # See whether user didn't provide paths.
+    if test -z "$my_sidplay2_includes"; then
+        if test "$my_pkgcfg_knows" = yes ; then
+            my_sidplay2_includes=`$PKG_CONFIG --variable=includedir libsidplay2`
+            my_sidplay2_cxxflags=`$PKG_CONFIG --cflags libsidplay2`
+        else
+            # Search common locations where header files might be stored.
+            my_sidplay2_incdirs="$my_sidplay2_includes $my_sidplay2_includes/include"
+            MY_FIND_FILE(sidplay/sidplay2.h,$my_sidplay2_incdirs,my_sidplay2_includes)
+            my_sidplay2_cxxflags="-I$my_sidplay2_includes"
+        fi
+    else
+        my_sidplay2_cxxflags="-I$my_sidplay2_includes"
+    fi
+    if test -z "$my_sidplay2_library"; then
+        if test "$my_pkgcfg_knows" = yes ; then
+            my_sidplay2_library=`$PKG_CONFIG --variable=libdir libsidplay2`
+            my_sidplay2_ldadd=`$PKG_CONFIG --libs libsidplay2`
+            my_sidplay2_builders=`$PKG_CONFIG --variable=builders libsidplay2`
+        else
+            # Search common locations where library might be stored.
+            my_sidplay2_libdirs="$my_sidplay2_library $my_sidplay2_library/lib \
+                              $my_sidplay2_library/src"
+            MY_FIND_FILE(libsidplay2.la,$my_sidplay2_libdirs,my_sidplay2_library)
+            my_sidplay2_ldadd="-L$my_sidplay2_library -lsidplay2"
+            my_sidplay2_builders="$my_sidplay2_library/sidplay/builders"
+        fi
+    else
+        my_sidplay2_ldadd="-L$my_sidplay2_library -lsidplay2"
+    fi
+    if test -z "$my_sidplay2_includes" || test -z "$my_sidplay2_library"; then
+        my_cv_have_sidplay2="my_have_sidplay2=no \
+          my_sidplay2_ldadd=\"\" my_sidplay2_cxxflags=\"\" \
+          my_sidplay2_builders=\"\" "
+    else
+        # Test compilation with found paths.
+        my_sidplay2_ldadd="-L$my_sidplay2_library -lsidplay2"
+        my_sidplay2_cxxflags="-I$my_sidplay2_includes"
+        MY_TRY_LIBSIDPLAY2
+        my_cv_have_sidplay2="my_have_sidplay2=$my_sidplay2_works \
+          my_sidplay2_ldadd=\"$my_sidplay2_ldadd\" \
+          my_sidplay2_cxxflags=\"$my_sidplay2_cxxflags\" \
+          my_sidplay2_builders=\"$my_sidplay2_builders\" "
+    fi
+    echo "DEBUG: $my_sidplay2_cxxflags"
+    echo "DEBUG: $my_sidplay2_ldadd"
 ])
 
-CXXFLAGS="$ac_cxxflags_safe"
-LDFLAGS="$ac_ldflags_safe"
-LIBS="$ac_libs_safe"
+AC_DEFUN(MY_TRY_LIBSIDPLAY2,
+[
+    MY_TRY_LINK_SAVE
+
+    CXX="${SHELL-/bin/sh} ${srcdir}/libtool $CXX"
+    CXXFLAGS="$CXXFLAGS $my_sidplay2_cxxflags -DHAVE_UNIX"
+    LDFLAGS="$LDFLAGS $my_sidplay2_ldadd"
+
+    AC_TRY_LINK(
+        [#include <sidplay/sidplay2.h>],
+        [sidplay2 *myEngine;],
+        [my_sidplay2_works=yes],
+        [my_sidplay2_works=no]
+    )
+    MY_TRY_LINK_RESTORE
+])
 
-AC_MSG_RESULT([$ac_cv_sidplay_works])
-if test "$ac_cv_sidplay_works" != yes; then
-  have_sidplay=no
-fi
+dnl -------------------------------------------------------------------------
+dnl Find libsidplay2 builders (sidbuilders) dir.
+dnl @BUILDERS_INCLUDES@
+dnl @BUILDERS_LDFLAGS@
+dnl -------------------------------------------------------------------------
+AC_DEFUN(BUILDERS_FIND,
+[
+    AC_MSG_CHECKING([for SIDPLAY2 builders directory])
+    AC_REQUIRE([MY_PATH_LIBSIDPLAY2])
+
+    dnl Be pessimistic.
+    builders_available=no
+
+    dnl Sidbuilder headers are included with "builders" prefix.
+    builders_includedir=$my_sidplay2_includes
+    builders_libdir=$my_sidplay2_builders
+
+    dnl If libsidplay2 is in standard library search path, we need
+    dnl to get an argument whether /usr, /usr/local, etc. Else we
+    dnl can only use ${libdir}/sidplay/builders, but then are
+    dnl unable to check whether files exist as long as ${exec_prefix}
+    dnl is not defined in the configure script. So, this is a bit
+    dnl ugly, but a satisfactory fallback default for those who
+    dnl define ${prefix} and ${exec_prefix}.
+    if test -z $builders_libdir; then
+        eval "builders_libdir=$libdir/sidplay/builders"
+    fi
 
-dnl
-
-AC_SUBST(SIDPLAY_CFLAGS)
-AC_SUBST(SIDPLAY_LIBS)
+    AC_ARG_WITH(sidbuilders,
+        [  --with-sidbuilders=DIR  what the SIDPLAY2 builders install PREFIX is],
+        [builders_includedir="$withval/include"
+         builders_libdir="$withval/lib/sidplay/builders"]
+    )
+    AC_ARG_WITH(builders-inc,
+        [  --with-builders-inc=DIR where the SIDPLAY2 builders headers are located],
+        [builders_includedir="$withval"]
+    )
+    AC_ARG_WITH(builders-lib,
+        [  --with-builders-lib=DIR where the SIDPLAY2 builders libraries are installed],
+        [builders_libdir="$withval"]
+    )
+    
+    if test -n "$builders_includedir"; then
+        BUILDERS_INCLUDES="-I$builders_includedir"
+    fi
+    if test -n "$builders_libdir"; then
+        BUILDERS_LDFLAGS="-L$builders_libdir"
+    fi
+    if test -d $builders_libdir; then
+        my_have_sidbuilders_dir=yes
+        AC_MSG_RESULT([$builders_libdir])
+    else
+        my_have_sidbuilders_dir=no
+        AC_MSG_RESULT([$my_have_sidbuilders_dir])
+        AC_MSG_ERROR([$builders_libdir not found!
+Check --help on how to specify SIDPLAY2 and/or builders library and
+header path, or set --exec-prefix to the same prefix as your installation
+of libsidplay2.
+        ])
+    fi
+    AC_SUBST(BUILDERS_INCLUDES)
+    AC_SUBST(BUILDERS_LDFLAGS)
+])
 
-AC_SUBST(sidplay_library)
-AC_SUBST(sidplay_cflags)
+dnl -------------------------------------------------------------------------
+dnl Test for working reSID builder.
+dnl sets $(RESID_LDADD), substitutes @RESID_LDADD@
+dnl -------------------------------------------------------------------------
+AC_DEFUN(BUILDERS_FIND_RESID,
+[
+    AC_MSG_CHECKING([for reSID builder module])
+    MY_TRY_LINK_SAVE
+    
+    CXX="${SHELL-/bin/sh} ${srcdir}/libtool $CXX"
+    CXXFLAGS="$CXXFLAGS $BUILDERS_INCLUDES"
+    LDFLAGS="$LDFLAGS $BUILDERS_LDFLAGS"
+    LIBS="$LIBS -lresid-builder"
+
+    AC_TRY_LINK(
+        [#include <sidplay/builders/resid.h>],
+        [ReSIDBuilder *sid;],
+        [builders_work=yes],
+        [builders_work=no]
+    )
+    MY_TRY_LINK_RESTORE
+
+    if test "$builders_work" = yes; then
+        builders_available=yes
+        AC_DEFINE(XSID_HAVE_RESID_BUILDER)
+        RESID_LDADD="-lresid-builder"
+    fi
+    AC_MSG_RESULT($builders_work)
+    AC_SUBST(RESID_LDADD)
+])
 
-AC_LANG_RESTORE
+dnl -------------------------------------------------------------------------
+dnl Test for working HardSID builder.
+dnl sets $(HARDSID_LDADD), substitutes @HARDSID_LDADD@
+dnl -------------------------------------------------------------------------
+AC_DEFUN(BUILDERS_FIND_HARDSID,
+[
+    AC_MSG_CHECKING([for HardSID builder module])
+    MY_TRY_LINK_SAVE
+
+    CXX="${SHELL-/bin/sh} ${srcdir}/libtool $CXX"
+    CXXFLAGS="$CXXFLAGS $BUILDERS_INCLUDES"
+    LDFLAGS="$LDFLAGS $BUILDERS_LDFLAGS"
+    LIBS="$LIBS -lhardsid-builder"
 
+    AC_TRY_LINK(
+        [#include <sidplay/builders/hardsid.h>],
+        [HardSID *sid;],
+        [builders_work=yes],
+        [builders_work=no]
+    )
+    MY_TRY_LINK_RESTORE
+
+    if test "$builders_work" = yes; then
+        builders_available=yes
+        AC_DEFINE(XSID_HAVE_HARDSID_BUILDER)
+        HARDSID_LDADD="-lhardsid-builder"
+    fi
+    AC_MSG_RESULT($builders_work)
+    AC_SUBST(HARDSID_LDADD)
 ])