renamed the package to libgedcom-dev
[gedcom-parse.git] / acinclude.m4
1 dnl $Id$
2 dnl $Name$
3
4 dnl Own functions
5 dnl gedcom_GLIBC_ICONV()
6 dnl Checks whether iconv is coming from glibc, defines USE_GLIBC_ICONV if so
7 dnl The variable $is_glibc_iconv contains yes or no
8 AC_DEFUN(gedcom_GLIBC22_ICONV, [
9   AC_CACHE_CHECK(for the GNU C Library 2.2 iconv implementation, is_glibc22_iconv, [
10     AC_EGREP_CPP(yes,
11     [
12 #include <iconv.h>
13 #ifdef __GLIBC__
14  #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || (__GLIBC__ > 2)
15 yes
16  #endif
17 #endif
18     ], is_glibc22_iconv=yes, is_glibc22_iconv=no)
19   ])
20   if test "$is_glibc22_iconv" = yes; then
21     AC_DEFINE(USE_GLIBC_ICONV,1,
22       [Define if the GNU implementation of iconv in glibc is used])
23   fi
24 ])
25
26 dnl gedcom_ICONV_HAS_CONV()
27 dnl Checks whether iconv has support to convert $1 to $2
28 dnl The variable $iconv_has_conv contains yes or no afterwards
29 dnl (overwritten on subsequent calls)
30 AC_DEFUN(gedcom_ICONV_HAS_CONV, [
31   my_save_LIBS="$LIBS"
32   LIBS="$LIBS $LIBICONV"
33   AC_TRY_RUN([
34 #include <iconv.h>
35 int main() {
36   iconv_t cd = iconv_open("$2","$1");
37   return (cd == (iconv_t)-1);
38 }
39     ],
40     iconv_has_conv=yes,
41     iconv_has_conv=no,
42     iconv_has_conv=no)
43     LIBS="$my_save_LIBS"
44   ])
45 ])
46
47 dnl gedcom_SANE_ICONV()
48 dnl Checks whether the iconv implementation has the basic functionality
49 dnl that we need
50 dnl The variable $is_iconv_sane contains yes or no
51 AC_DEFUN(gedcom_SANE_ICONV, [
52   AC_CACHE_CHECK(whether iconv has the needed functionality, is_iconv_sane, [
53     is_iconv_sane=yes
54     gedcom_ICONV_HAS_CONV(ASCII, UTF-8)
55     if test "$iconv_has_conv" = "no"; then
56       is_iconv_sane=no
57     else
58       gedcom_ICONV_HAS_CONV(UCS-2LE, UTF-8)
59       if test "$iconv_has_conv" = "no"; then
60         is_iconv_sane=no
61       else
62         gedcom_ICONV_HAS_CONV(UCS-2BE, UTF-8)
63         if test "$iconv_has_conv" = "no"; then
64           is_iconv_sane=no
65         fi
66       fi
67     fi
68   ])
69 ])
70
71 dnl gedcom_LIBICONV_HAS_ANSEL()
72 dnl Checks whether libiconv has ANSEL support
73 dnl The variable $is_ansel_supported contains yes or no
74 AC_DEFUN(gedcom_LIBICONV_HAS_ANSEL, [
75   AC_CACHE_CHECK(for ANSEL support in libiconv, is_ansel_supported, [
76     is_ansel_supported=no
77     gedcom_ICONV_HAS_CONV(ANSEL, UTF-8)
78     if test "$iconv_has_conv" = yes; then
79       is_ansel_supported=yes
80     fi
81   ])
82 ])
83
84 dnl gedcom_SYS_NEWLINE()
85 dnl Checks how newline is written on the system
86 dnl SYS_NEWLINE is set to one of the following:
87 dnl END_CR, END_LF, END_CR_LF, END_LF_CR
88 AC_DEFUN(gedcom_SYS_NEWLINE, [
89   AC_CACHE_CHECK(how to represent newline, ac_cv_system_newline, [
90     echo > newlinetest
91     AC_TRY_RUN([
92 #include <sys/types.h>
93 #include <sys/stat.h>
94 #include <fcntl.h>
95 #include <stdio.h>
96 int main() {
97   char buffer[11];
98   int i, fd;
99   FILE* f;
100   for (i=0; i<10; i++) { buffer[i] = '\0'; }
101   fd = open("newlinetest", O_RDONLY);
102   if (fd == -1) return 1;
103   read(fd, buffer, 10);
104   close(fd);
105   f = fopen("newlinetest", "w");
106   if (!f) return 1;
107   i = 0;
108   while (buffer[i] != '\0') { fprintf(f, "%02x", buffer[i++]); }
109   fclose(f);
110   return 0;
111 }
112     ],
113     [system_newline_output=`cat newlinetest`
114      case "$system_newline_output" in
115        0a0d) ac_cv_system_newline="\"\x0A\x0D\"" ;;
116        0d0a) ac_cv_system_newline="\"\x0D\x0A\"" ;;
117        0a)   ac_cv_system_newline="\"\x0A\"" ;;
118        0d)   ac_cv_system_newline="\"\x0D\"" ;;
119        *)    ac_cv_system_newline="\"\x0A\"" ;;
120      esac],
121     ac_cv_system_newline="\"\x0A\"",
122     ac_cv_system_newline="\"\x0A\"")
123     rm -f newlinetest
124   ])
125   AC_DEFINE_UNQUOTED(SYS_NEWLINE,$ac_cv_system_newline,
126     [The representation of newline in text files in the system])
127 ])