3914d33061e998160086a85e46f968a0c3163a96
[npth.git] / configure.ac
1 # configure.ac                                          -*- Autoconf -*-
2 # Copyright (C) 2011, 2012 g10 Code GmbH
3 #
4 # This file is part of nPth.
5 #
6 # nPth is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as
8 # published by the Free Software Foundation; either version 2.1 of the
9 # License, or (at your option) any later version.
10 #
11 # nPth is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
14 # Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
18
19 # Process this file with autoconf to produce a configure script.
20
21 AC_PREREQ([2.67])
22 min_automake_version="1.14"
23
24 # To build a release you need to create a tag with the version number
25 # (git tag -s npth-n.m) and run "./autogen.sh --force".  Please bump
26 # the version number immediately after the release and do another
27 # commit and push so that the git magic is able to work.
28 # See below for the LT versions.
29 m4_define(my_version, [1.6])
30
31 # Below is m4 magic to extract and compute the git revision number,
32 # the decimalized short revision number, a beta version string and a
33 # flag indicating a development version (my_isgit). The latter works
34 # by requiring the final tag in the repository.
35 m4_define([git_revision],
36           m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r']))
37 m4_define([git_revision_dec],
38           m4_esyscmd_s([echo $((0x$(echo ]git_revision[|head -c 4)))]))
39 m4_define([git_betastring],
40           m4_esyscmd_s([git describe --match 'npth-[0-9].*[0-9]' --long|\
41                         awk -F- '$3!=0{print"-beta"$3}']))
42 m4_define([my_isgit],m4_if(git_betastring,[],[no],[yes]))
43 m4_define([my_full_version],[my_version[]git_betastring])
44
45 AC_INIT([npth],[my_full_version],[gnupg-devel@gnupg.org])
46
47 # LT Version numbers, remember to change them just *before* a release.
48 #   (Code changed:                      REVISION++)
49 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
50 #   (Interfaces added:                  AGE++)
51 #   (Interfaces removed/changed:        AGE=0)
52 #
53 LIBNPTH_LT_CURRENT=1
54 LIBNPTH_LT_AGE=1
55 LIBNPTH_LT_REVISION=1
56
57 # If the API is changed in an incompatible way: increment the next counter.
58 NPTH_CONFIG_API_VERSION=1
59 ##############################################
60
61 PACKAGE=$PACKAGE_NAME
62 VERSION=$PACKAGE_VERSION
63
64 AC_CONFIG_AUX_DIR([build-aux])
65 AC_CONFIG_SRCDIR([src/npth.c])
66 AC_CONFIG_HEADERS([config.h])
67 AC_CONFIG_MACRO_DIR([m4])
68 AM_INIT_AUTOMAKE([serial-tests dist-bzip2 no-dist-gzip])
69 AM_MAINTAINER_MODE
70 AC_CANONICAL_HOST
71 AM_SILENT_RULES
72
73 # Enable GNU extensions on systems that have them.
74 AC_GNU_SOURCE
75
76 AH_VERBATIM([_REENTRANT],
77 [#ifndef _REENTRANT
78 # define _REENTRANT 1
79 #endif])
80
81 # Checks for programs.
82 AC_PROG_CC
83
84 AC_SUBST(LIBNPTH_LT_CURRENT)
85 AC_SUBST(LIBNPTH_LT_AGE)
86 AC_SUBST(LIBNPTH_LT_REVISION)
87
88 AC_SUBST(PACKAGE)
89 AC_SUBST(VERSION)
90 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
91 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
92
93 run_tests="yes"
94 AC_ARG_ENABLE(tests,
95   AC_HELP_STRING([--disable-tests], [disable tests]),
96          run_tests=$enableval)
97 AM_CONDITIONAL(RUN_TESTS, test "$run_tests" = "yes")
98
99
100 # Don't default to build static libs.
101 LT_PREREQ([2.2.6])
102 LT_INIT([win32-dll disable-static])
103 LT_LANG([Windows Resource])
104
105
106 # For now we hardcode the use of version scripts.  It would be better
107 # to write a test for this or even implement this within libtool.
108 have_ld_version_script=no
109 case "${host}" in
110     *-*-linux*)
111         have_ld_version_script=yes
112         ;;
113     *-*-gnu*)
114         have_ld_version_script=yes
115         ;;
116     *-apple-darwin*)
117         AC_SEARCH_LIBS([dispatch_semaphore_create],[dispatch],
118         [AC_DEFINE([HAVE_LIB_DISPATCH],1,[Defined if we have libdispatch])])
119         ;;
120     *-*-aix*)
121         have_fork_unsafe_semaphore=yes
122         ;;
123     *-*-dragonfly*|*-*-freebsd*|*-*-netbsd*|*-*-hpux*)
124         LIBS="-lpthread $LIBS"
125         AC_SEARCH_LIBS([sem_init],[rt])
126         ;;
127 esac
128
129 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
130 if test "$have_fork_unsafe_semaphore" = yes; then
131    AC_DEFINE(HAVE_FORK_UNSAFE_SEMAPHORE, 1, [Defined if we have fork-unsafe semaphore])
132 fi
133
134 # Set some default values
135 config_libs="-lnpth $LIBS"
136 have_w32_system=no
137 have_w32ce_system=no
138 have_w64_system=no
139
140 # Define OS macros
141 case "${host}" in
142     x86_64-*mingw32*)
143         have_w64_system=yes
144         ;;
145     *-mingw32ce*)
146         have_w32ce_system=yes
147         ;;
148 esac
149 case "${host}" in
150     *-mingw32ce*|*-mingw32*)
151         have_w32_system=yes
152         ;;
153     *)
154         ;;
155 esac
156
157 if test "$have_w32_system" = yes; then
158    AC_DEFINE(HAVE_W32_SYSTEM,1,
159              [Defined if we run on any kind of W32 API based system])
160 fi
161 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
162
163 if test "$have_w64_system" = yes; then
164    AC_DEFINE(HAVE_W64_SYSTEM,1,
165              [Defined if we run on a 64 bit W32 API based system])
166 fi
167 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
168
169 #
170 # Generate values for the DLL version info
171 #
172 if test "$have_w32_system" = yes; then
173     BUILD_ISODATE=`date --iso-8601`
174     changequote(,)dnl
175     BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
176     changequote([,])dnl
177     BUILD_FILEVERSION="${BUILD_FILEVERSION}git_revision_dec"
178 fi
179 AC_SUBST(BUILD_ISODATE)
180 AC_SUBST(BUILD_FILEVERSION)
181 AC_ARG_ENABLE([build-timestamp],
182   AC_HELP_STRING([--enable-build-timestamp],
183                  [set an explicit build timestamp for reproducibility.
184                   (default is the current time in ISO-8601 format)]),
185      [if test "$enableval" = "yes"; then
186         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
187       else
188         BUILD_TIMESTAMP="$enableval"
189       fi],
190      [BUILD_TIMESTAMP="<none>"])
191 AC_SUBST(BUILD_TIMESTAMP)
192 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
193                    [The time this package was configured for a build])
194
195
196 #
197 # Checks for header files.
198 #
199 # fixme: For what do we need the sys/socket test?
200 AC_CHECK_HEADERS([sys/socket.h sys/select.h unistd.h sys/time.h time.h \
201                   signal.h])
202 INSERT_SYS_SELECT_H=
203 if test x"$ac_cv_header_sys_select_h" = xyes; then
204   INSERT_SYS_SELECT_H="include <sys/select.h>"
205 fi
206 AC_SUBST(INSERT_SYS_SELECT_H)
207
208 if test x"$ac_cv_header_sys_time_h" = xyes; then
209   INSERT_SYS_TIME_H="include <sys/time.h>"
210 fi
211 AC_SUBST(INSERT_SYS_TIME_H)
212
213 if test x"$ac_cv_header_time_h" = xyes; then
214   INSERT_TIME_H="include <time.h>"
215 fi
216 AC_SUBST(INSERT_TIME_H)
217
218 if test x"$ac_cv_header_signal_h" = xyes; then
219   INSERT_SIGNAL_H="include <signal.h>"
220 fi
221 AC_SUBST(INSERT_SIGNAL_H)
222
223
224 # Some systems lack socklen_t - provide a replacement.
225 gl_TYPE_SOCKLEN_T
226 case "${host}" in
227   *-*-mingw32*)
228     # socklen_t may or may not be defined depending on what headers
229     # are included.  To be safe we use int as this is the actual type.
230     INSERT_SOCKLEN_T="define _npth_socklen_t int"
231     ;;
232   *)
233     if test ".$gl_cv_socklen_t_equiv" = "."; then
234       INSERT_SOCKLEN_T="define _npth_socklen_t socklen_t"
235     else
236       INSERT_SOCKLEN_T="define _npth_socklen_t ${gl_cv_socklen_t_equiv}"
237     fi
238 esac
239 AC_SUBST(INSERT_SOCKLEN_T)
240
241
242 #
243 # Checks for typedefs, structures, and compiler characteristics.
244 #
245 AC_TYPE_PID_T
246 AC_TYPE_SIZE_T
247 AC_TYPE_SSIZE_T
248
249
250 #
251 # Checks for libraries and functions.
252 #
253 #   We test for pthread_detach because glibc 2.22 includes
254 #   pthread_create but not pthread_detach.
255 if test "$have_w32_system" = no; then
256   AC_SEARCH_LIBS([pthread_detach],[pthread])
257   case "x$ac_cv_search_pthread_detach" in
258     xno)
259       have_pthread=no
260       ;;
261     xnone\ required)
262       have_pthread=yes
263       ;;
264     *)
265       have_pthread=yes
266       config_libs="$config_libs $ac_cv_search_pthread_detach"
267       ;;
268   esac
269   if test "$have_pthread" != no; then
270     AC_DEFINE(HAVE_PTHREAD,1,[Define if we have pthread.])
271     AC_CHECK_FUNCS([pthread_tryjoin_np pthread_setname_np pthread_getname_np])
272     AC_CHECK_FUNCS([pthread_mutex_timedlock])
273     AC_CHECK_FUNCS([pthread_rwlock_rdlock pthread_rwlock_wrlock])
274     AC_CHECK_FUNCS([pthread_rwlock_timedrdlock pthread_rwlock_timedwrlock])
275     AC_CHECK_FUNCS([pthread_rwlock_tryrdlock pthread_rwlock_trywrlock])
276     AC_CHECK_FUNCS([pthread_atfork])
277   fi
278 fi
279
280 AC_CHECK_FUNCS([select pselect gettimeofday])
281
282 npth_LIBSOCKET
283 config_libs="$config_libs $LIBSOCKET"
284
285 # Save and restore LIBS so e.g., -lrt, isn't added to it.  Otherwise, *all*
286 # programs in the package would end up linked with that potentially-shared
287 # library, inducing unnecessary run-time overhead.
288 LIB_CLOCK_GETTIME=
289 AC_SUBST([LIB_CLOCK_GETTIME])
290 gl_saved_libs=$LIBS
291 AC_SEARCH_LIBS([clock_gettime], [rt posix4],
292                [if test "$ac_cv_search_clock_gettime" != "none required"; then
293                   LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime
294                   config_libs="$config_libs $LIB_CLOCK_GETTIME"
295                 fi
296                 AC_DEFINE([HAVE_CLOCK_GETTIME],1,
297                   [Define to 1 if you have the `clock_gettime' function.])
298                 ])
299 LIBS=$gl_saved_libs
300
301
302 #
303 # Set NETLIBS
304 #
305 if test "$have_w32ce_system" = yes; then
306    NETLIBS="-lws2 $NETLIBS"
307 elif test "$have_w32_system" = yes; then
308    NETLIBS="-lws2_32 $NETLIBS"
309 fi
310 AC_SUBST(NETLIBS)
311
312
313 #
314 # Substitutions to set generated files in a Emacs buffer to read-only.
315 #
316 AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
317 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
318 AC_SUBST(emacs_local_vars_end, ['End:'])
319
320
321 #
322 # Substitution used for npth-config
323 #
324 NPTH_CONFIG_LIBS="$config_libs"
325 NPTH_CONFIG_CFLAGS=""
326 NPTH_CONFIG_HOST="$host"
327 AC_SUBST(NPTH_CONFIG_API_VERSION)
328 AC_SUBST(NPTH_CONFIG_LIBS)
329 AC_SUBST(NPTH_CONFIG_CFLAGS)
330 AC_SUBST(NPTH_CONFIG_HOST)
331
332 #
333 # Last check.
334 #
335 die=no
336 if test "$have_w32_system" = no; then
337   if test "$have_pthread" = "no"; then
338      die=yes
339      AC_MSG_NOTICE([[
340 ***
341 *** You need Pthread to build this program.
342 *** Normally, this library comes with your system.  On Windows, you can use:
343 ***   http://sourceware.org/pthreads-win32/
344 ***]])
345   fi
346 fi
347
348 if test "$die" = "yes"; then
349     AC_MSG_ERROR([[
350 ***
351 *** Required libraries not found. Please consult the above messages
352 *** and install them before running configure again.
353 ***]])
354 fi
355
356 #
357 # Write output
358 #
359 AC_CONFIG_FILES([Makefile
360 src/npth.h
361 src/Makefile
362 w32/Makefile
363 tests/Makefile])
364 AC_CONFIG_FILES(npth-config, chmod +x npth-config)
365 AC_OUTPUT
366
367 echo "
368         $PACKAGE_NAME-$PACKAGE_VERSION prepared for make
369
370         Revision: git_revision  (git_revision_dec)
371         Platform: $host
372 "