1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ([2.68])
5
6# Get version from file VERSION
7m4_define([f2fs_tools_version], m4_esyscmd([sed -n '1p' VERSION | tr -d '\n']))
8m4_define([f2fs_tools_date], m4_esyscmd([sed -n '2p' VERSION | tr -d '\n']))
9m4_define([f2fs_tools_gitdate],
10		m4_esyscmd([git log -1 --pretty=format:%ci 2> /dev/null]))
11
12AC_INIT([F2FS tools], [f2fs_tools_version],
13			[linux-f2fs-devel@lists.sourceforge.net])
14
15AC_DEFINE([F2FS_TOOLS_VERSION], "f2fs_tools_version", [f2fs-tools version])
16AC_DEFINE([F2FS_MAJOR_VERSION], m4_bpatsubst(f2fs_tools_version,
17				[\([0-9]*\)\(\w\|\W\)*], [\1]),
18				[Major version for f2fs-tools])
19AC_DEFINE([F2FS_MINOR_VERSION], m4_bpatsubst(f2fs_tools_version,
20				[\([0-9]*\).\([0-9]*\)\(\w\|\W\)*], [\2]),
21				[Minor version for f2fs-tools])
22
23AS_IF([test -d .git],[
24	AC_DEFINE([F2FS_TOOLS_DATE],
25		"m4_bpatsubst(f2fs_tools_gitdate,
26		[\([0-9-]*\)\(\w\|\W\)*], [\1])",
27		[f2fs-tools date based on Git commits])],[
28	AC_DEFINE([F2FS_TOOLS_DATE],
29		"f2fs_tools_date",
30		[f2fs-tools date based on Source releases])])
31
32AC_CONFIG_SRCDIR([config.h.in])
33AC_CONFIG_HEADER([config.h])
34AC_CONFIG_MACRO_DIR([m4])
35AC_CONFIG_AUX_DIR([build-aux])
36AM_INIT_AUTOMAKE([foreign tar-pax dist-xz])
37
38# Test configure options.
39AC_ARG_WITH([selinux],
40	AS_HELP_STRING([--without-selinux],
41	  [Ignore presence of libselinux and disable selinux support]))
42
43AC_ARG_WITH([blkid],
44	AS_HELP_STRING([--without-blkid],
45	  [Ignore presence of libblkid and disable blkid support]))
46
47# Checks for programs.
48AC_PROG_CC
49AC_PROG_LIBTOOL
50AC_PATH_PROG([LDCONFIG], [ldconfig],
51       [AC_MSG_ERROR([ldconfig not found])],
52       [$PATH:/sbin])
53
54# Checks for libraries.
55AC_CHECK_LIB([lzo2], [main],
56	[AC_SUBST([liblzo2_LIBS], ["-llzo2"])
57		AC_DEFINE([HAVE_LIBLZO2], [1],
58		[Define if you have liblzo2])
59	], [], [])
60
61AC_CHECK_LIB([lz4], [main],
62	[AC_SUBST([liblz4_LIBS], ["-llz4"])
63		AC_DEFINE([HAVE_LIBLZ4], [1],
64		[Define if you have liblz4])
65	], [], [])
66
67PKG_CHECK_MODULES([libuuid], [uuid])
68
69AS_IF([test "x$with_selinux" != "xno"],
70	[PKG_CHECK_MODULES([libselinux], [libselinux],
71	                   [have_selinux=yes], [have_selinux=no])],
72	[have_selinux=no]
73)
74
75AS_IF([test "x$have_selinux" = "xyes"],
76	[AC_DEFINE([HAVE_LIBSELINUX], [1], [Use libselinux])],
77	[AS_IF([test "x$with_selinux" = "xyes"],
78		[AC_MSG_ERROR([selinux support requested but libselinux not found])]
79	)]
80)
81
82AS_IF([test "x$with_blkid" != "xno"],
83	[PKG_CHECK_MODULES([libblkid], [blkid],
84	                   [have_blkid=yes], [have_blkid=no])],
85	[have_blkid=no]
86)
87
88AS_IF([test "x$have_blkid" = "xyes"],
89	[AC_DEFINE([HAVE_LIBBLKID], [1], [Use blkid])],
90	[AS_IF([test "x$with_blkid" = "xyes"],
91		[AC_MSG_ERROR([blkid support requested but libblkid not found])]
92	)]
93)
94
95# Checks for header files.
96AC_CHECK_HEADERS(m4_flatten([
97	attr/xattr.h
98	byteswap.h
99	fcntl.h
100	linux/blkzoned.h
101	linux/falloc.h
102	linux/fs.h
103	linux/hdreg.h
104	linux/limits.h
105	linux/posix_acl.h
106	linux/types.h
107	linux/xattr.h
108	linux/fiemap.h
109	mach/mach_time.h
110	mntent.h
111	scsi/sg.h
112	stdlib.h
113	string.h
114	sys/acl.h
115	sys/ioctl.h
116	sys/syscall.h
117	sys/mount.h
118	sys/sysmacros.h
119	sys/utsname.h
120	sys/xattr.h
121	unistd.h
122]))
123
124# Checks for typedefs, structures, and compiler characteristics.
125AC_C_INLINE
126AC_TYPE_INT32_T
127AC_TYPE_INT8_T
128AC_TYPE_SIZE_T
129
130# Checks for library functions.
131AC_FUNC_GETMNTENT
132AC_CHECK_FUNCS_ONCE([
133	add_key
134	fallocate
135	fsetxattr
136	fstat
137	fstat64
138	getmntent
139	keyctl
140	llseek
141	lseek64
142	memset
143	setmntent
144])
145
146AS_IF([test "$ac_cv_header_byteswap_h" = "yes"],
147      [AC_CHECK_DECLS([bswap_64],,,[#include <byteswap.h>])])
148
149dnl
150dnl Check to see if llseek() is declared in unistd.h.  On some libc's
151dnl it is, and on others it isn't..... Thank you glibc developers....
152dnl
153AC_CHECK_DECL(llseek,[AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
154			[Define to 1 if llseek declared in unistd.h])],,
155			[#include <unistd.h>])
156dnl
157dnl Check to see if lseek64() is declared in unistd.h.  Glibc's header files
158dnl are so convoluted that I can't tell whether it will always be defined,
159dnl and if it isn't defined while lseek64 is defined in the library,
160dnl disaster will strike.
161dnl
162dnl Warning!  Use of --enable-gcc-wall may throw off this test.
163dnl
164dnl
165AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
166		[Define to 1 if lseek64 declared in unistd.h])],,
167		[#define _LARGEFILE_SOURCE
168		#define _LARGEFILE64_SOURCE
169		#include <unistd.h>])
170dnl
171dnl Word sizes...
172dnl
173
174# AC_CANONICAL_HOST is needed to access the 'host_os' variable
175AC_CANONICAL_HOST
176
177build_linux=no
178build_windows=no
179build_mac=no
180
181# Detect the target system
182case "${host_os}" in
183linux*|uclinux*)
184	build_linux=yes
185	;;
186cygwin*|mingw*)
187	build_windows=yes
188	;;
189darwin*)
190	build_mac=yes
191	;;
192*)
193	AC_MSG_ERROR(["OS $host_os is not supported"])
194	;;
195esac
196
197# Pass the conditionals to automake
198AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"])
199AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"])
200AM_CONDITIONAL([OSX], [test "$build_mac" = "yes"])
201
202# Install directories
203#AC_PREFIX_DEFAULT([/usr])
204#AC_SUBST([sbindir], [/sbin])
205#AC_SUBST([sysconfdir], [/etc])
206#AC_SUBST([localstatedir], [/var])
207
208AC_ARG_WITH([root-libdir],
209[  --with-root-libdir=DIR override location for /lib/libf2fs.so],
210root_libdir=$withval,
211root_libdir=NONE)dnl
212
213if test "$root_libdir" = NONE ; then
214   root_libdir="$libdir"
215fi
216AC_SUBST(root_libdir)
217
218AC_CONFIG_FILES([
219	Makefile
220	man/Makefile
221	lib/Makefile
222	mkfs/Makefile
223	fsck/Makefile
224	tools/Makefile
225	tools/sg_write_buffer/Makefile
226	tools/f2fs_io/Makefile
227])
228
229AC_CHECK_MEMBER([struct blk_zone.capacity],
230		[AC_DEFINE(HAVE_BLK_ZONE_REP_V2, [1], [report zones includes zone capacity])],
231		[], [[#include <linux/blkzoned.h>]])
232
233# export library version info for mkfs/libf2fs_format_la
234AC_SUBST(FMT_CURRENT, 7)
235AC_SUBST(FMT_REVISION, 0)
236AC_SUBST(FMT_AGE, 0)
237
238# export library version info for lib/libf2fs_la
239AC_SUBST(LIBF2FS_CURRENT, 8)
240AC_SUBST(LIBF2FS_REVISION, 0)
241AC_SUBST(LIBF2FS_AGE, 0)
242
243AC_OUTPUT
244