xref: /freebsd/contrib/file/configure.ac (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([file],[5.46],[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 lrziplib support)
63AC_ARG_ENABLE([lrziplib],
64[AS_HELP_STRING([--disable-lrziplib], [disable liblrzip (lrzip) compression support @<:@default=auto@:>@])])
65AC_MSG_RESULT($enable_lrziplib)
66
67AC_MSG_CHECKING(for libseccomp support)
68AC_ARG_ENABLE([libseccomp],
69[AS_HELP_STRING([--disable-libseccomp], [disable libseccomp sandboxing @<:@default=auto@:>@])])
70AC_MSG_RESULT($enable_libseccomp)
71
72AC_MSG_CHECKING(for file formats in man section 5)
73AC_ARG_ENABLE(fsect-man5,
74[  --enable-fsect-man5      enable file formats in man section 5],
75[if test "${enableval}" = yes; then
76  AC_MSG_RESULT(yes)
77  fsect=5
78else
79  AC_MSG_RESULT(no)
80  fsect=4
81fi], [
82  # disable by default
83  AC_MSG_RESULT(no)
84  fsect=4
85])
86
87AC_CANONICAL_HOST
88case "$host_os" in
89   mingw32*)
90      MINGW=1
91      ;;
92   *)
93      MINGW=0
94      ;;
95esac
96AC_SUBST(MINGW)
97AM_CONDITIONAL(MINGW, test "$MINGW" = 1)
98
99AC_SUBST([pkgdatadir], ['$(datadir)/misc'])
100AC_SUBST(fsect)
101AM_CONDITIONAL(FSECT5, test x$fsect = x5)
102
103AC_SUBST(WARNINGS)
104
105dnl Checks for programs.
106AC_PROG_CC
107AC_USE_SYSTEM_EXTENSIONS
108AM_PROG_CC_C_O
109AC_C_BIGENDIAN
110AC_PROG_INSTALL
111AC_PROG_LN_S
112LT_INIT([disable-static pic-only])
113gl_VISIBILITY
114dnl Checks for headers
115AC_HEADER_MAJOR
116AC_HEADER_SYS_WAIT
117AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h byteswap.h)
118AC_CHECK_HEADERS(spawn.h utime.h wchar.h wctype.h)
119AC_CHECK_HEADERS(getopt.h err.h xlocale.h)
120AC_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)
121if test "$enable_zlib" != "no"; then
122  AC_CHECK_HEADERS(zlib.h)
123fi
124if test "$enable_bzlib" != "no"; then
125  AC_CHECK_HEADERS(bzlib.h)
126fi
127if test "$enable_xzlib" != "no"; then
128  AC_CHECK_HEADERS(lzma.h)
129fi
130if test "$enable_zstdlib" != "no"; then
131  AC_CHECK_HEADERS(zstd.h zstd_errors.h)
132fi
133if test "$enable_lzlib" != "no"; then
134  AC_CHECK_HEADERS(lzlib.h)
135fi
136if test "$enable_lrziplib" != "no"; then
137  AC_CHECK_HEADERS(Lrzip.h)
138fi
139AC_CHECK_TYPE([sig_t],[AC_DEFINE([HAVE_SIG_T],1,[Have sig_t type])],,[#include <signal.h>])
140
141dnl Checks for typedefs, structures, and compiler characteristics.
142AC_TYPE_OFF_T
143AC_TYPE_SIZE_T
144AC_CHECK_MEMBERS([struct stat.st_rdev])
145
146AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
147AC_STRUCT_TIMEZONE
148AC_STRUCT_TIMEZONE_DAYLIGHT
149AC_SYS_LARGEFILE
150AC_FUNC_FSEEKO
151AC_TYPE_MBSTATE_T
152
153AC_STRUCT_OPTION_GETOPT_H
154AC_TYPE_PID_T
155AC_TYPE_UINT8_T
156AC_TYPE_UINT16_T
157AC_TYPE_UINT32_T
158AC_TYPE_INT32_T
159AC_TYPE_UINT64_T
160AC_TYPE_INT64_T
161AC_TYPE_INTPTR_T
162AC_TYPE_UINTPTR_T
163m4_ifdef([AC_SYS_YEAR2038], [AC_SYS_YEAR2038], [
164# GNU libc only allows setting _TIME_BITS when FILE_OFFSET_BITS is also set.
165# GNU libc defines __TIMESIZE on systems where _TIME_BITS can be set.
166AS_IF([test X"$ac_cv_sys_file_offset_bits" = X"64"], [
167    AC_CHECK_DECL(__TIMESIZE, [
168	AC_DEFINE([_TIME_BITS], [64], [Number of bits in a timestamp, on hosts where this is settable.])
169    ], [], [
170AC_INCLUDES_DEFAULT
171#include <time.h>
172	])
173    ])
174])
175AC_FUNC_MMAP
176AC_FUNC_FORK
177AC_FUNC_MBRTOWC
178
179AC_MSG_CHECKING(for gcc compiler warnings)
180AC_ARG_ENABLE(warnings,
181[  --disable-warnings	disable compiler warnings],
182[if test "${enableval}" = no -o "$GCC" = no; then
183   AC_MSG_RESULT(no)
184   WARNINGS=
185else
186   AC_MSG_RESULT(yes)
187   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
188       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
189       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
190       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
191fi], [
192if test "$GCC" = yes; then
193   AC_MSG_RESULT(yes)
194   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
195       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
196       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
197       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
198else
199   WARNINGS=
200   AC_MSG_RESULT(no)
201fi])
202
203dnl Checks for functions
204AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem pipe2 posix_spawnp)
205
206dnl Provide implementation of some required functions if necessary
207AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r localtime_r gmtime_r pread strcasestr fmtcheck dprintf)
208
209dnl Checks for libraries
210if test "$enable_zlib" != "no"; then
211  AC_CHECK_LIB(z, gzopen)
212fi
213if test "$enable_bzlib" != "no"; then
214  AC_CHECK_LIB(bz2, BZ2_bzCompressInit)
215fi
216if test "$enable_xzlib" != "no"; then
217  AC_CHECK_LIB(lzma, lzma_stream_decoder)
218fi
219if test "$enable_zstdlib" != "no"; then
220  AC_CHECK_LIB(zstd, ZSTD_createDStream)
221fi
222if test "$enable_lzlib" != "no"; then
223  AC_CHECK_LIB(lz, LZ_decompress_open)
224fi
225if test "$enable_lrziplib" != "no"; then
226  AC_CHECK_LIB(lrzip, lrzip_new)
227fi
228
229if test "$enable_libseccomp" != "no"; then
230    AC_CHECK_LIB(seccomp, seccomp_init)
231fi
232if test "$MINGW" = 1; then
233  AC_CHECK_LIB(gnurx,regexec,,AC_MSG_ERROR([libgnurx is required to build file(1) with MinGW]))
234fi
235
236dnl See if we are cross-compiling
237AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes)
238
239dnl Final sanity checks
240if test "$enable_zlib" = "yes"; then
241  if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" != "yesyes"; then
242    AC_MSG_ERROR([zlib support requested but not found])
243  fi
244fi
245if  test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" = "yesyes"; then
246  AC_DEFINE([ZLIBSUPPORT], 1, [Enable zlib compression support])
247fi
248if test "$enable_bzlib" = "yes"; then
249  if test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" != "yesyes"; then
250    AC_MSG_ERROR([bzlib support requested but not found])
251  fi
252fi
253if  test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" = "yesyes"; then
254  AC_DEFINE([BZLIBSUPPORT], 1, [Enable bzlib compression support])
255fi
256if test "$enable_xzlib" = "yes"; then
257  if test "$ac_cv_header_lzma_h$ac_cv_lib_lzma_lzma_stream_decoder" != "yesyes"; then
258    AC_MSG_ERROR([xzlib support requested but not found])
259  fi
260fi
261if  test "$ac_cv_header_lzma_h$ac_cv_lib_lzma_lzma_stream_decoder" = "yesyes"; then
262  AC_DEFINE([XZLIBSUPPORT], 1, [Enable xzlib compression support])
263fi
264if test "$enable_zstdlib" = "yes"; then
265  if test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" != "yesyes"; then
266    AC_MSG_ERROR([zstdlib support requested but not found])
267  fi
268fi
269if  test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" = "yesyes"; then
270  AC_DEFINE([ZSTDLIBSUPPORT], 1, [Enable zstdlib compression support])
271fi
272if test "$enable_lzlib" = "yes"; then
273  if test "$ac_cv_header_lzlib_h$ac_cv_lib_lz_LZ_decompress_open" != "yesyes"; then
274    AC_MSG_ERROR([lzlib support requested but not found])
275  fi
276fi
277if  test "$ac_cv_header_lzlib_h$ac_cv_lib_lz_LZ_decompress_open" = "yesyes"; then
278  AC_DEFINE([LZLIBSUPPORT], 1, [Enable lzlib compression support])
279fi
280
281if test "$enable_lrziplib" = "yes"; then
282  if test "$ac_cv_header_Lrzip_h$ac_cv_lib_lrzip_lrzip_new" != "yesyes"; then
283    AC_MSG_ERROR([lrzip support requested but not found])
284  fi
285fi
286if  test "$ac_cv_header_Lrzip_h$ac_cv_lib_lrzip_lrzip_new" = "yesyes"; then
287  AC_DEFINE([LRZIPLIBSUPPORT], 1, [Enable lrziplib compression support])
288fi
289
290AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile libmagic.pc])
291AC_OUTPUT
292