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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
AC_INIT(main.cc)
AM_INIT_AUTOMAKE(geresh, 0.6.3)
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_INSTALL
AC_LANG_CPLUSPLUS
AC_ARG_PROGRAM
debugging_support=no
AC_ARG_ENABLE(debug,
[ --enable-debug Enable debugging support],
[ if test "$enableval" = yes; then
debugging_support=yes
AC_DEFINE(DEBUG)
fi
])
dnl ---- fribidi ----
if test "x$FRIBIDI_CONFIG" = x; then
AC_PATH_PROG(FRIBIDI_CONFIG, fribidi-config)
fi
test "x$FRIBIDI_CONFIG" = x && AC_MSG_ERROR(Can't locate the fribidi-config program)
test ! -x "$FRIBIDI_CONFIG" && AC_MSG_ERROR(Can't execute the program '$FRIBIDI_CONFIG')
FRIBIDI_CXXFLAGS=`$FRIBIDI_CONFIG --cflags`
if test "x$FRIBIDI_CXXFLAGS" = x-I/usr/include; then
AC_CHECK_HEADER(fribidi/fribidi.h, , [CXXFLAGS="$CXXFLAGS $FRIBIDI_CXXFLAGS"])
else
CXXFLAGS="$CXXFLAGS $FRIBIDI_CXXFLAGS"
fi
LDFLAGS="$LDFLAGS `$FRIBIDI_CONFIG --libs`"
AC_CHECK_FUNCS(fribidi_log2vis fribidi_log2vis_get_embedding_levels, ,
[AC_MSG_ERROR(A required FriBiDi function doesn't exist)])
AC_MSG_CHECKING(your FriBiDi library using a short test program)
AC_TRY_RUN(
[#include <stdio.h>
#include <fribidi/fribidi.h>
typedef FriBidiChar unichar;
typedef FriBidiCharType ctype_t;
typedef FriBidiLevel level_t;
typedef FriBidiStrIndex idx_t;
int main()
{
unichar unistr[] = { 0x5D0, 0x5D1, 0x5D2, 'A', 0 }; /* alef, bet, gimel, 'A' */
#define UNISTRLEN 4
level_t levels[UNISTRLEN];
unichar deststr[UNISTRLEN + 1];
ctype_t ctype;
ctype_t base_dir = FRIBIDI_TYPE_RTL;
unichar lparen = '(';
unichar lparen_mirror;
/* make sure all these constants are defined. */
ctype = FRIBIDI_TYPE_LTR | FRIBIDI_TYPE_RTL | FRIBIDI_TYPE_ON | FRIBIDI_TYPE_NSM;
if (sizeof(unichar) != 4) {
printf("\nERROR: FriBiDi doesn't use UCS-4\n");
/* I'm planning support for 16 bit chars someday. */
return 1;
}
ctype = fribidi_get_type(unistr[0]);
if (!FRIBIDI_IS_LETTER(ctype) ||
!FRIBIDI_IS_RTL(ctype) ||
FRIBIDI_IS_SPACE(ctype) ||
FRIBIDI_IS_NUMBER(ctype))
{
printf("\nERROR: Wrong properties for the Hebrew letter Alef\n");
return 1;
}
fribidi_log2vis_get_embedding_levels(unistr, UNISTRLEN, &base_dir, levels);
if (levels[0] != 1 ||
levels[1] != 1 ||
levels[2] != 1 ||
levels[3] != 2)
{
printf("\nERROR: fribidi_log2vis_get_embedding_levels() "
"gives wrong results\n");
return 1;
}
fribidi_log2vis(unistr, UNISTRLEN, &base_dir, deststr, NULL, NULL, NULL);
if (deststr[0] != 'A' ||
deststr[1] != 0x5D2 ||
deststr[2] != 0x5D1 ||
deststr[3] != 0x5D0)
{
printf("\nERROR: fribidi_log2vis() gives wrong results\n");
return 1;
}
if (!fribidi_get_mirror_char(lparen, &lparen_mirror) ||
lparen_mirror != ')')
{
printf("\nERROR: fribidi_get_mirror_char() gives wrong results\n");
return 1;
}
return 0;
}],
[AC_MSG_RESULT(OK)],
[AC_MSG_ERROR(The test program failed; check 'config.log'. You probably have an old version of FriBiDi; please upgrade.)],
[AC_MSG_ERROR(Can't cross-compile this test)])
dnl ---- curses ----
AC_ARG_WITH(curses,
[ --with-curses=DIR Where [n]curses[w] is installed ],
[
case $withval in
no)
AC_MSG_ERROR([I can only use curses, so don't specify --without-curses!]);;
yes) ;;
*)
if test "x$withval" != x/usr; then
LDFLAGS="-L${withval}/lib $LDFLAGS"
CPPFLAGS="$CPPFLAGS -I${withval}/include"
fi;;
esac
])
curses_lib=ncursesw
curses_header=
# First, check for ncursesw
AC_CHECK_LIB(ncursesw, waddnwstr, , [curses_lib=])
if test "x$curses_lib" = xncursesw; then
# look for ncursesw headers
AC_CHECK_HEADERS(ncursesw/ncurses.h, [curses_header="ncursesw/ncurses.h"])
if test "x$curses_header" = x; then
AC_CHECK_HEADERS(ncurses.h, [curses_header="ncurses.h"],
[AC_MSG_ERROR(Can't find ncursesw's header file!)])
fi
# make sure it is indeed the header of the wchar_t version.
AC_TRY_LINK([#define _XOPEN_SOURCE_EXTENDED 1
#include <$curses_header>],
[
wchar_t ch;
waddnwstr((WINDOW*)0, &ch, 1);
], ,
[AC_MSG_ERROR(I can't find ncursesw's header file! please check config.log)])
AC_DEFINE(HAVE_WIDE_CURSES)
else
curses_lib=ncurses
AC_CHECK_HEADERS(curses.h ncurses.h)
AC_CHECK_LIB(ncurses, initscr, , [curses_lib=])
if test "x$curses_lib" = x; then
curses_lib=curses
AC_CHECK_LIB(curses, initscr, , [curses_lib=])
fi
if test "x$curses_lib" = x; then
AC_MSG_ERROR(No curses/ncurses was found)
fi
fi
# test for the existance of particular curses functions
AC_CHECK_FUNCS(use_default_colors start_color curs_set)
if test "$ac_cv_func_start_color" = yes; then
AC_DEFINE(HAVE_COLOR, 1)
fi
dnl ---- gettext ----
# rudimentary gettext check, till I utilize automake's gettext support
AC_CHECK_HEADERS(libintl.h, [AC_CHECK_FUNCS(gettext, [AC_DEFINE(USE_GETTEXT)])])
# locale support
AC_CHECK_HEADERS(locale.h)
AC_CHECK_FUNCS(setlocale)
AC_MSG_CHECKING(for nl_langinfo and CODESET)
AC_TRY_LINK([#include <langinfo.h>],
[char* s = nl_langinfo(CODESET);],
[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_LANGINFO_CODESET)
],
[AC_MSG_RESULT(no)])
dnl ---- iconv ----
AC_ARG_WITH(iconv,
[ --with-iconv=DIR Where iconv is installed ],
[
case $withval in
no) skip_iconv=yes ;;
yes) ;;
*)
if test "x$withval" != x/usr; then
LDFLAGS="-L${withval}/lib $LDFLAGS"
CPPFLAGS="$CPPFLAGS -I${withval}/include"
fi;;
esac
])
use_iconv=no
default_encoding=ISO-8859-8
if test "x$skip_iconv" != xyes; then
AC_CHECK_HEADERS(iconv.h,
[
AC_C_BIGENDIAN
case $ac_cv_c_bigendian in
yes) internal_encoding=UCS-4BE ;;
no) internal_encoding=UCS-4LE ;;
*) AC_MSG_ERROR(Can't determine machine endianess)
esac
AC_CHECK_LIB(iconv, iconv_open)
for encoding in UTF-8 ISO-8859-8 CP1255; do
tr_encoding=`echo $encoding | tr - _`
AC_MSG_CHECKING(whether iconv supports the $encoding encoding)
AC_TRY_RUN([#include <iconv.h>
int main()
{
iconv_t cd = iconv_open("$internal_encoding", "$encoding");
return (cd == (iconv_t)-1);
}],
[
AC_MSG_RESULT(yes)
eval "have_encoding_${tr_encoding}=yes"
],
[
AC_MSG_RESULT(no)
eval "have_encoding_${tr_encoding}=no"
],
[AC_MSG_ERROR(Can't cross-compile this test)]
)
done
if test "$have_encoding_UTF_8" = yes -a "$have_encoding_ISO_8859_8" = yes; then
use_iconv=yes
if test "$have_encoding_CP1255" = yes; then
default_encoding=CP1255
else
default_encoding=ISO-8859-8
fi
AC_MSG_CHECKING(whether your iconv() needs const)
iconv_const=
AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],
[iconv((iconv_t)-1,(const char **)NULL,NULL,NULL,NULL);],
AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],
[iconv((iconv_t)-1,(char **)NULL,NULL,NULL,NULL);],
,
iconv_const=const
)
)
AC_MSG_RESULT($iconv_const)
AC_DEFINE(USE_ICONV)
AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const)
AC_DEFINE_UNQUOTED(INTERNAL_ENCODING, "$internal_encoding")
fi
])
fi
AC_DEFINE_UNQUOTED(DEFAULT_FILE_ENCODING, "$default_encoding")
AC_CHECK_FUNCS(wctob btowc)
dnl ---- misc ----
AC_CHECK_FUNCS(getopt_long)
AC_HEADER_DIRENT
dnl AC_CHEK_HEADERS(fcntl.h unistd.h)
AC_CHECK_FUNCS(strerror strstr strtol vprintf, ,
AC_MSG_ERROR([A required function does not exist]))
AC_CHECK_FUNCS(vsnprintf vasprintf)
AC_TYPE_MODE_T
dnl AC_TYPE_SIGNAL - fails on some systems, so:
AC_DEFINE(RETSIGTYPE, void)
dnl ---- print out the results ----
cat <<MSG
Results:
--------
curses library: $curses_lib
use iconv: $use_iconv
default file encoding: $default_encoding
(debugging support: $debugging_support)
MSG
if ! test "$curses_lib" = ncursesw; then
cat <<MSG
WARNING: you're using $curses_lib, not ncursesw, so you won't be able to use
$PACKAGE in the UTF-8 locale.
MSG
fi
AC_OUTPUT(Makefile pgeresh, [chmod +x pgeresh])
|