Release 0.90.
[npth.git] / configure.ac
1 # configure.ac                                          -*- Autoconf -*-
2 # Copyright (C) 2011 g10 Code GmbH
3 # This file is part of NPTH.
4 #
5 # NPTH is free software; you can redistribute it and/or modify it
6 # under the terms of either
7 #
8 # - the GNU Lesser General Public License as published by the Free
9 # Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # or
13 #
14 # - the GNU General Public License as published by the Free
15 # Software Foundation; either version 2 of the License, or (at
16 # your option) any later version.
17 #
18 # or both in parallel, as here.
19 #
20 # NPTH is distributed in the hope that it will be useful, but WITHOUT
21 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
23 # Public License for more details.
24 #
25 # You should have received a copy of the GNU Lesser General Public
26 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
27
28 # Process this file with autoconf to produce a configure script.
29
30 AC_PREREQ([2.67])
31 min_automake_version="1.11"
32
33 # Version number: Remember to change it immediately *after* a release.
34 #                 Make sure to pull the correct branch and run
35 #                 "./autogen.sh --force"  before a "make dist".
36 #                 See below for the LT versions.
37 m4_define(my_version, [0.90])
38 m4_define(my_issvn, [no])
39
40 m4_define([git_revision], m4_esyscmd([git branch -v 2>/dev/null \
41           | awk '/^\* / {printf "%s",$3}']))
42 AC_INIT([npth],
43         [my_version[]m4_if(my_issvn,[yes],[-git[]git_revision])],
44         [gnupg-devel@gnupg.org])
45
46 # LT Version numbers, remember to change them just *before* a release.
47 #   (Code changed:                      REVISION++)
48 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
49 #   (Interfaces added:                  AGE++)
50 #   (Interfaces removed/changed:        AGE=0)
51 #
52 LIBNPTH_LT_CURRENT=0
53 LIBNPTH_LT_AGE=0
54 LIBNPTH_LT_REVISION=1
55
56 # If the API is changed in an incompatible way: increment the next counter.
57 NPTH_CONFIG_API_VERSION=1
58 ##############################################
59
60 m4_define([git_brevis],m4_esyscmd(printf "%u" 0x[]m4_substr(git_revision,0,4)))
61 BUILD_REVISION=m4_if(git_revision,[],[svn_revision],[git_brevis])
62 PACKAGE=$PACKAGE_NAME
63 VERSION=$PACKAGE_VERSION
64
65 AC_CONFIG_SRCDIR([src/npth.c])
66 AC_CONFIG_HEADERS([config.h])
67 AC_CONFIG_MACRO_DIR([m4])
68 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
69 AM_MAINTAINER_MODE
70 AC_CANONICAL_HOST
71
72 # Enable GNU extensions on systems that have them.
73 AC_GNU_SOURCE
74
75 AH_VERBATIM([_REENTRANT],
76 [#ifndef _REENTRANT
77 # define _REENTRANT 1
78 #endif])
79
80 # Checks for programs.
81 AC_PROG_CC
82
83 AC_SUBST(LIBNPTH_LT_CURRENT)
84 AC_SUBST(LIBNPTH_LT_AGE)
85 AC_SUBST(LIBNPTH_LT_REVISION)
86
87 AC_SUBST(PACKAGE)
88 AC_SUBST(VERSION)
89 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
90 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
91
92 #
93 # Generate values for the DLL version info
94 #
95 if test "$have_w32_system" = yes; then
96     BUILD_TIMESTAMP=`date --iso-8601=minutes`
97     changequote(,)dnl
98     BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
99     changequote([,])dnl
100     BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
101 fi
102 AC_SUBST(BUILD_REVISION)
103 AC_SUBST(BUILD_TIMESTAMP)
104 AC_SUBST(BUILD_FILEVERSION)
105
106 run_tests="yes"
107 AC_ARG_ENABLE(tests,
108   AC_HELP_STRING([--disable-tests], [disable tests]),
109          run_tests=$enableval)
110 AM_CONDITIONAL(RUN_TESTS, test "$run_tests" = "yes")
111
112
113 # Don't default to build static libs.
114 LT_PREREQ([2.2.6])
115 LT_INIT([win32-dll disable-static])
116 LT_LANG([Windows Resource])
117
118
119 # For now we hardcode the use of version scripts.  It would be better
120 # to write a test for this or even implement this within libtool.
121 have_ld_version_script=no
122 case "${host}" in
123     *-*-linux*)
124         have_ld_version_script=yes
125         ;;
126     *-*-gnu*)
127         have_ld_version_script=yes
128         ;;
129     *-apple-darwin*)
130         AC_DEFINE(_XOPEN_SOURCE, 500, Activate POSIX interface on MacOS X)
131         ;;
132 esac
133
134 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
135
136 # Set some default values
137 config_libs="-lnpth"
138 have_w32_system=no
139 have_w32ce_system=no
140 have_w64_system=no
141
142 # Define OS macros
143 case "${host}" in
144     x86_64-*mingw32*)
145         have_w64_system=yes
146         ;;
147     *-mingw32ce*)
148         have_w32ce_system=yes
149         ;;
150 esac
151 case "${host}" in
152     *-mingw32ce*|*-mingw32*)
153         have_w32_system=yes
154         ;;
155     *)
156         ;;
157 esac
158
159 if test "$have_w32_system" = yes; then
160    AC_DEFINE(HAVE_W32_SYSTEM,1,
161              [Defined if we run on any kind of W32 API based system])
162    ACSUBST
163 fi
164 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
165
166 if test "$have_w64_system" = yes; then
167    AC_DEFINE(HAVE_W64_SYSTEM,1,
168              [Defined if we run on a 64 bit W32 API based system])
169 fi
170 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
171
172
173 #
174 # Checks for header files.
175 #
176 # fixme: For what do we need the sys/socket test?
177 AC_CHECK_HEADERS([sys/socket.h sys/select.h])
178 INSERT_SYS_SELECT_H=
179 if test x"$ac_cv_header_sys_select_h" = xyes; then
180   INSERT_SYS_SELECT_H="include <sys/select.h>"
181 fi
182 AC_SUBST(INSERT_SYS_SELECT_H)
183
184
185 #
186 # Checks for typedefs, structures, and compiler characteristics.
187 #
188 AC_TYPE_PID_T
189 AC_TYPE_SIZE_T
190 AC_TYPE_SSIZE_T
191
192
193 #
194 # Checks for libraries and functions.
195 #
196 if test "$have_w32_system" = no; then
197   AC_SEARCH_LIBS([pthread_create],[pthread])
198   case "x$ac_cv_search_pthread_create" in
199     xno)
200       have_pthread=no
201       ;;
202     xnone\ required)
203       have_pthread=yes
204       ;;
205     *)
206       have_pthread=yes
207       config_libs="$config_libs $ac_cv_search_pthread_create"
208       ;;
209   esac
210   if test "$have_pthread" != no; then
211     AC_DEFINE(HAVE_PTHREAD,1,[Define if we have pthread.])
212     AC_CHECK_FUNCS([pthread_tryjoin_np pthread_setname_np pthread_getname_np])
213     AC_CHECK_FUNCS([pthread_mutex_timedlock])
214     AC_CHECK_FUNCS([pthread_rwlock_rdlock pthread_rwlock_wrlock])
215     AC_CHECK_FUNCS([pthread_rwlock_timedrdlock pthread_rwlock_timedwrlock])
216     AC_CHECK_FUNCS([pthread_rwlock_tryrdlock pthread_rwlock_trywrlock])
217   fi
218 fi
219
220 NETLIBS=
221 if test "$have_w32_system" = yes; then
222    if test "$have_w32ce_system" = yes; then
223      NETLIBS="-lws2 $NETLIBS"
224    else
225      # FIXME: Check why we need to use ws2_32 and document that.
226      NETLIBS="-lws2_32 $NETLIBS"
227    fi
228 fi
229 AC_SUBST(NETLIBS)
230
231 AC_CHECK_FUNCS([select])
232
233 AC_SEARCH_LIBS([clock_gettime],[rt posix4])
234 if test "x$ac_cv_search_clock_gettime" != no; then
235     AC_DEFINE(HAVE_CLOCK_GETTIME,1,
236               [Define to 1 if you have the `clock_gettime' function.])
237 fi
238
239
240 #
241 # Substitutions to set generated files in a Emacs buffer to read-only.
242 #
243 AC_SUBST(emacs_local_vars_begin, ['Local Variables:'])
244 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
245 AC_SUBST(emacs_local_vars_end, ['End:'])
246
247
248 #
249 # Substitution used for npth-config
250 #
251 NPTH_CONFIG_LIBS="$config_libs"
252 NPTH_CONFIG_CFLAGS=""
253 NPTH_CONFIG_HOST="$host"
254 AC_SUBST(NPTH_CONFIG_API_VERSION)
255 AC_SUBST(NPTH_CONFIG_LIBS)
256 AC_SUBST(NPTH_CONFIG_CFLAGS)
257 AC_SUBST(NPTH_CONFIG_HOST)
258
259 #
260 # Last check.
261 #
262 die=no
263 if test "$have_w32_system" = no; then
264   if test "$have_pthread" = "no"; then
265      die=yes
266      AC_MSG_NOTICE([[
267 ***
268 *** You need Pthread to build this program.
269 *** Normally, this library comes with your system.  On Windows, you can use:
270 ***   http://sourceware.org/pthreads-win32/
271 ***]])
272   fi
273 fi
274
275 if test "$die" = "yes"; then
276     AC_MSG_ERROR([[
277 ***
278 *** Required libraries not found. Please consult the above messages
279 *** and install them before running configure again.
280 ***]])
281 fi
282
283 #
284 # Write output
285 #
286 AC_CONFIG_FILES([Makefile
287 src/npth.h
288 src/Makefile
289 w32/Makefile
290 tests/Makefile])
291 AC_CONFIG_FILES(src/npth-config, chmod +x src/npth-config)
292 AC_CONFIG_FILES(w32/npth-config, chmod +x w32/npth-config)
293 AC_OUTPUT