1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(postal.cpp)
3AC_CONFIG_HEADER(conf.h)
4AC_SUBST(version)
5version="0.73"
6
7AC_ARG_ENABLE(stripping,
8      [  --disable-stripping  disables stripping of installed binaries],
9      STRIPPING=$strippingval, STRIPPING=no)
10AC_SUBST(stripping)
11if [[ ! "$STRIPPING" = "no" ]]; then
12  stripping=""
13else
14  stripping="-s"
15fi
16
17AC_ARG_ENABLE(openssl,
18      [  --disable-openssl  disables openssl support],
19      DISABLEOPENSSL=$opensslval, DISABLEOPENSSL=no)
20AC_ARG_ENABLE(gnutls,
21      [  --disable-gnutls  disables gnutls support],
22      DISABLEGNUTLS=$gnutlsval, DISABLEGNUTLS=no)
23
24dnl Checks for programs.
25AC_LANG_CPLUSPLUS
26AC_PROG_CC
27AC_PROG_CXX
28AC_PROG_CXXCPP
29AC_PROG_INSTALL
30
31dnl Checks for typedefs, structures, and compiler characteristics.
32AC_C_CONST
33AC_TYPE_SIZE_T
34
35AC_SUBST(semun)
36AC_TRY_COMPILE(#include <sys/types.h>
37#include <sys/ipc.h>
38#include <sys/sem.h>
39    , union semun sem; , semun="yes")
40if [[ -n "$semun" ]]; then
41   semun="#define SEMUN_IN_SEM_H"
42fi
43
44AC_SUBST(bool)
45AC_TRY_COMPILE([], [bool var;] , , bool="typedef bool char;")
46AC_SUBST(true_false)
47AC_TRY_COMPILE(, [char c = true; char d = false;
48] , true_false="0", true_false="1")
49AC_SUBST(snprintf)
50AC_TRY_LINK([#include <stdio.h>], char buf[[10]]; snprintf(buf, sizeof(buf), "abc");,,snprintf="no");
51if [[ -n "$snprintf" ]]; then
52   snprintf="#define NO_SNPRINTF"
53fi
54
55AC_SUBST(extra_ldflags)
56extra_ldflags=
57AC_ARG_WITH(extra-libs, [  --with-extra-libs=DIR   adds non standard library paths],
58  use_extra_libs=$withval,
59  use_extra_libs=NONE
60)
61if test -n "$use_extra_libs" && \
62   test "$use_extra_libs" != "NONE"; then
63
64   ac_save_ifs=$IFS
65   IFS=':'
66   for dir in $use_extra_libs; do
67     extra_ldflags="$extra_ldflags -L$dir"
68   done
69   IFS=$ac_save_ifs
70fi
71
72extra_ldflags=`/usr/bin/uname -a | grep -q SunOS && echo -lrt`
73
74dnl Checks for library -l socket.
75AC_CHECK_LIB(socket, bind, extra_ldflags="$extra_ldflags -lsocket -lnsl")
76
77dnl Checks for header files.
78AC_SUBST(gnutls)
79AC_SUBST(openssl)
80AC_SUBST(extra_objs)
81if [[ "$DISABLEGNUTLS" = "no" ]]; then
82  AC_CHECK_HEADER(gnutls/gnutls.h, GNUTLS=yes, GNUTLS=no)
83else
84  GNUTLS=no
85fi
86if [[ "$GNUTLS" = "yes" ]]; then
87  DISABLEOPENSSL=yes
88fi
89if [[ "$DISABLEOPENSSL" = "no" ]]; then
90  AC_CHECK_HEADER(openssl/crypto.h, OPENSSL=yes, OPENSSL=no)
91else
92  OPENSSL=no
93fi
94if [[ "$OPENSSL" = "no" ]]; then
95  extra_objs="md5.o"
96fi
97
98AC_SUBST(linux_pthread)
99AC_TRY_COMPILE([#define _GNU_SOURCE
100#include <pthread.h>
101] , [pthread_mutexattr_t attr;
102    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);]
103  , linux_pthread="yes")
104if [[ -n "$linux_pthread" ]]; then
105   linux_pthread="#define LINUX_PTHREAD"
106fi
107
108LDFLAGS=-lpthread
109AC_TRY_LINK([#include <pthread.h>
110void * thread_func(void * param) { return NULL; }
111] , [pthread_t thread_info;
112     pthread_attr_t attr;
113     pthread_create(&thread_info, &attr, &thread_func, NULL);]
114  , extra_ldflags="$extra_ldflags -lpthread"
115  , extra_ldflags="$extra_ldflags -pthread")
116
117AC_SUBST(crypt_ldflags)
118crypt_ldflags="$extra_ldflags"
119if [[ "$GNUTLS" = "no" ]]; then
120  gnutls=""
121else
122  gnutls="#define USE_GNUTLS"
123  crypt_ldflags="$extra_ldflags -lgnutls -lgcrypt"
124fi
125if [[ "$OPENSSL" = "no" ]]; then
126  openssl=""
127else
128  openssl="#define USE_OPENSSL"
129  crypt_ldflags="$extra_ldflags -lssl -lcrypto"
130fi
131
132AC_SUBST(large_file)
133large_file=""
134
135AC_SUBST(socklen_t)
136AC_TRY_COMPILE([#include <sys/types.h>
137#include <sys/socket.h>
138] , [socklen_t * namelen;], , no_socklen_t="true")
139if [[ -n "$no_socklen_t" ]]; then
140  socklen_t="#define socklen_t int"
141fi
142
143AC_CHECK_HEADERS(vector ext/hash_map)
144
145dnl Checks for library functions.
146
147AC_OUTPUT(Makefile postal.h port.h postal.spec sun/pkginfo)
148