OSDN Git Service

Avoid the buffer overflow BUG to occur to read the level0 or level1 header
[lha/lha.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 AC_INIT([LHa for UNIX], 1.14i-ac20081023, arai@users.sourceforge.jp, lha)
3 AC_DEFINE_UNQUOTED(LHA_CONFIGURE_OPTIONS, "$ac_configure_args",
4             [specified options for the configure script.])
5 AC_CANONICAL_HOST
6 AC_CANONICAL_TARGET
7 AM_INIT_AUTOMAKE
8 AM_CONFIG_HEADER(config.h)
9
10 AC_DEFINE_UNQUOTED(PLATFORM, "$ac_cv_host",
11                    [the type of system on which the package will run.])
12
13 # Checks for programs.
14 AC_PROG_CC
15 AC_PROG_GCC_TRADITIONAL
16 AC_PROG_INSTALL
17 AC_PROG_MAKE_SET
18 AC_MINIX
19 AC_SYS_LARGEFILE
20 dnl Workaround for Zsh bug? on Cygwin:
21 dnl
22 dnl  Environment to trouble
23 dnl    Cygwin version 1.1.5.25
24 dnl    Zsh version 4.3.4
25 dnl
26 dnl  Examples:
27 dnl
28 dnl  o One machine(no problem)
29 dnl    $ uname -srvmpio
30 dnl    -> CYGWIN_NT-5.1 1.5.25(0.156/4/2) 2007-12-09 09:47 i686 unknown unknown Cygwin
31 dnl    $ zsh -c 'echo | diff - /dev/null' >/dev/null
32 dnl    -> $? set to 1
33 dnl  o Another machine(problem)
34 dnl    $ uname -srvmpio
35 dnl    -> CYGWIN_NT-5.1 1.5.25(0.156/4/2) 2008-05-26 20:37 i686 unknown unknown Cygwin
36 dnl    zsh -c 'echo | diff - /dev/null' >/dev/null
37 dnl    -> diff: -: Illegal seek
38 dnl    -> $? set to 2
39 dnl
40 dnl  I don't know why this problem happend.
41 dnl
42 # AC_CHECK_PROGS(sh_for_lha_test, [zsh bash ksh pdksh], [sh])
43 AC_CACHE_VAL([lha_cv_prog_sh_for_lha_test],[
44 AC_CHECK_PROG(sh_for_lha_test, [zsh], [zsh])
45
46 if test -n "$sh_for_lha_test"; then
47   $sh_for_lha_test -c 'echo | diff - /dev/null' >/dev/null 2>&1
48   if test $? -eq 2; then
49     sh_for_lha_test=''   # cannot use Zsh
50     $as_unset ac_cv_prog_sh_for_lha_test
51   fi
52 fi
53
54 if test -z "$sh_for_lha_test"; then
55   AC_CHECK_PROGS(sh_for_lha_test, [bash ksh pdksh], [sh])
56 fi
57 ])
58
59 # Checks for libraries.
60 AC_SEARCH_LIBS(opendir, [mingwex])
61 AC_CHECK_LIB(applefile, af_open)
62
63 # Checks for header files.
64 AC_HEADER_DIRENT
65 AC_HEADER_STDC
66 AC_CHECK_HEADERS(fcntl.h limits.h sys/file.h sys/param.h sys/time.h)
67 AC_CHECK_HEADERS(pwd.h grp.h utime.h inttypes.h stdint.h fnmatch.h)
68
69 # Checks for typedefs, structures, and compiler characteristics.
70 AC_C_CONST
71 AC_HEADER_TIME
72 AC_STRUCT_TM
73 AC_STRUCT_TIMEZONE
74
75 AC_CHECK_SIZEOF(long)
76 AC_CHECK_SIZEOF(off_t)
77 AC_CHECK_TYPES([uid_t, gid_t, long long, uint64_t, ssize_t])
78 AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct stat.st_ino],,,
79 [
80 #if HAVE_SYS_TYPES_H
81 # include <sys/types.h>
82 #endif
83 #if HAVE_SYS_STAT_H
84 # include <sys/stat.h>
85 #endif
86 #if TIME_WITH_SYS_TIME
87 # include <sys/time.h>
88 # include <time.h>
89 #else
90 # if HAVE_SYS_TIME_H
91 #  include <sys/time.h>
92 # else
93 #  include <time.h>
94 # endif
95 #endif
96 ])
97
98 # Checks for library functions.
99 AC_TYPE_SIGNAL
100 AC_FUNC_UTIME_NULL
101 AC_FUNC_FNMATCH
102 AC_FUNC_FSEEKO
103 AC_CHECK_FUNCS(strchr strdup memcpy memset memmove strcasecmp)
104 AC_CHECK_FUNCS(mktime timelocal tzset ftime gettimeofday utime)
105 AC_CHECK_FUNCS(ftruncate chsize lchown mkstemp ftello)
106 AC_CHECK_FUNCS(getpwuid getgrgid getpwnam getgrnam)
107 AC_CHECK_FUNCS(iconv basename)
108 AC_REPLACE_FUNCS(vsnprintf fnmatch)
109
110 if test $ac_header_dirent = no; then
111   AC_LIBOBJ(lhdir)
112 fi
113
114 AC_CHECK_DECLS([basename])
115
116 # checking whether 8 bit clean or not
117 AC_CACHE_CHECK([whether strchr()/strrchr() is 8bit clean],
118   [lha_cv_func_strchr_8bit_clean],
119   AC_TRY_RUN([
120 #if STDC_HEADERS
121 # include <string.h>
122 #else
123 # if !HAVE_STRCHR
124 #  define strchr index
125 #  define strrchr rindex
126 # endif
127 char *strchr (), *strrchr ();
128 #endif
129
130 main()
131 {
132   char *s = "\377";
133   if (strchr(s, 0xff) != s) exit(1);
134   if (strchr(s, '\377') != s) exit(1);
135   if (strrchr(s, 0xff) != s) exit(1);
136   if (strrchr(s, '\377') != s) exit(1);
137   exit(0); /* ok */
138 }
139 ], lha_cv_func_strchr_8bit_clean=yes,
140    lha_cv_func_strchr_8bit_clean=no,
141    lha_cv_func_strchr_8bit_clean=no))
142
143 if test x$lha_cv_func_strchr_8bit_clean = xyes; then
144   AC_DEFINE(STRCHR_8BIT_CLEAN, 1,
145             [Define to 1 if strchr()/strrchr() works correctly.])
146 fi
147
148 # checking whether the 2nd argument of gettimeofday() is effective or not.
149 # note that this timezone argument is obsolete.
150 AC_CACHE_CHECK([whether the 2nd argument of gettimeofday() is effective],
151   [lha_cv_func_gettimeofday_2nd_arg],
152   AC_TRY_RUN([
153 #if TIME_WITH_SYS_TIME
154 # include <sys/time.h>
155 # include <time.h>
156 #else
157 # if HAVE_SYS_TIME_H
158 #  include <sys/time.h>
159 # else
160 #  include <time.h>
161 # endif
162 #endif
163
164 main()
165 {
166     struct timeval tv;
167     struct timezone tz;
168
169     tz.tz_minuteswest = -1;
170     if (gettimeofday(&tv, &tz) == -1)
171         exit(1);
172
173     if (tz.tz_minuteswest == -1)
174         exit(1);        /* the timezone information is no given */
175
176     exit(0);
177 }], lha_cv_func_gettimeofday_2nd_arg=yes,
178    lha_cv_func_gettimeofday_2nd_arg=no,
179    lha_cv_func_gettimeofday_2nd_arg=no))
180
181 if test x$lha_cv_func_gettimeofday_2nd_arg = xyes; then
182   AC_DEFINE(GETTIMEOFDAY_HAS_2ND_ARG, 1,
183             [Define to 1 if the 2nd argument of gettimeofday() is effective.])
184 fi
185
186 # support kanji code conversion
187 AC_SUBST(DEF_KCODE)
188 AC_MSG_CHECKING(kanji code conversion on text file)
189 AC_ARG_ENABLE(text-conv,
190   AC_HELP_STRING([--enable-text-conv],
191                  [support text code convert from/to EUC [[default=yes]]]),
192   , enable_text_conv=yes)
193
194 AC_MSG_RESULT($enable_text_conv)
195 if test $enable_text_conv = yes; then
196   DEF_KCODE=-DEUC
197 fi
198
199 # force support -lh7-
200 AC_SUBST(SUPPORT_LZHUFF_METHOD)
201 SUPPORT_LZHUFF_METHOD=-DSUPPORT_LH7
202
203 # whether use the -lh567- method
204 AC_MSG_CHECKING(default archive method)
205 AC_ARG_WITH(default-method,
206   [AC_HELP_STRING([[[[--with-default-method=[567]]]]],
207                  [create the -lh[567]- archive default [default=5]])],
208   [case $withval in
209    [[567]]) ;;
210    *) AC_MSG_ERROR([you should have specified 5, 6 or 7]);;
211    esac],
212   with_default_method=5)
213 AC_MSG_RESULT(-lh$with_default_method-)
214 AC_DEFINE_UNQUOTED(DEFAULT_LZHUFF_METHOD, LZHUFF${with_default_method}_METHOD_NUM, [Define it to 5, 6 or 7 which you want to use -lhX- method, default])
215
216 # decide temporary path names
217 AC_MSG_CHECKING(template of the temporary file)
218 AC_ARG_WITH(tmp-file,
219   AC_HELP_STRING([--with-tmp-file=TEMPLATE],
220                  [temporary file template [[default=/tmp/lhXXXXXX]]]),
221   [case $withval in
222    yes)  with_tmp_file=/tmp/lhXXXXXX ;;
223    no)   ;;
224    esac],
225   with_tmp_file=/tmp/lhXXXXXX)
226
227 AC_MSG_RESULT($with_tmp_file)
228 if test x"$with_tmp_file" != xno; then
229   AC_DEFINE_UNQUOTED(TMP_FILENAME_TEMPLATE, "$with_tmp_file",
230     [temporary file template for mktemp/mkstemp])
231 fi
232
233 # incremental indicator
234 AC_MSG_CHECKING(whether incremental indicator is needed)
235 AC_ARG_ENABLE(indicator,
236   AC_HELP_STRING([--enable-indicator],
237                  [need incremental indicator [[default=yes]]]),
238   ,
239   # default
240   enable_indicator=yes)
241
242 AC_MSG_RESULT($enable_indicator)
243 if test "x$enable_indicator" = xyes; then
244   AC_DEFINE(NEED_INCREMENTAL_INDICATOR, 1,
245             [Define to 1 if you want to use the incremental indicator])
246 fi
247
248 # support multibyte filename
249 AC_MSG_CHECKING(kanji code of filename)
250 AC_ARG_ENABLE(multibyte-filename,
251   AC_HELP_STRING([--enable-multibyte-filename],
252                  [support multibyte filename. specify kanji code (euc, sjis, utf8 or auto) [[default=auto]]]),,
253   # default
254   enable_multibyte_filename=auto)
255
256 case $enable_multibyte_filename in
257 auto|yes)
258   AC_EGREP_CPP(SJIS,[
259 #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__hpux)
260 SJIS
261 #endif], enable_multibyte_filename=CODE_SJIS,
262   AC_EGREP_CPP(UTF8,[
263 #if defined(__APPLE__)  /* for Mac OS X */
264 UTF8
265 #endif], enable_multibyte_filename=CODE_UTF8,
266          enable_multibyte_filename=CODE_EUC));;
267 sjis)    enable_multibyte_filename=CODE_SJIS;;
268 euc)     enable_multibyte_filename=CODE_EUC;;
269 utf8)    enable_multibyte_filename=CODE_UTF8;;
270 no)      ;;
271 *)       AC_MSG_ERROR([you should specify auto, sjis or euc as your system filename code.]);;
272 esac
273
274 AC_MSG_RESULT($enable_multibyte_filename)
275 if test x$enable_multibyte_filename != xno; then
276   AC_DEFINE_UNQUOTED(MULTIBYTE_FILENAME, $enable_multibyte_filename,
277       [Define to CODE_EUC or CODE_SJIS if you want to use multibyte filename])
278
279   case $target_os in
280   darwin*)
281         # for multibyte filename
282         LDFLAGS="$LDFLAGS -framework CoreFoundation"
283         ;;
284   esac
285 fi
286
287 # make user/group name extented header
288 AC_MSG_CHECKING(whether user/group name extended header is needed)
289 AC_ARG_ENABLE(user-name-header,
290   AC_HELP_STRING([--enable-user-name-header],
291                  [make user/group name extended header [[default=no]]]),
292   ,
293   # default
294   enable_user_name_header=no)
295
296 AC_MSG_RESULT($enable_user_name_header)
297 if test "x$enable_user_name_header" = xyes; then
298   AC_DEFINE(INCLUDE_OWNER_NAME_IN_HEADER, 1,
299             [Define to 1 if you want to use the user/group name extened header])
300 fi
301
302 # backup old archive file
303 AC_MSG_CHECKING(whether backup file for old archive is left)
304 AC_ARG_ENABLE(backup-archive,
305   AC_HELP_STRING([--enable-backup-archive],
306                  [backup old archive [[default=no]]]),
307   ,
308   # default
309   enable_backup_archive=no)
310
311 AC_MSG_RESULT($enable_backup_archive)
312 if test "x$enable_backup_archive" = xyes; then
313   AC_DEFINE(BACKUP_OLD_ARCHIVE, 1,
314             [Define to 1 if you want to leave an old archive])
315 fi
316
317 # additional suffixes of archive filename.
318 AC_MSG_CHECKING(additional suffixes of archive filename)
319 AC_ARG_WITH(additional-suffixes,
320   [AC_HELP_STRING([[[--with-additional-suffixes=foo,bar]]],
321                  [additional suffixes of archive filename, default is empty string])],
322   ,
323   with_additional_suffixes="")
324
325 AC_MSG_RESULT($with_additional_suffixes)
326 AC_DEFINE_UNQUOTED(ADDITIONAL_SUFFIXES, "$with_additional_suffixes",
327             [Define to comma separated suffixes list if you wish to regard it as implicit archive suffixes.])
328
329 case $host_os in
330 *msdosdjgpp*)
331 CFLAGS="$CFLAGS -DNOT_COMPATIBLE_MODE"
332 ;;
333 esac
334
335 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile olddoc/Makefile])
336 AC_CONFIG_FILES([tests/Makefile tests/lha-test])
337 AC_OUTPUT