xref: /freebsd/contrib/file/configure.ac (revision 5c2bc3db201a4fe8d7911cf816bea104d5dc2138)
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([file],[5.45],[christos@astron.com])
3AM_INIT_AUTOMAKE([subdir-objects foreign])
4m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
5
6AC_CONFIG_HEADERS([config.h])
7AC_CONFIG_MACRO_DIR([m4])
8
9AC_MSG_CHECKING(for builtin ELF support)
10AC_ARG_ENABLE(elf,
11[  --disable-elf            disable builtin ELF support],
12[if test "${enableval}" = yes; then
13  AC_MSG_RESULT(yes)
14  AC_DEFINE([BUILTIN_ELF], 1, [Define if built-in ELF support is used])
15else
16  AC_MSG_RESULT(no)
17fi], [
18  # enable by default
19  AC_MSG_RESULT(yes)
20  AC_DEFINE([BUILTIN_ELF], 1, [Define in built-in ELF support is used])
21])
22
23AC_MSG_CHECKING(for ELF core file support)
24AC_ARG_ENABLE(elf-core,
25[  --disable-elf-core       disable ELF core file support],
26[if test "${enableval}" = yes; then
27  AC_MSG_RESULT(yes)
28  AC_DEFINE([ELFCORE], 1, [Define for ELF core file support])
29else
30  AC_MSG_RESULT(no)
31fi], [
32  # enable by default
33  AC_MSG_RESULT(yes)
34  AC_DEFINE([ELFCORE], 1, [Define for ELF core file support])
35])
36
37AC_MSG_CHECKING(for zlib support)
38AC_ARG_ENABLE([zlib],
39[AS_HELP_STRING([--disable-zlib], [disable zlib compression support @<:@default=auto@:>@])])
40AC_MSG_RESULT($enable_zlib)
41
42AC_MSG_CHECKING(for bzlib support)
43AC_ARG_ENABLE([bzlib],
44[AS_HELP_STRING([--disable-bzlib], [disable bz2lib compression support @<:@default=auto@:>@])])
45AC_MSG_RESULT($enable_bzlib)
46
47AC_MSG_CHECKING(for xzlib support)
48AC_ARG_ENABLE([xzlib],
49[AS_HELP_STRING([--disable-xzlib], [disable liblzma/xz compression support @<:@default=auto@:>@])])
50AC_MSG_RESULT($enable_xzlib)
51
52AC_MSG_CHECKING(for zstdlib support)
53AC_ARG_ENABLE([zstdlib],
54[AS_HELP_STRING([--disable-zstdlib], [disable zstdlib compression support @<:@default=auto@:>@])])
55AC_MSG_RESULT($enable_zstdlib)
56
57AC_MSG_CHECKING(for lzlib support)
58AC_ARG_ENABLE([lzlib],
59[AS_HELP_STRING([--disable-lzlib], [disable liblz (lzip) compression support @<:@default=auto@:>@])])
60AC_MSG_RESULT($enable_lzlib)
61
62AC_MSG_CHECKING(for libseccomp support)
63AC_ARG_ENABLE([libseccomp],
64[AS_HELP_STRING([--disable-libseccomp], [disable libseccomp sandboxing @<:@default=auto@:>@])])
65AC_MSG_RESULT($enable_libseccomp)
66
67AC_MSG_CHECKING(for file formats in man section 5)
68AC_ARG_ENABLE(fsect-man5,
69[  --enable-fsect-man5      enable file formats in man section 5],
70[if test "${enableval}" = yes; then
71  AC_MSG_RESULT(yes)
72  fsect=5
73else
74  AC_MSG_RESULT(no)
75  fsect=4
76fi], [
77  # disable by default
78  AC_MSG_RESULT(no)
79  fsect=4
80])
81
82AC_CANONICAL_HOST
83case "$host_os" in
84   mingw32*)
85      MINGW=1
86      ;;
87   *)
88      MINGW=0
89      ;;
90esac
91AC_SUBST(MINGW)
92AM_CONDITIONAL(MINGW, test "$MINGW" = 1)
93
94AC_SUBST([pkgdatadir], ['$(datadir)/misc'])
95AC_SUBST(fsect)
96AM_CONDITIONAL(FSECT5, test x$fsect = x5)
97
98AC_SUBST(WARNINGS)
99
100dnl Checks for programs.
101AC_PROG_CC
102AC_USE_SYSTEM_EXTENSIONS
103AM_PROG_CC_C_O
104AC_C_BIGENDIAN
105AC_PROG_INSTALL
106AC_PROG_LN_S
107LT_INIT([disable-static pic-only])
108gl_VISIBILITY
109dnl Checks for headers
110AC_HEADER_MAJOR
111AC_HEADER_SYS_WAIT
112AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h byteswap.h)
113AC_CHECK_HEADERS(spawn.h utime.h wchar.h wctype.h)
114AC_CHECK_HEADERS(getopt.h err.h xlocale.h)
115AC_CHECK_HEADERS(sys/bswap.h sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h sys/sysmacros.h sys/ioctl.h)
116if test "$enable_zlib" != "no"; then
117  AC_CHECK_HEADERS(zlib.h)
118fi
119if test "$enable_bzlib" != "no"; then
120  AC_CHECK_HEADERS(bzlib.h)
121fi
122if test "$enable_xzlib" != "no"; then
123  AC_CHECK_HEADERS(lzma.h)
124fi
125if test "$enable_zstdlib" != "no"; then
126  AC_CHECK_HEADERS(zstd.h zstd_errors.h)
127fi
128if test "$enable_lzlib" != "no"; then
129  AC_CHECK_HEADERS(lzlib.h)
130fi
131AC_CHECK_TYPE([sig_t],[AC_DEFINE([HAVE_SIG_T],1,[Have sig_t type])],,[#include <signal.h>])
132
133dnl Checks for typedefs, structures, and compiler characteristics.
134AC_TYPE_OFF_T
135AC_TYPE_SIZE_T
136AC_CHECK_MEMBERS([struct stat.st_rdev])
137
138AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
139AC_STRUCT_TIMEZONE
140AC_STRUCT_TIMEZONE_DAYLIGHT
141AC_SYS_LARGEFILE
142AC_FUNC_FSEEKO
143AC_TYPE_MBSTATE_T
144
145AC_STRUCT_OPTION_GETOPT_H
146AC_TYPE_PID_T
147AC_TYPE_UINT8_T
148AC_TYPE_UINT16_T
149AC_TYPE_UINT32_T
150AC_TYPE_INT32_T
151AC_TYPE_UINT64_T
152AC_TYPE_INT64_T
153AC_TYPE_INTPTR_T
154AC_TYPE_UINTPTR_T
155AC_FUNC_MMAP
156AC_FUNC_FORK
157AC_FUNC_MBRTOWC
158
159AC_MSG_CHECKING(for gcc compiler warnings)
160AC_ARG_ENABLE(warnings,
161[  --disable-warnings	disable compiler warnings],
162[if test "${enableval}" = no -o "$GCC" = no; then
163   AC_MSG_RESULT(no)
164   WARNINGS=
165else
166   AC_MSG_RESULT(yes)
167   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
168       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
169       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
170       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
171fi], [
172if test "$GCC" = yes; then
173   AC_MSG_RESULT(yes)
174   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
175       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
176       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
177       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
178else
179   WARNINGS=
180   AC_MSG_RESULT(no)
181fi])
182
183dnl Checks for functions
184AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem pipe2 posix_spawnp)
185
186dnl Provide implementation of some required functions if necessary
187AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r localtime_r gmtime_r pread strcasestr fmtcheck dprintf)
188
189dnl Checks for libraries
190if test "$enable_zlib" != "no"; then
191  AC_CHECK_LIB(z, gzopen)
192fi
193if test "$enable_bzlib" != "no"; then
194  AC_CHECK_LIB(bz2, BZ2_bzCompressInit)
195fi
196if test "$enable_xzlib" != "no"; then
197  AC_CHECK_LIB(lzma, lzma_stream_decoder)
198fi
199if test "$enable_zstdlib" != "no"; then
200  AC_CHECK_LIB(zstd, ZSTD_createDStream)
201fi
202if test "$enable_lzlib" != "no"; then
203  AC_CHECK_LIB(lz, LZ_decompress_open)
204fi
205if test "$enable_libseccomp" != "no"; then
206    AC_CHECK_LIB(seccomp, seccomp_init)
207fi
208if test "$MINGW" = 1; then
209  AC_CHECK_LIB(gnurx,regexec,,AC_MSG_ERROR([libgnurx is required to build file(1) with MinGW]))
210fi
211
212dnl See if we are cross-compiling
213AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes)
214
215dnl Final sanity checks
216if test "$enable_zlib" = "yes"; then
217  if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" != "yesyes"; then
218    AC_MSG_ERROR([zlib support requested but not found])
219  fi
220fi
221if  test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" = "yesyes"; then
222  AC_DEFINE([ZLIBSUPPORT], 1, [Enable zlib compression support])
223fi
224if test "$enable_bzlib" = "yes"; then
225  if test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" != "yesyes"; then
226    AC_MSG_ERROR([bzlib support requested but not found])
227  fi
228fi
229if  test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" = "yesyes"; then
230  AC_DEFINE([BZLIBSUPPORT], 1, [Enable bzlib compression support])
231fi
232if test "$enable_xzlib" = "yes"; then
233  if test "$ac_cv_header_lzma_h$ac_cv_lib_lzma_lzma_stream_decoder" != "yesyes"; then
234    AC_MSG_ERROR([xzlib support requested but not found])
235  fi
236fi
237if  test "$ac_cv_header_lzma_h$ac_cv_lib_lzma_lzma_stream_decoder" = "yesyes"; then
238  AC_DEFINE([XZLIBSUPPORT], 1, [Enable xzlib compression support])
239fi
240if test "$enable_zstdlib" = "yes"; then
241  if test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" != "yesyes"; then
242    AC_MSG_ERROR([zstdlib support requested but not found])
243  fi
244fi
245if  test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" = "yesyes"; then
246  AC_DEFINE([ZSTDLIBSUPPORT], 1, [Enable zstdlib compression support])
247fi
248if test "$enable_lzlib" = "yes"; then
249  if test "$ac_cv_header_lzlib_h$ac_cv_lib_lz_LZ_decompress_open" != "yesyes"; then
250    AC_MSG_ERROR([lzlib support requested but not found])
251  fi
252fi
253if  test "$ac_cv_header_lzlib_h$ac_cv_lib_lz_LZ_decompress_open" = "yesyes"; then
254  AC_DEFINE([LZLIBSUPPORT], 1, [Enable lzlib compression support])
255fi
256
257AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile libmagic.pc])
258AC_OUTPUT
259