1# libmetalink
2#
3# Copyright (c) 2012 Tatsuhiro Tsujikawa
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22AC_PREREQ(2.61)
23AC_INIT([libmetalink], [0.1.3], [t-tujikawa@users.sourceforge.net])
24
25LT_PREREQ([2.2.6])
26LT_INIT()
27
28dnl See versioning rule:
29dnl  http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
30AC_SUBST(LT_CURRENT, 4)
31AC_SUBST(LT_REVISION, 0)
32AC_SUBST(LT_AGE, 1)
33
34AC_CANONICAL_BUILD
35AC_CANONICAL_HOST
36AC_CANONICAL_TARGET
37
38AM_INIT_AUTOMAKE()
39AC_CONFIG_MACRO_DIR([m4])
40
41# Special host-dependent stuff
42case ${host} in
43    *android*|*mingw*)
44        ac_cv_func_malloc_0_nonnull=yes
45        ac_cv_func_realloc_0_nonnull=yes
46        ;;
47    *-*solaris*)
48        CFLAGS="-std=gnu99 -D_XOPEN_SOURCE=600 $CFLAGS"
49        ;;
50    *)
51        ;;
52esac
53
54# Checks for arguments.
55AC_ARG_WITH([libexpat], [  --with-libexpat            use libexpat library if installed. Default: yes], [with_libexpat=$withval], [with_libexpat=yes])
56AC_ARG_WITH([libxml2], [  --with-libxml2             use libxml2 library if installed. Default: yes], [with_libxml2=$withval], [with_libxml2=yes])
57
58AC_ARG_ENABLE([maintainer-mode],
59    [AS_HELP_STRING([--enable-maintainer-mode],
60                    [Turn on compile time warnings])],
61    [maintainer_mode=$withval], [maintainer_mode=no])
62
63AC_ARG_ENABLE([gcc-visibility],
64    [AS_HELP_STRING([--enable-gcc-visibility],
65                    [Use gcc visibility attribute. This option may be removed in the future release.])],
66    [gcc_visibility=$withval], [gcc_visibility=no])
67
68# Checks for programs
69AC_PROG_CC
70AC_PROG_INSTALL
71
72# Package version
73AC_SUBST([MAJOR_VERSION],
74	 [[`echo $PACKAGE_VERSION | sed 's/\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/'`]])
75AC_SUBST([MINOR_VERSION],
76         [[`echo $PACKAGE_VERSION | sed 's/[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/'`]])
77AC_SUBST([PATCH_VERSION],
78         [[`echo $PACKAGE_VERSION | sed 's/[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'`]])
79AC_SUBST([NUMBER_VERSION], `printf "0x%02x%02x%02x" $MAJOR_VERSION $MINOR_VERSION $PATCH_VERSION`)
80
81# Checks for libraries.
82
83if test "x$with_libexpat" = "xyes"; then
84  PKG_CHECK_MODULES([EXPAT], [expat >= 2.1.0], [have_libexpat=yes], [have_libexpat=no])
85  if test "x$have_libexpat" != "xyes"; then
86    AC_MSG_WARN([$EXPAT_PKG_ERRORS])
87    AM_PATH_LIBEXPAT
88  fi
89fi
90
91if test "x$with_libxml2" = "xyes" && test "x$have_libexpat" != "xyes"; then
92   AM_PATH_XML2([2.6.24], [have_libxml2=yes])
93   if test "x$have_libxml2" = "xyes"; then
94      AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if you have libxml2.])
95   fi
96fi
97
98if test "x$have_libexpat" != "xyes" && test "x$have_libxml2" != "xyes"; then
99    AC_MSG_FAILURE([Neither expat nor libxml2 found. Please install one of \
100them and run configure again.])
101fi
102
103# cunit
104PKG_CHECK_MODULES([CUNIT], [cunit >= 2.1], [have_cunit=yes], [have_cunit=no])
105# If pkg-config does not find cunit, check it using AC_CHECK_LIB.  We
106# do this because Debian (Ubuntu) lacks pkg-config file for cunit.
107if test "x${have_cunit}" = "xno"; then
108  AC_MSG_WARN([${CUNIT_PKG_ERRORS}])
109  AC_CHECK_LIB([cunit], [CU_initialize_registry],
110               [have_cunit=yes], [have_cunit=no])
111  if test "x${have_cunit}" = "xyes"; then
112    CUNIT_LIBS="-lcunit"
113    CUNIT_CFLAGS=""
114    AC_SUBST([CUNIT_LIBS])
115    AC_SUBST([CUNIT_CFLAGS])
116  fi
117fi
118
119AM_CONDITIONAL([ENABLE_LIBEXPAT], [test "x$have_libexpat" = "xyes"])
120AM_CONDITIONAL([ENABLE_LIBXML2], [test "x$have_libxml2" = "xyes"])
121AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ])
122
123# Checks for header files.
124AC_HEADER_STDC
125AC_CHECK_HEADERS([limits.h stdlib.h string.h time64.h alloca.h])
126
127AC_CHECK_HEADER([inttypes.h], [have_inttypes_h=yes], [have_inttypes_h=no])
128
129if test "x$have_inttypes_h" = "xyes"; then
130    AC_DEFINE([HAVE_INTTYPES_H], [1],
131              [Define to 1 if you have <inttypes.h> header file.])
132    CPPFLAGS="-DHAVE_INTTYPES_H ${CPPFLAGS}"
133fi
134
135# Checks for typedefs, structures, and compiler characteristics.
136AC_C_CONST
137AC_TYPE_SIZE_T
138
139# Checks for library functions.
140AC_FUNC_MALLOC
141
142# _mkgmtime is available in Windows, behaves like timegm.
143# _mkgmtime is for mingw. mkgmtime is for NetWare.
144# Newer Android NDKs have timegm64 in the time64.h header.
145AC_CHECK_FUNCS([memset strtol strtoll timegm64 _mkgmtime mkgmtime])
146AC_CHECK_FUNC([timegm], [have_timegm=yes], [have_timegm=no])
147
148if test "x$have_timegm" = "xyes"; then
149    AC_DEFINE([HAVE_TIMEGM], [1],
150              [Define to 1 if you have timegm function.])
151fi
152AM_CONDITIONAL([HAVE_TIMEGM], [ test "x$have_timegm" = "xyes" ])
153
154
155AC_CHECK_FUNC([strptime], [have_strptime=yes], [have_strptime=no])
156
157if test "x$have_strptime" = "xyes"; then
158    AC_DEFINE([HAVE_STRPTIME], [1],
159              [Define to 1 if you have strptime function.])
160fi
161AM_CONDITIONAL([HAVE_STRPTIME], [ test "x$have_strptime" = "xyes" ])
162
163if test "x$maintainer_mode" != "xno"; then
164    CFLAGS="-Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wpointer-arith -Wdeclaration-after-statement -Werror=declaration-after-statement -Wformat -Wformat-security -Werror=format-security -Wimplicit-function-declaration -Werror=implicit-function-declaration $CFLAGS"
165fi
166
167if test "x$gcc_visibility" != "xno"; then
168    CFLAGS="-fvisibility=hidden $CFLAGS"
169    AC_DEFINE([GCC_VISIBILITY], [1], [Define to 1 if you use gcc visibility attribute.])
170fi
171
172AC_CONFIG_HEADERS([config.h])
173AC_CONFIG_FILES([
174	Makefile
175	lib/Makefile
176	lib/libmetalink.pc
177        lib/includes/metalink/metalinkver.h
178	lib/includes/Makefile
179	test/Makefile
180	doc/Makefile
181	doc/examples/Makefile
182	doc/man3/Makefile
183	m4/Makefile
184])
185AC_OUTPUT
186
187AC_MSG_NOTICE([summary of build options:
188
189    Version:        ${VERSION} (${MAJOR_VERSION}:${MINOR_VERSION}:${PATCH_VERSION}), shared $LT_CURRENT:$LT_REVISION:$LT_AGE
190    Host type:      ${host}
191    Install prefix: ${prefix}
192    C compiler:     ${CC}
193    CFLAGS:         ${CFLAGS}
194    LDFLAGS:        ${LDFLAGS}
195    LIBS:           ${LIBS}
196    CPPFLAGS:       ${CPPFLAGS}
197    C preprocessor: ${CPP}
198    Library types:  Shared=${enable_shared}, Static=${enable_static}
199    Libexpat:       ${have_libexpat} ${EXPAT_CFLAGS} ${EXPAT_LIBS}
200    Libxml2:        ${have_libxml2} ${XML_CPPFLAGS} ${XML_LIBS}
201    CUnit:          ${have_cunit} ${CUNIT_CFLAGS} ${CUNIT_LIBS}
202])
203