]> git.sur5r.net Git - glabels/blob - glabels1/macros/gnome-print-check.m4
Initial revision
[glabels] / glabels1 / macros / gnome-print-check.m4
1 # Configure paths for GNOME-PRINT
2 # Chris Lahey   99-2-5
3 # stolen from Manish Singh again
4 # stolen back from Frank Belew
5 # stolen from Manish Singh
6 # Shamelessly stolen from Owen Taylor
7
8 dnl AM_PATH_GNOME_PRINT([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
9 dnl Test for GNOME-PRINT, and define GNOME_PRINT_CFLAGS and GNOME_PRINT_LIBS
10 dnl
11 AC_DEFUN(AM_PATH_GNOME_PRINT,
12 [dnl 
13 dnl Get the cflags and libraries from the gnome-config script
14 dnl
15 AC_ARG_WITH(gnome-print-prefix,[  --with-gnome-print-prefix=PFX   Prefix where GNOME-PRINT is installed (optional)],
16             gnome_print_prefix="$withval", gnome_print_prefix="")
17 AC_ARG_WITH(gnome-print-exec-prefix,[  --with-gnome-print-exec-prefix=PFX Exec prefix where GNOME-PRINT is installed (optional)],
18             gnome_print_exec_prefix="$withval", gnome_print_exec_prefix="")
19 AC_ARG_ENABLE(gnome-printtest, [  --disable-gnome-printtest       Do not try to compile and run a test GNOME-PRINT program],
20                     , enable_gnome_printtest=yes)
21
22   if test x$gnome_print_exec_prefix != x ; then
23      gnome_print_args="$gnome_print_args --exec-prefix=$gnome_print_exec_prefix"
24      if test x${GNOME_CONFIG+set} != xset ; then
25         GNOME_CONFIG=$gnome_print_exec_prefix/bin/gnome-config
26      fi
27   fi
28   if test x$gnome_print_prefix != x ; then
29      gnome_print_args="$gnome_print_args --prefix=$gnome_print_prefix"
30      if test x${GNOME_CONFIG+set} != xset ; then
31         GNOME_CONFIG=$gnome_print_prefix/bin/gnome-config
32      fi
33   fi
34
35   AC_PATH_PROG(GNOME_CONFIG, gnome-config, no)
36   min_gnome_print_version=ifelse([$1], ,0.1.0,$1)
37   AC_MSG_CHECKING(for GNOME-PRINT - version >= $min_gnome_print_version)
38   no_gnome_print=""
39   if test "$GNOME_CONFIG" = "no" ; then
40     no_gnome_print=yes
41   else
42     GNOME_PRINT_CFLAGS=`$GNOME_CONFIG $gnome_printconf_args --cflags print`
43     GNOME_PRINT_LIBS=`$GNOME_CONFIG $gnome_printconf_args --libs print`
44
45     gnome_print_major_version=`$GNOME_CONFIG $gnome_print_args --version | \
46            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
47     gnome_print_minor_version=`$GNOME_CONFIG $gnome_print_args --version | \
48            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
49     gnome_print_micro_version=`$GNOME_CONFIG $gnome_print_config_args --version | \
50            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
51     if test "x$enable_gnome_printtest" = "xyes" ; then
52       ac_save_CFLAGS="$CFLAGS"
53       ac_save_LIBS="$LIBS"
54       CFLAGS="$CFLAGS $GNOME_PRINT_CFLAGS"
55       LIBS="$LIBS $GNOME_PRINT_LIBS"
56 dnl
57 dnl Now check if the installed GNOME-PRINT is sufficiently new. (Also sanity
58 dnl checks the results of gnome-config to some extent
59 dnl
60       rm -f conf.gnome_printtest
61       AC_TRY_RUN([
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <libgnomeprint/gnome-print.h>
66
67 static char*
68 my_strdup (char *str)
69 {
70   char *new_str;
71   
72   if (str)
73     {
74       new_str = malloc ((strlen (str) + 1) * sizeof(char));
75       strcpy (new_str, str);
76     }
77   else
78     new_str = NULL;
79   
80   return new_str;
81 }
82
83 int main ()
84 {
85   int major, minor, micro;
86   char *tmp_version;
87
88   system ("touch conf.gnome_printtest");
89
90   /* HP/UX 9 (%@#!) writes to sscanf strings */
91   tmp_version = my_strdup("$min_gnome_print_version");
92   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
93      printf("%s, bad version string\n", "$min_gnome_print_version");
94      exit(1);
95    }
96   return 0;
97 #if 0
98    if (($gnome_print_major_version > major) ||
99       (($gnome_print_major_version == major) && ($gnome_print_minor_version > minor)) ||
100       (($gnome_print_major_version == major) && ($gnome_print_minor_version == minor) && ($gnome_print_micro_version >= micro)))
101     {
102       return 0;
103     }
104   else
105     {
106       printf("\n*** 'gnome-config print --version' returned %d.%d.%d, but the minimum version\n", $gnome_print_major_version, $gnome_print_minor_version, $gnome_print_micro_version);
107       printf("*** of GNOME-PRINT required is %d.%d.%d. If gnome-config is correct, then it is\n", major, minor, micro);
108       printf("*** best to upgrade to the required version.\n");
109       printf("*** If gnome-config was wrong, set the environment variable GNOME_CONFIG\n");
110       printf("*** to point to the correct copy of gnome-config, and remove the file\n");
111       printf("*** config.cache before re-running configure\n");
112       return 1;
113     }
114 #endif
115 }
116
117 ],, no_gnome_print=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
118        CFLAGS="$ac_save_CFLAGS"
119        LIBS="$ac_save_LIBS"
120      fi
121   fi
122   if test "x$no_gnome_print" = x ; then
123      AC_MSG_RESULT(yes)
124      ifelse([$2], , :, [$2])     
125   else
126      AC_MSG_RESULT(no)
127      if test "$GNOME_CONFIG" = "no" ; then
128        echo "*** The gnome-config script installed by GNOME-LIBS could not be found"
129        echo "*** If GNOME-PRINT was installed in PREFIX, make sure PREFIX/bin is in"
130        echo "*** your path, or set the GNOME_CONFIG environment variable to the"
131        echo "*** full path to gnome-config."
132      else
133        if test -f conf.gnome_printtest ; then
134         :
135        else
136           echo "*** Could not run GNOME-PRINT test program, checking why..."
137           CFLAGS="$CFLAGS $GNOME_PRINT_CFLAGS"
138           LIBS="$LIBS $GNOME_PRINT_LIBS"
139           AC_TRY_LINK([
140 #include <stdio.h>
141 #include <libgnomeprint/gnome-print.h>
142 ],      [ return 0; ],
143         [ echo "*** The test program compiled, but did not run. This usually means"
144           echo "*** that the run-time linker is not finding GNOME-PRINT or finding the wrong"
145           echo "*** version of GNOME-PRINT. If it is not finding GNOME-PRINT, you'll need to set your"
146           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
147           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
148           echo "*** is required on your system"
149           echo "***"
150           echo "*** If you have an old version installed, it is best to remove it, although"
151           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
152         [ echo "*** The test program failed to compile or link. See the file config.log for the"
153           echo "*** exact error that occured. This usually means GNOME-PRINT was incorrectly installed"
154           echo "*** or that you have moved GNOME-PRINT since it was installed. In the latter case, you"
155           echo "*** may want to edit the gnome-config script: $GNOME_CONFIG" ])
156           CFLAGS="$ac_save_CFLAGS"
157           LIBS="$ac_save_LIBS"
158        fi
159      fi
160      GNOME_PRINT_CFLAGS=""
161      GNOME_PRINT_LIBS=""
162      ifelse([$3], , :, [$3])
163   fi
164   AC_SUBST(GNOME_PRINT_CFLAGS)
165   AC_SUBST(GNOME_PRINT_LIBS)
166   rm -f conf.gnome_printtest
167 ])
168
169 AC_DEFUN([GNOME_PRINT_CHECK], [
170         AM_PATH_GNOME_PRINT(0.1.0,,[AC_MSG_ERROR(GNOME-PRINT not found)])
171 ])