Adding tests
[mozilla-central.git] / build / autoconf / libIDL.m4
blob3c0979c080ee5c8816e645543a6417645fce6d15
1 # Configure paths for LIBIDL
3 dnl AM_PATH_LIBIDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
4 dnl Test for LIBIDL, and define LIBIDL_CFLAGS and LIBIDL_LIBS
5 dnl
6 AC_DEFUN([AM_PATH_LIBIDL],
7 [dnl 
8 dnl Get the cflags and libraries from the libIDL-config script
9 dnl
10 AC_ARG_WITH(libIDL-prefix,[  --with-libIDL-prefix=PFX
11                           Prefix where libIDL is installed (optional)],
12             libIDL_config_prefix="$withval", libIDL_config_prefix="")
13 AC_ARG_WITH(libIDL-exec-prefix,[  --with-libIDL-exec-prefix=PFX
14                           Exec prefix where libIDL is installed (optional)],
15             libIDL_config_exec_prefix="$withval", libIDL_config_exec_prefix="")
16 AC_ARG_ENABLE(libIDLtest, [  --disable-libIDLtest    Do not try to compile and run a test libIDL program],
17                     , enable_libIDLtest=yes)
19   if test x$libIDL_config_exec_prefix != x ; then
20      libIDL_config_args="$libIDL_config_args --exec-prefix=$libIDL_config_exec_prefix"
21      if test x${LIBIDL_CONFIG+set} != xset ; then
22         LIBIDL_CONFIG=$libIDL_config_exec_prefix/bin/libIDL-config
23      fi
24   fi
25   if test x$libIDL_config_prefix != x ; then
26      libIDL_config_args="$libIDL_config_args --prefix=$libIDL_config_prefix"
27      if test x${LIBIDL_CONFIG+set} != xset ; then
28         LIBIDL_CONFIG=$libIDL_config_prefix/bin/libIDL-config
29      fi
30   fi
32   AM_PATH_GLIB(1.2.0)
34   dnl Force a version check to keep upgraded versions from being overridden by the cached value.
35   unset ac_cv_path_LIBIDL_CONFIG
37   AC_PATH_PROG(LIBIDL_CONFIG, libIDL-config, no)
38   min_libIDL_version=ifelse([$1], ,0.6.0,$1)
39   AC_MSG_CHECKING(for libIDL - version >= $min_libIDL_version)
40   no_libIDL=""
41   if test "$LIBIDL_CONFIG" = "no" ; then
42     no_libIDL=yes
43   else
44     LIBIDL_CFLAGS=`$LIBIDL_CONFIG $libIDL_config_args --cflags`
45     LIBIDL_LIBS=`$LIBIDL_CONFIG $libIDL_config_args --libs`
46     # hack to allow us to keep using libIDL 0.6.3-0.6.7. Anyone may remove
47     # this after we start requiring libIDL 0.6.8 or anything higher
48     LIBIDL_CFLAGS="$GLIB_CFLAGS $LIBIDL_CFLAGS"
49     LIBIDL_LIBS="$GLIB_LIBS $LIBIDL_LIBS"
50     libIDL_config_major_version=`$LIBIDL_CONFIG $libIDL_config_args --version | \
51            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
52     libIDL_config_minor_version=`$LIBIDL_CONFIG $libIDL_config_args --version | \
53            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
54     libIDL_config_micro_version=`$LIBIDL_CONFIG $libIDL_config_args --version | \
55            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
56     if test "x$enable_libIDLtest" = "xyes" ; then
57       ac_save_CFLAGS="$CFLAGS"
58       ac_save_LIBS="$LIBS"
59       CFLAGS="$CFLAGS $LIBIDL_CFLAGS"
60       LIBS="$LIBIDL_LIBS $LIBS"
61 dnl
62 dnl Now check if the installed LIBIDL is sufficiently new.
63 dnl
64       rm -f conf.libIDLtest
65       AC_TRY_RUN([
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <libIDL/IDL.h>
70 int 
71 main ()
73   int major, minor, micro;
74   int libIDL_major_version;
75   int libIDL_minor_version;
76   int libIDL_micro_version;
77   char *tmp_version;
79   system ("touch conf.libIDLtest");
81   /* HP/UX 9 (%@#!) writes to sscanf strings */
82   tmp_version = g_strdup ("$min_libIDL_version");
83   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
84      printf("%s, bad version string\n", "$min_libIDL_version");
85      exit(1);
86   }
87   tmp_version = g_strdup (IDL_get_libver_string ());
88   if (sscanf(tmp_version, "%d.%d.%d",
89              &libIDL_major_version,
90              &libIDL_minor_version,
91              &libIDL_micro_version) != 3) {
92      printf("%s, bad version string\n", tmp_version);
93      exit(1);
94   }
96   if ((libIDL_major_version != $libIDL_config_major_version) ||
97       (libIDL_minor_version != $libIDL_config_minor_version) ||
98       (libIDL_micro_version != $libIDL_config_micro_version))
99     {
100       printf("\n*** 'libIDL-config --version' returned %d.%d.%d, but libIDL (%d.%d.%d)\n", 
101              $libIDL_config_major_version, $libIDL_config_minor_version, $libIDL_config_micro_version,
102              libIDL_major_version, libIDL_minor_version, libIDL_micro_version);
103       printf ("*** was found! If libIDL-config was correct, then it is best\n");
104       printf ("*** to remove the old version of LIBIDL. You may also be able to fix the error\n");
105       printf("*** by modifying your LD_LIBRARY_PATH environment variable, or by editing\n");
106       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
107       printf("*** required on your system.\n");
108       printf("*** If libIDL-config was wrong, set the environment variable LIBIDL_CONFIG\n");
109       printf("*** to point to the correct copy of libIDL-config, and remove the file config.cache\n");
110       printf("*** before re-running configure\n");
111     } 
112   else if ((libIDL_major_version != LIBIDL_MAJOR_VERSION) ||
113            (libIDL_minor_version != LIBIDL_MINOR_VERSION) ||
114            (libIDL_micro_version != LIBIDL_MICRO_VERSION))
115     {
116       printf("\n*** libIDL header files (version %d.%d.%d) do not match\n",
117              LIBIDL_MAJOR_VERSION, LIBIDL_MINOR_VERSION, LIBIDL_MICRO_VERSION);
118       printf("*** library (version %d.%d.%d)\n",
119              libIDL_major_version, libIDL_minor_version, libIDL_micro_version);
120     }
121   else
122     {
123       if ((libIDL_major_version > major) ||
124         ((libIDL_major_version == major) && (libIDL_minor_version > minor)) ||
125         ((libIDL_major_version == major) && (libIDL_minor_version == minor) && (libIDL_micro_version >= micro)))
126       {
127         return 0;
128        }
129      else
130       {
131         printf("\n*** An old version of libIDL (%d.%d.%d) was found.\n",
132                libIDL_major_version, libIDL_minor_version, libIDL_micro_version);
133         printf("*** You need at least libIDL version %d.%d.%d.\n",
134                major, minor, micro);
135         printf("***\n");
136         printf("*** If you have already installed a sufficiently new version, this error\n");
137         printf("*** probably means that the wrong copy of the libIDL-config shell script is\n");
138         printf("*** being found. The easiest way to fix this is to remove the old version\n");
139         printf("*** of libIDL, but you can also set the LIBIDL_CONFIG environment to point to the\n");
140         printf("*** correct copy of libIDL-config. (In this case, you will have to\n");
141         printf("*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf\n");
142         printf("*** so that the correct libraries are found at run-time))\n");
143       }
144     }
145   return 1;
147 ],, no_libIDL=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
148        CFLAGS="$ac_save_CFLAGS"
149        LIBS="$ac_save_LIBS"
150      fi
151   fi
152   if test "x$no_libIDL" = x ; then
153      AC_MSG_RESULT(yes)
154      ifelse([$2], , :, [$2])     
155   else
156      AC_MSG_RESULT(no)
157      if test "$LIBIDL_CONFIG" = "no" ; then
158        echo "*** The libIDL-config script installed by libIDL could not be found"
159        echo "*** If libIDL was installed in PREFIX, make sure PREFIX/bin is in"
160        echo "*** your path, or set the LIBIDL_CONFIG environment variable to the"
161        echo "*** full path to libIDL-config."
162      else
163        if test -f conf.libIDLtest ; then
164         :
165        else
166           echo "*** Could not run libIDL test program, checking why..."
167           CFLAGS="$CFLAGS $LIBIDL_CFLAGS"
168           LIBS="$LIBS $LIBIDL_LIBS"
169           AC_TRY_LINK([
170 #include <stdio.h>
171 #include <stdlib.h>
172 #include <libIDL/IDL.h>
173 ],      [ return IDL_get_libver_string ? 1 : 0; ],
174         [ echo "*** The test program compiled, but did not run. This usually means"
175           echo "*** that the run-time linker is not finding libIDL or finding the wrong"
176           echo "*** version of LIBIDL. If it is not finding libIDL, you'll need to set your"
177           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
178           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
179           echo "*** is required on your system"
180           echo "***"
181           echo "*** If you have an old version installed, it is best to remove it, although"
182           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
183         [ echo "*** The test program failed to compile or link. See the file config.log for the"
184           echo "*** exact error that occured. This usually means libIDL was incorrectly installed"
185           echo "*** or that you have moved libIDL since it was installed. In the latter case, you"
186           echo "*** may want to edit the libIDL-config script: $LIBIDL_CONFIG" ])
187           CFLAGS="$ac_save_CFLAGS"
188           LIBS="$ac_save_LIBS"
189        fi
190      fi
191      LIBIDL_CFLAGS=""
192      LIBIDL_LIBS=""
193      ifelse([$3], , :, [$3])
194   fi
195   AC_SUBST(LIBIDL_CFLAGS)
196   AC_SUBST(LIBIDL_LIBS)
197   rm -f conf.libIDLtest