-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.ac
275 lines (230 loc) · 7.97 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
dnl Process this file with autoconf to produce a configure script.
dnl confgure.ac for pwsafe
dnl $Id: configure.ac,v 1.25 2005/09/30 21:06:37 ndade Exp $
AC_PREREQ(2.5)
AC_INIT(pwsafe.cpp)
dnl Every other copy of the package version number gets its value from here
AM_INIT_AUTOMAKE(pwsafe, 0.2.0)
dnl create a config.h file (Automake will add -DHAVE_CONFIG_H)
AM_CONFIG_HEADER(config.h)
dnl --with-openssl-dir=dir
AC_ARG_WITH(openssl-dir, AC_HELP_STRING([--with-openssl-dir=DIR], [indicate where openssl is installed (default=/usr)]),,)
if test "$with_openssl_dir" = no; then
AC_MSG_ERROR(openssl is required is not supported)
fi
if test -n "$with_openssl_dir" && test "$with_openssl_dir" != yes; then
CPPFLAGS="$CPPFLAGS -I${with_openssl_dir}/include"
LDFLAGS="$LDFLAGS -L${with_openssl_dir}/lib"
fi
dnl --with-readline or without
AC_ARG_WITH(readline, AC_HELP_STRING([--with-readline], [use readline for read input (default=yes)]),,with_readline=yes)
if test "$with_readline" != no; then
AC_DEFINE(WITH_READLINE, 1, [Define to 1 to enable use of gnu libreadline for input])
fi
dnl --with-getopt_long or without
dnl note: there is also a test to see if getopt_long exists. both it and this have to be true for it to be use
AC_ARG_WITH(getopt_long, AC_HELP_STRING([--with-getopt_long], [use getopt_long to parse arguments (default=yes if available)]),,with_getopt_long=yes)
dnl --enable-debug
AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [compile in debug support (default=no)]),,)
AC_SUBST(VERSION)
ISODATE=`date +%Y-%m-%d`
AC_SUBST(ISODATE)
AC_CANONICAL_HOST
dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC
AC_PROG_CXX
AC_CHECK_TOOL([STRIP],[strip])
dnl check for or fix up some types and functions
AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_SIZE_T
AC_CHECK_TYPES(long long)
AC_FUNC_MEMCMP
dnl Check for X
AC_PATH_XTRA
dnl if this is OS X then we're going to need -flat_namespace -supress undefined in order to build against the X libraries
dnl and since it doesn't hurt otherwise, always use the option (thanks to Robert)
case $ac_sys_system/$ac_sys_release in
Darwin/*)LDFLAGS="$LDFLAGS -flat_namespace -undefined suppress";;
esac
dnl Checks for libraries.
dnl AM_WITH_REGEX
AC_CHECK_LIB(crypto, SHA1_Init, [], [AC_MSG_ERROR(openssl (libssl) is required)])
if test "$with_readline" != no; then
dnl readline usually needs libncurses, but on some systems (like netbsd) libcurses will do. so pick one and use it
AC_CHECK_LIB(ncurses, initscr,,)
AC_CHECK_LIB(curses, initscr,,)
AC_MSG_CHECKING([if libreadline needs libncurses])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdio.h>
#include <readline/readline.h>
]],[[
char*x=readline("test");
return (x?0:1);
]]
)],
[AC_MSG_RESULT(no)
dnl maybe it needs libcurses
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdio.h>
#include <readline/readline.h>
]],[[
char*x=readline("test");
return (x?0:1);
]]
)],
[AC_MSG_RESULT(no)],
[CPPFLAGS="$CPPFLAGS -lcurses"
AC_MSG_RESULT(yes)])],
[CPPFLAGS="$CPPFLAGS -lncurses"
AC_MSG_RESULT(yes)])
AC_CHECK_LIB(readline, readline, [], [AC_MSG_ERROR(libreadline can't be found)])
fi
dnl check for the X libraries
if test "$have_x" = yes; then
CPPFLAGS="$CPPFLAGS $X_CFLAGS $X_LIBS"
AC_CHECK_LIB(X11, XOpenDisplay,, $X_EXTRA_LIBS)
AC_CHECK_LIB(Xmu, XmuInternAtom,, $X_EXTRA_LIBS)
fi
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h sys/param.h sys/time.h time.h sys/types.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h fcntl.h signal.h sys/select.h sys/resource.h sys/socket.h sys/un.h sys/mman.h)
AC_CHECK_HEADERS(stdint.h errno.h termios.h getopt.h)
AC_CHECK_HEADERS(openssl/sha.h openssl/blowfish.h openssl/rand.h, [], [AC_MSG_ERROR(openssl headers (libssl-dev) are required)])
if test "$with_readline" != no; then
AC_CHECK_HEADERS(curses.h, [], [AC_MSG_ERROR(curses.h (lib[n]curses-dev) is required by readline)])
AC_CHECK_HEADERS(readline/readline.h, [], [AC_MSG_ERROR(readline/readline.h (libreadline-dev) can't be found)])
fi
AC_CHECK_HEADERS(netinet/in.h, [], [AC_MSG_ERROR(netinet/in.h is required)])
if test "$have_x" = yes; then
AC_CHECK_HEADERS(X11/Xlib.h X11/Xatom.h X11/Xmu/Atoms.h)
fi
AC_HEADER_MAJOR
AC_STRUCT_TM
dnl Checks for typedefs, structures, and compiler characteristics.
dnl MacOSX, for example, does not define socklen_t
AC_CHECK_TYPE(socklen_t,[AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define to 1 if the type socklen_t exists])],,[
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
])
dnl Checks for library functions.
AM_SYS_POSIX_TERMIOS
if test "$am_cv_sys_posix_termios" != yes -a "$ac_cv_sys_posix_termios" != yes; then
AC_MSG_ERROR("POSIX termios operations are required")
fi
if test "$with_getopt_long" != no; then
AC_CHECK_FUNC(getopt_long, [AC_DEFINE(HAS_GETOPT_LONG, 1, [Define to 1 if getopt_long is supported])], [])
fi
AC_CHECK_FUNC(tcsetattr, [], [AC_MSG_ERROR(tcsetattr() is needed)])
AC_CHECK_FUNC(setrlimit, [AC_DEFINE(HAVE_SETRLIMIT, 1, [Define to 1 if setrlimit is supported])], [])
if test "$with_readline" != no; then
AC_CHECK_FUNC(readline, [], [AC_MSG_ERROR(readline() is needed)])
fi
if test "$with_readline" != no; then
dnl older readline.h's declared readline() without any arguments and outside of 'extern "C"', which freaks out C++
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([if readline.h needs extern "C"])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdio.h>
#include <readline/readline.h>
]],[[
char*x=readline("test");
return (x?0:1);
]]
)],
[AC_MSG_RESULT(no)],
[AC_DEFINE(READLINE_H_NEEDS_EXTERN_C, 1, [Define to 1 if readline/readline.h needs extern "C"])
AC_MSG_RESULT(yes)])
AC_LANG_POP(C++)
fi
if test "$with_readline" != no; then
dnl slightly newer but still broken readline.h's use extern "C" but don't declare arguments as const
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([if readline.h lacks 'const' in its declarations])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdio.h>
#if READLINE_H_NEEDS_EXTERN_C
extern "C" {
#endif
#include <readline/readline.h>
#if READLINE_H_NEEDS_EXTERN_C
} // terminate extern "C"
#endif
]],[[
const char* prompt = "abc";
char*x = readline(prompt);
]]
)],
[AC_MSG_RESULT(no)],
[AC_DEFINE(READLINE_H_USES_NO_CONST, 1, [Define to 1 if readline/readline.h doesn't properly declare arguments to be const])
AC_MSG_RESULT(yes)])
AC_LANG_POP(C++)
fi
if test "$with_readline" != no; then
dnl some other broken readline.h's use extern "C" and declare arguments for most everything, except for the callback functions
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([if readline.h lacks types in its declaration of callbacks])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdio.h>
#if READLINE_H_NEEDS_EXTERN_C
extern "C" {
#endif
#include <readline/readline.h>
#if READLINE_H_NEEDS_EXTERN_C
} // terminate extern "C"
#endif
#ifdef READLINE_H_USES_NO_CONST
char* dummy_completion(char*, int) { return 0; }
#else
char* dummy_completion(const char*, int) { return 0; }
#endif
]],[[
rl_completion_entry_function = dummy_completion;
]]
)],
[AC_MSG_RESULT(no)],
[AC_DEFINE(READLINE_H_LACKS_TYPES_FOR_CALLBACKS, 1, [Define to 1 if readline/readline.h lacks proper declarations for callbacks])
AC_MSG_RESULT(yes)])
AC_LANG_POP(C++)
fi
dnl some systems do not supply getline()
AC_MSG_CHECKING([if getline() is supported])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
]],[[
char* buf = 0;
size_t len = 0;
getline(&buf,&len,0);
]]
)],
[AC_DEFINE(HAS_GETLINE, 1, [Define to 1 if getline() is supported])
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)])
dnl if we enabled debug, remove the -O2 and add -g; actually I override the -O2 by following it with -O0
if test "$enable_debug" = yes; then
CFLAGS="$CFLAGS -O0 -g"
CXXFLAGS="$CXXFLAGS -O0 -g"
LDADD="$LDADD -g"
fi
AC_SUBST(CXXFLAGS)
AC_OUTPUT(Makefile pwsafe.1 pwsafe.lsm pwsafe.spec)