summaryrefslogtreecommitdiff
path: root/libgphoto2_port/gphoto-m4/gp-libltdl.m4
blob: 9680318d825407f5877a6929c191972164e9668c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# gp-libltdl.m4 - check for libltdl (from libtool)             -*- Autoconf -*-
# serial 13
dnl | Increment the above serial number every time you edit this file.
dnl | When it finds multiple m4 files with the same name,
dnl | aclocal will use the one with the highest serial.
dnl
dnl Written by Hans Ulrich Niedermann
dnl LDFLAGS vs LIBS fix by Dan Nicholson
dnl
dnl ####################################################################
dnl GP_LIBLTDL
dnl ####################################################################
dnl
dnl We are using our own libltdl checks instead of AC_WITH_LTDL
dnl because we do not want to ship our own copy of libltdl.
dnl
dnl Look for external libltdl, not shipping internal libltdl.
AC_DEFUN([GP_LIBLTDL], [dnl
AC_ARG_VAR([LTDLINCL], [CFLAGS for compiling with libltdl])
AC_ARG_VAR([LIBLTDL],  [LIBS to add for linking against libltdl])
dnl
have_libltdl=no
AC_MSG_CHECKING([for libltdl])
AS_IF([test "x${LTDLINCL}${LIBLTDL}" != x], [dnl
  AC_MSG_RESULT([variables given explicitly])

  AC_MSG_CHECKING([LTDLINCL (given explicitly)])
  AC_MSG_RESULT([${LTDLINCL}])
  AC_MSG_CHECKING([LIBLTDL (given explictly)])
  AC_MSG_RESULT([${LIBLTDL}])

  GP_LINK_LIBLTDL_IFELSE([dnl
    have_libltdl=yes
  ], [dnl
    GP_MSG_ERROR_LIBLTDL
  ])
], [dnl
  AC_MSG_RESULT([autodetecting])

  AS_VAR_IF([have_libltdl], [no], [dnl Try default location
    LTDLINCL=""
    LIBLTDL="-lltdl"
    AC_MSG_CHECKING([for libltdl at default location])
    GP_LINK_LIBLTDL_IFELSE([
      have_libltdl=yes
    ], [dnl
      AS_UNSET([LTDLINCL])
      AS_UNSET([LIBLTDL])
    ])
    AC_MSG_RESULT([$have_libltdl])
  ])

  dnl FreeBSD packages install to /usr/local
  dnl NetBSD  packages install to /usr/pkg
  dnl MacOSX  brew packages install to `brew --prefix`
  for gp_prefix in /usr/local /usr/pkg `brew --prefix 2>/dev/null`; do
    AS_IF([test -d "$gp_prefix"], [dnl
      AS_VAR_IF([have_libltdl], [no], [dnl
        LTDLINCL="-I${gp_prefix}/include"
        LIBLTDL="-L${gp_prefix}/lib -lltdl"
        AC_MSG_CHECKING([for libltdl at $gp_prefix])
        GP_LINK_LIBLTDL_IFELSE([
          have_libltdl=yes
          AC_MSG_RESULT([$have_libltdl])
          break
        ], [dnl
          AS_UNSET([LTDLINCL])
          AS_UNSET([LIBLTDL])
          AC_MSG_RESULT([$have_libltdl])
        ])
      ])
    ])
  done

  AS_VAR_IF([have_libltdl], [yes], [dnl
    AC_MSG_CHECKING([LTDLINCL (autodetected)])
    AC_MSG_RESULT([${LTDLINCL}])
    AC_MSG_CHECKING([LIBLTDL (autodetected)])
    AC_MSG_RESULT([${LIBLTDL}])
  ], [dnl
    GP_MSG_ERROR_LIBLTDL
  ])
])
])dnl
dnl
dnl
dnl ####################################################################
dnl GP_MSG_ERROR_LIBLTDL
dnl ####################################################################
dnl
dnl Print the error message when libltdl has not been found to work.
dnl
AC_DEFUN([GP_MSG_ERROR_LIBLTDL], [dnl
AC_MSG_ERROR([
${PACKAGE} requires libltdl (a part of libtool)

Please make sure that the proper development package is installed
(may be called libltdl-dev, libtool-ltdl-devel, libltdl, etc.) and if
the autodetection fails, that the LTDLINCL and LIBLTDL variables are
set properly on the configure command line.
])
])dnl
dnl
dnl
dnl ####################################################################
dnl GP_LINK_LIBLTDL_IFELSE
dnl ####################################################################
dnl
dnl Make sure we can actually compile and link against libltdl
dnl
AC_DEFUN([GP_LINK_LIBLTDL_IFELSE], [dnl
AC_LANG_PUSH([C])
saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $LTDLINCL"
LIBS="$LIBS $LIBLTDL"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h> /* for NULL */
#include <ltdl.h>   /* for lt_* */
]], [[
  int ret = lt_dlforeachfile("/usr/lib:/usr/local/lib", NULL, NULL);
  (void) ret;
]])], [$1], [$2])
CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"
AC_LANG_POP([C])
])dnl
dnl
dnl ####################################################################
dnl
dnl Local Variables:
dnl mode: autoconf
dnl End: