Add labels for debug menu items.
[familia.git] / m4 / gedcom.m4
1 dnl Autoconf/automake macros for the Gedcom parser library
2 dnl Peter Verthez
3 dnl partly stolen from Manish Singh
4 dnl stolen back from Frank Belew
5 dnl stolen from Manish Singh
6 dnl Shamelessly stolen from Owen Taylor
7 dnl 
8 dnl $Id$
9 dnl $Name$
10
11 dnl AM_PATH_GEDCOM_PARSER([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
12 dnl Test for gedcom-parse, and define GEDCOM_CFLAGS and GEDCOM_LIBS
13 dnl
14 AC_DEFUN(AM_PATH_GEDCOM_PARSER, [
15 AC_ARG_WITH(gedcom-prefix,[  --with-gedcom-prefix=PFX   Prefix where the Gedcom parser library is installed (optional)],
16             gedcom_config_prefix="$withval", gedcom_config_prefix="")
17 AC_ARG_WITH(gedcom-exec-prefix,[  --with-gedcom-exec-prefix=PFX Exec prefix where the Gedcom parser library is installed (optional)],
18             gedcom_config_exec_prefix="$withval", gedcom_config_exec_prefix="")
19 AC_ARG_ENABLE(gedcomtest, [  --disable-gedcomtest       Do not try to compile and run a test program with the Gedcom parser library],
20                     , enable_gedcomtest=yes)
21
22   for module in . $4
23   do
24       case "$module" in
25          gom) 
26              gedcom_config_args="$gedcom_config_args gom"
27          ;;
28       esac
29   done
30
31   if test x$gedcom_config_exec_prefix != x ; then
32      gedcom_config_args="$gedcom_config_args --exec-prefix=$gedcom_config_exec_prefix"
33      if test x${GEDCOM_CONFIG+set} != xset ; then
34         GEDCOM_CONFIG=$gedcom_config_exec_prefix/bin/gedcom-config
35      fi
36   fi
37   if test x$gedcom_config_prefix != x ; then
38      gedcom_config_args="$gedcom_config_args --prefix=$gedcom_config_prefix"
39      if test x${GEDCOM_CONFIG+set} != xset ; then
40         GEDCOM_CONFIG=$gedcom_config_prefix/bin/gedcom-config
41      fi
42   fi
43
44   AC_PATH_PROG(GEDCOM_CONFIG, gedcom-config, no)
45   min_gedcom_version=ifelse([$1], ,0.20.0,$1)
46   AC_MSG_CHECKING(for Gedcom parser library - version >= $min_gedcom_version)
47   no_gedcom=""
48   if test "$GEDCOM_CONFIG" = "no" ; then
49     no_gedcom=yes
50   else
51     GEDCOM_CFLAGS=`$GEDCOM_CONFIG $gedcom_config_args --cflags`
52     GEDCOM_LIBS=`$GEDCOM_CONFIG $gedcom_config_args --libs`
53     gedcom_config_major_vers=`$GEDCOM_CONFIG $gedcom_config_args --version | \
54            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
55     gedcom_config_minor_vers=`$GEDCOM_CONFIG $gedcom_config_args --version | \
56            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
57     gedcom_config_patch_vers=`$GEDCOM_CONFIG $gedcom_config_args --version | \
58            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
59     if test "x$enable_gedcomtest" = "xyes" ; then
60       ac_save_CFLAGS="$CFLAGS"
61       ac_save_LIBS="$LIBS"
62       CFLAGS="$CFLAGS $GEDCOM_CFLAGS"
63       LIBS="$GEDCOM_LIBS $LIBS"
64 dnl
65 dnl Now check if the installed Gedcom parser is sufficiently new. (Also sanity
66 dnl checks the results of gedcom-config to some extent
67 dnl
68       rm -f conf.gedcomtest
69       AC_TRY_RUN([
70 #include <stdio.h>
71 #include <stdlib.h>
72 #include <string.h>
73 #include "gedcom.h"
74
75 char*
76 my_strdup (char *str)
77 {
78   char *new_str;
79   
80   if (str)
81     {
82       new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
83       strcpy (new_str, str);
84     }
85   else
86     new_str = NULL;
87   
88   return new_str;
89 }
90
91 int 
92 main ()
93 {
94   int major, minor, micro;
95   char *tmp_version;
96
97   system ("touch conf.gedcomtest");
98
99   /* HP/UX 9 (%@#!) writes to sscanf strings */
100   tmp_version = my_strdup("$min_gedcom_version");
101   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
102      printf("%s, bad version string\n", "$min_gedcom_version");
103      exit(1);
104    }
105
106   if (0) {
107   }
108 #ifdef GEDCOM_PARSE_VERSION_PATCH
109   else if ((GEDCOM_PARSE_VERSION_MAJOR != $gedcom_config_major_vers) ||
110            (GEDCOM_PARSE_VERSION_MINOR != $gedcom_config_minor_vers) ||
111            (GEDCOM_PARSE_VERSION_PATCH != $gedcom_config_patch_vers))
112     {
113       printf("\n*** 'gedcom-config --version' returned %d.%d.%d, but gedcom-parse (%d.%d.%d)\n", 
114              $gedcom_config_major_vers, $gedcom_config_minor_vers, $gedcom_config_patch_vers,
115              GEDCOM_PARSE_VERSION_MAJOR, GEDCOM_PARSE_VERSION_MINOR,
116              GEDCOM_PARSE_VERSION_PATCH);
117       printf ("*** was found! If gedcom-config was correct, then it is best to remove the\n");
118       printf ("*** old version of gedcom-parse. You may also be able to fix the error\n");
119       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
120       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
121       printf("*** required on your system.\n");
122       printf("*** If gedcom-config was wrong, set the environment variable GEDCOM_CONFIG\n");
123       printf("*** to point to the correct copy of gedcom-config, and remove the file config.cache\n");
124       printf("*** before re-running configure\n");
125       return 1;
126     }
127
128   else if (gedcom_check_version(major, minor, micro)) {
129     return 0;
130   }
131 #else
132   else if (GEDCOM_PARSE_VERSION >= major * 1000 + minor) {
133     return 0;
134   }
135 #endif
136
137   else
138       {
139         printf("\n*** An old version of gedcom-parse (%d.%d.%d) was found.\n",
140                GEDCOM_PARSE_VERSION_MAJOR, GEDCOM_PARSE_VERSION_MINOR,
141                GEDCOM_PARSE_VERSION_PATCH);
142         printf("*** You need a version of gedcom-parse newer than %d.%d.%d. The latest version\n",
143                major, minor, micro);
144         printf("*** of gedcom-parse is always available from the following location:\n");
145         printf("*** https://sourceforge.net/projects/gedcom-parse\n");
146         printf("***\n");
147         printf("*** If you have already installed a sufficiently new version, this error\n");
148         printf("*** probably means that the wrong copy of the gedcom-config shell script is\n");
149         printf("*** being found. The easiest way to fix this is to remove the old version\n");
150         printf("*** of gedcom-parse, but you can also set the GEDCOM_CONFIG environment to\n");
151         printf("*** point to the correct copy of gedcom-config. (In this case, you will have\n");
152         printf("*** to modify your LD_LIBRARY_PATH environment var., or edit /etc/ld.so.conf\n");
153         printf("*** so that the correct libraries are found at run-time))\n");
154         return 1;
155       }
156 }
157 ],, no_gedcom=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
158        CFLAGS="$ac_save_CFLAGS"
159        LIBS="$ac_save_LIBS"
160      fi
161   fi
162   if test "x$no_gedcom" = x ; then
163      AC_MSG_RESULT(yes)
164      ifelse([$2], , :, [$2])     
165   else
166      AC_MSG_RESULT(no)
167      if test "$GEDCOM_CONFIG" = "no" ; then
168        echo "*** The gedcom-config script installed by gedcom-parse could not be found"
169        echo "*** If gedcom-parse was installed in PREFIX, make sure PREFIX/bin is in"
170        echo "*** your path, or set the GEDCOM_CONFIG environment variable to the"
171        echo "*** full path to gedcom-config."
172        echo "*** It could also be that your version of gedcom-parse is too old."
173        echo "*** You need at least version $min_gedcom_version.  The latest version"
174        echo "*** of gedcom-parse can always be found at this location:"
175        echo "*** https://sourceforge.net/projects/gedcom-parse"
176      else
177        if test -f conf.gedcomtest ; then
178         :
179        else
180           echo "*** Could not run gedcom-parse test program, checking why..."
181           CFLAGS="$CFLAGS $GEDCOM_CFLAGS"
182           LIBS="$LIBS $GEDCOM_LIBS"
183           AC_TRY_LINK([
184 #include <stdio.h>
185 #include "gedcom.h"
186 ],      [ return ((GEDCOM_PARSE_VERSION_MAJOR) || (GEDCOM_PARSE_VERSION_MINOR) || (GEDCOM_PARSE_VERSION_PATCH)); ],
187         [ echo "*** The test program compiled, but did not run. This usually means"
188           echo "*** that the run-time linker is not finding gedcom-parse or finding the wrong"
189           echo "*** version of gedcom-parse. If it is not finding gedcom-parse, you'll need"
190           echo "*** to set your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf"
191           echo "*** to point to the installed location  Also, make sure you have run ldconfig"
192           echo "*** if that is required on your system"
193           echo "***"
194           echo "*** If you have an old version installed, it is best to remove it, although"
195           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
196           echo "***"],
197         [ echo "*** The test program failed to compile or link. See the file config.log for the"
198           echo "*** exact error that occured. This usually means gedcom-parse was incorrectly"
199           echo "*** installed or that you have moved gedcom-parse since it was installed."
200           echo "*** In the latter case, you may want to edit the gedcom-config script: $GEDCOM_CONFIG" ])
201           CFLAGS="$ac_save_CFLAGS"
202           LIBS="$ac_save_LIBS"
203        fi
204      fi
205      GEDCOM_CFLAGS=""
206      GEDCOM_LIBS=""
207      ifelse([$3], , :, [$3])
208   fi
209   AC_SUBST(GEDCOM_CFLAGS)
210   AC_SUBST(GEDCOM_LIBS)
211   rm -f conf.gedcomtest
212 ])