Blame m4/compilelinkrun.m4

Packit Service 6754ca
dnl
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl compilelinkrun.m4 - used to check whether a required package is properly 
Packit Service 6754ca
dnl installed.  Compiles, links and runs a c++ test program that uses the 
Packit Service 6754ca
dnl package to verify that the package is properly installed
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl Expected arguments:
Packit Service 6754ca
dnl $1: the name of the package we are testing, e.g. "OpenEXR"
Packit Service 6754ca
dnl     used for informational messages, warnings & errors
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $2: the argument passed to configure specifying how to disable this test
Packit Service 6754ca
dnl     for example:
Packit Service 6754ca
dnl     $3 = "openexrtest" and 
Packit Service 6754ca
dnl     "configure --disable-openexrtest" will skip the test
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $3: CXXFLAGS used by the test
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $4: LDFLAGS used by the test
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $5: include section of sourcecode for a c++ test program
Packit Service 6754ca
dnl $6: body section of sourcecode for a c++ test program
Packit Service 6754ca
dnl The test program should make use of a library that is supposed to 
Packit Service 6754ca
dnl be tested.
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $7: the action to be perfomed if the test succeeds 
Packit Service 6754ca
dnl     (e.g. AC_MSG_RESULT("OpenEXR test program succeeded"))
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl $8   the action to be perfomed if the test fails
Packit Service 6754ca
dnl     (e.g. AC_MSG_ERROR("OpenEXR test program failed"))
Packit Service 6754ca
dnl
Packit Service 6754ca
Packit Service 6754ca
AC_DEFUN([AM_COMPILELINKRUN],
Packit Service 6754ca
[
Packit Service 6754ca
Packit Service 6754ca
dnl create some local m4 "variables" so that we don't have to use numbers
Packit Service 6754ca
define([arg_pkg_name],$1)
Packit Service 6754ca
define([arg_disable],$2)
Packit Service 6754ca
define([arg_cxxflags],$3)
Packit Service 6754ca
define([arg_ldflags],$4)
Packit Service 6754ca
define([arg_libs],$5)
Packit Service 6754ca
define([arg_include_source],$6)
Packit Service 6754ca
define([arg_body_source],$7)
Packit Service 6754ca
define([arg_do_yes],$8)
Packit Service 6754ca
define([arg_do_no],$9)
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
dnl check arguments
Packit Service 6754ca
AC_ARG_ENABLE(arg_disable, [  --disable-arg_disable  Do not try to compile and run a test arg_pkg_name program],, enable_programtest=yes)
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
dnl
Packit Service 6754ca
dnl if the test hasn't been disabled, then compile, link and run test program
Packit Service 6754ca
dnl
Packit Service 6754ca
  if test "x$enable_programtest" = "xyes" ; then
Packit Service 6754ca
Packit Service 6754ca
    dnl basic preliminary checks
Packit Service 6754ca
    AC_MSG_CHECKING(for arg_pkg_name)
Packit Service 6754ca
    test_runs="yes"
Packit Service 6754ca
Packit Service 6754ca
    dnl save settings and setup c++ before we start
Packit Service 6754ca
    ac_save_CXXFLAGS="$CXXFLAGS"
Packit Service 6754ca
    ac_save_LDFLAGS="$LDFLAGS"
Packit Service 6754ca
    ac_save_LIBS="$LIBS"
Packit Service 6754ca
    CXXFLAGS="$CXXFLAGS arg_cxxflags"
Packit Service 6754ca
    LDFLAGS="$LDFLAGS arg_ldflags"
Packit Service 6754ca
    LIBS="$LIBS arg_libs"
Packit Service 6754ca
    AC_REQUIRE_CPP()
Packit Service 6754ca
    AC_LANG_PUSH([C++])
Packit Service 6754ca
    rm -f conf.testprogram
Packit Service 6754ca
Packit Service 6754ca
    dnl
Packit Service 6754ca
    dnl first try a complete test - compile, link run
Packit Service 6754ca
    dnl
Packit Service 6754ca
    AC_RUN_IFELSE([AC_LANG_PROGRAM(arg_include_source,
Packit Service 6754ca
                  arg_body_source; [[system("touch conf.testprogram"); ]])],
Packit Service 6754ca
                  test_runs=yes,
Packit Service 6754ca
                  test_runs=no,
Packit Service 6754ca
                  [echo $ac_n "cross compiling; assumed OK... $ac_c"])
Packit Service 6754ca
Packit Service 6754ca
    if test "x$test_runs" = "xyes"  || test -f conf.testprogram ; then
Packit Service 6754ca
       AC_MSG_RESULT(yes)
Packit Service 6754ca
       ifelse([arg_do_yes], , :, [arg_do_yes])     
Packit Service 6754ca
    else
Packit Service 6754ca
       AC_MSG_RESULT(no)
Packit Service 6754ca
       echo "*** Could not run the arg_pkg_name test program, checking why..."
Packit Service 6754ca
Packit Service 6754ca
       test_compiles="yes"
Packit Service 6754ca
       test_links="yes"
Packit Service 6754ca
Packit Service 6754ca
       dnl
Packit Service 6754ca
       dnl if the program did not run, attempt to compile only
Packit Service 6754ca
       dnl
Packit Service 6754ca
Packit Service 6754ca
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM(arg_include_source,
Packit Service 6754ca
                                          arg_body_source ; )],
Packit Service 6754ca
                      test_compiles=yes,
Packit Service 6754ca
                      test_compiles=no)
Packit Service 6754ca
Packit Service 6754ca
       if test "x$test_compiles" = "xno" ; then
Packit Service 6754ca
          echo "*** The test program could not be compiled.  Is arg_pkg_name installed?"
Packit Service 6754ca
          echo "*** Check that the cflags (below) includes the arg_pkg_name include directory"
Packit Service 6754ca
Packit Service 6754ca
       else
Packit Service 6754ca
          dnl
Packit Service 6754ca
          dnl if the program did compile, try linking
Packit Service 6754ca
          dnl
Packit Service 6754ca
          AC_LINK_IFELSE([AC_LANG_PROGRAM(arg_include_source,
Packit Service 6754ca
                                          arg_body_source ; )],
Packit Service 6754ca
                         test_links=yes,
Packit Service 6754ca
                         test_links=no)
Packit Service 6754ca
Packit Service 6754ca
          if test "x$test_links" = "xyes"; then
Packit Service 6754ca
              echo "*** The test program compiled and staticly linked, but did not run. This "
Packit Service 6754ca
              echo "*** usually means that the run-time linker is not finding arg_pkg_name or finding"
Packit Service 6754ca
              echo "*** the wrong version of arg_pkg_name."
Packit Service 6754ca
              echo "***"
Packit Service 6754ca
              echo "*** If the linker is not finding arg_pkg_name, you'll need to set your"
Packit Service 6754ca
              echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
Packit Service 6754ca
              echo "*** to the installed location  Also, make sure you have run ldconfig if that"
Packit Service 6754ca
              echo "*** is required on your system."
Packit Service 6754ca
          else
Packit Service 6754ca
              echo "*** The arg_pkg_name test program could be compiled, but could not be dynamically."
Packit Service 6754ca
              echo "*** or statically linked."
Packit Service 6754ca
              echo "***"
Packit Service 6754ca
              echo "*** Make sure the LDFLAGS points to the location of the arg_pkg_name library."
Packit Service 6754ca
              echo "*** (e.g. -L/usr/local/lib)."
Packit Service 6754ca
              echo "*** If the run-time linker is not finding arg_pkg_name, you'll need to set your"
Packit Service 6754ca
              echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
Packit Service 6754ca
              echo "*** to the installed location  Also, make sure you have run ldconfig if that"
Packit Service 6754ca
              echo "*** is required on your system."
Packit Service 6754ca
          fi
Packit Service 6754ca
       fi
Packit Service 6754ca
Packit Service 6754ca
       dnl
Packit Service 6754ca
       dnl The test failed for some reason. Print out more info, 
Packit Service 6754ca
       dnl unset flags  and signal an error.
Packit Service 6754ca
       dnl
Packit Service 6754ca
       echo "***"
Packit Service 6754ca
       echo "*** Flags used by the test:"
Packit Service 6754ca
       echo "***     cflags: $CXXFLAGS "
Packit Service 6754ca
       echo "***     ldflags: $LDFLAGS"
Packit Service 6754ca
       echo "***"
Packit Service 6754ca
       echo "*** You can also run configure with --disable-arg_disable to skip this test."
Packit Service 6754ca
Packit Service 6754ca
       ifelse([arg_do_no], , :, [arg_do_no])
Packit Service 6754ca
    fi
Packit Service 6754ca
Packit Service 6754ca
    AC_LANG_POP([C++])
Packit Service 6754ca
    CXXFLAGS="$ac_save_CXXFLAGS"
Packit Service 6754ca
    LDFLAGS="$ac_save_LDFLAGS"
Packit Service 6754ca
    LIBS="$ac_save_LIBS"
Packit Service 6754ca
        
Packit Service 6754ca
    dnl
Packit Service 6754ca
    dnl clean up
Packit Service 6754ca
    dnl
Packit Service 6754ca
    rm -f conf.testprogram
Packit Service 6754ca
  fi
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
dnl clean up local "variables"
Packit Service 6754ca
undefine([arg_pkg_name])
Packit Service 6754ca
undefine([arg_disable])
Packit Service 6754ca
undefine([arg_cxxflags])
Packit Service 6754ca
undefine([arg_ldflags])
Packit Service 6754ca
undefine([arg_libs])
Packit Service 6754ca
undefine([arg_include_source])
Packit Service 6754ca
undefine([arg_body_source])
Packit Service 6754ca
undefine([arg_do_yes])
Packit Service 6754ca
undefine([arg_do_no])
Packit Service 6754ca
Packit Service 6754ca
])