1#
2# Copyright (c) 2019 Brent Cook
3#
4# Permission to use, copy, modify, and distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16AC_INIT([rpki-client], m4_esyscmd([tr -d '\n' < VERSION]))
17
18AC_CANONICAL_HOST
19AM_INIT_AUTOMAKE([subdir-objects foreign])
20AC_CONFIG_MACRO_DIR([m4])
21m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
22AC_PROG_CC([cc gcc])
23
24case $host_os in
25	*darwin*)
26		HOST_OS=darwin
27		AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
28		;;
29	*freebsd*)
30		HOST_OS=freebsd
31		;;
32	*linux*)
33		HOST_OS=linux
34		CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE"
35		AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
36		;;
37	*netbsd*)
38		HOST_OS=netbsd
39		;;
40	*openbsd*)
41		HOST_OS=openbsd
42		AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])
43		AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
44		;;
45	*solaris*)
46		HOST_OS=solaris
47		CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
48		;;
49	*) ;;
50esac
51
52AM_CONDITIONAL([HOST_DARWIN],  [test x$HOST_OS = xdarwin])
53AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
54AM_CONDITIONAL([HOST_LINUX],   [test x$HOST_OS = xlinux])
55AM_CONDITIONAL([HOST_NETBSD],  [test x$HOST_OS = xnetbsd])
56AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
57
58AC_PROG_SED
59AC_PROG_CC
60AC_PROG_CC_STDC
61AM_PROG_CC_C_O
62AC_PROG_LIBTOOL
63
64AC_ARG_ENABLE(warnings,
65	AS_HELP_STRING([--disable-warnings],
66	[ enable compiler warnings [default=enabled]]),
67    [case $enableval in
68	    yes) enable_warnings=yes;;
69	    no) enable_warnings=no;;
70	    *) enable_warnings=yes;; esac],
71    enable_warnings=yes)
72
73if test "$enable_warnings" = yes; then
74	AM_CFLAGS="$AM_CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Werror-implicit-function-declaration"
75	#AC_SUBST(AM_CFLAGS, ["-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Werror-implicit-function-declaration"])
76
77	save_cflags="$CFLAGS"
78	CFLAGS=-Wno-pointer-sign
79	AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
80	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
81	    [AC_MSG_RESULT([yes])]
82	    [WARN_CFLAGS=-Wno-pointer-sign],
83	    [AC_MSG_RESULT([no])]
84	)
85	AM_CFLAGS="$AM_CFLAGS $WARN_CFLAGS"
86	CFLAGS="$save_cflags"
87fi
88
89AC_MSG_CHECKING([if compiling with clang])
90AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
91#ifndef __clang__
92	not clang
93#endif
94	]])],
95	[AC_MSG_RESULT([yes])]
96	[CLANG_FLAGS=-Qunused-arguments],
97	[AC_MSG_RESULT([no])]
98)
99AM_CFLAGS="$AM_CFLAGS $CLANG_FLAGS"
100AM_LDFLAGS="$LDFLAGS $CLANG_FLAGS"
101AC_SUBST(AM_CFLAGS)
102AC_SUBST(AM_LDFLAGS)
103
104AC_ARG_WITH([openssl],
105	AS_HELP_STRING([--with-openssl=pkg-name],
106		[Use pkg-config(1) pkg-name to find OpenSSL files]),
107	PKG_NAME="$withval"
108)
109if test X"$PKG_NAME" != X; then
110	OPENSSL_CFLAGS=`pkg-config --cflags-only-I $PKG_NAME 2>/dev/null`
111	OPENSSL_LDFLAGS=`pkg-config --libs-only-L $PKG_NAME 2>/dev/null`
112fi
113
114AC_ARG_WITH([openssl-cflags],
115	AS_HELP_STRING([--with-openssl-cflags=STRING],
116		[Extra compiler flags to build with OpenSSL]),
117	OPENSSL_CFLAGS="$withval"
118)
119AC_ARG_WITH([openssl-ldflags],
120	AS_HELP_STRING([--with-openssl-ldflags=STRING],
121		[Extra flags for linker to link with OpenSSL libraries]),
122	OPENSSL_LDFLAGS="$withval"
123)
124AC_SUBST(OPENSSL_CFLAGS)
125AC_SUBST(OPENSSL_LDFLAGS)
126
127CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
128CPPFLAGS="$CPPFLAGS $OPENSSL_CFLAGS"
129LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
130
131AC_ARG_WITH([libtls],
132	AS_HELP_STRING([--with-libtls=pkg-name],
133		[Use pkg-config(1) pkg-name to find LibreSSL libtls]),
134	PKG_NAME="$withval"
135)
136if test X"$PKG_NAME" != X; then
137	LIBTLS_CFLAGS=`pkg-config --cflags-only-I $PKG_NAME 2>/dev/null`
138	LIBTLS_LDFLAGS=`pkg-config --libs-only-L $PKG_NAME 2>/dev/null`
139fi
140
141AC_ARG_WITH([libtls-cflags],
142	AS_HELP_STRING([--with-libtls-cflags=STRING],
143		[Extra compiler flags to build with LibreSSL libtls]),
144	LIBTLS_CFLAGS="$withval"
145)
146AC_ARG_WITH([libtls-ldflags],
147	AS_HELP_STRING([--with-libtls-ldflags=STRING],
148		[Extra flags for linker to link with libtls library]),
149	LIBTLS_LDFLAGS="$withval"
150)
151AC_SUBST(LIBTLS_CFLAGS)
152AC_SUBST(LIBTLS_LDFLAGS)
153
154CFLAGS="$CFLAGS $LIBTLS_CFLAGS"
155CPPFLAGS="$CPPFLAGS $LIBTLS_CFLAGS"
156LDFLAGS="$LDFLAGS $LIBTLS_LDFLAGS"
157
158AC_ARG_WITH([expat],
159	AS_HELP_STRING([--with-expat=pkg-name],
160		[Use pkg-config(1) pkg-name to find Expat]),
161	PKG_NAME="$withval"
162)
163if test X"$PKG_NAME" != X; then
164	LIBEXPAT_CFLAGS=`pkg-config --cflags-only-I $PKG_NAME 2>/dev/null`
165	LIBEXPAT_LDFLAGS=`pkg-config --libs-only-L $PKG_NAME 2>/dev/null`
166fi
167
168AC_ARG_WITH([expat-cflags],
169	AS_HELP_STRING([--with-expat-cflags=STRING],
170		[Extra compiler flags to build with Expat]),
171	LIBEXPAT_CFLAGS="$withval"
172)
173AC_ARG_WITH([expat-ldflags],
174	AS_HELP_STRING([--with-libtls-ldflags=STRING],
175		[Extra flags for linker to link with Expat library]),
176	LIBEXPAT_LDFLAGS="$withval"
177)
178AC_SUBST(LIBEXPAT_CFLAGS)
179AC_SUBST(LIBEXPAT_LDFLAGS)
180
181CFLAGS="$CFLAGS $LIBEXPAT_CFLAGS"
182CPPFLAGS="$CPPFLAGS $LIBEXPAT_CFLAGS"
183LDFLAGS="$LDFLAGS $LIBEXPAT_LDFLAGS"
184
185# check functions that are expected to be in libc
186AC_CHECK_FUNCS([explicit_bzero])
187AC_CHECK_FUNCS([reallocarray recallocarray freezero])
188AC_CHECK_FUNCS([setproctitle setgroups])
189AC_CHECK_FUNCS([setregid setresgid setreuid setresuid])
190AC_CHECK_FUNCS([memrchr strlcat strlcpy strtonum])
191AC_CHECK_FUNCS([pledge unveil])
192AC_CHECK_FUNCS([getdtablecount pipe2 ppoll])
193AC_CHECK_FUNCS([strnvis])
194
195dnl NetBSD added an strnvis and unfortunately made it incompatible with the
196dnl existing one in OpenBSD and Linux's libbsd (the former having existed
197dnl for over ten years). Despite this incompatibility being reported during
198dnl development (see http://gnats.netbsd.org/44977) they still shipped it.
199dnl Even more unfortunately FreeBSD and later MacOS picked up this incompatible
200dnl implementation.  Try to detect this mess, and assume the only safe option
201dnl if we're cross compiling.
202dnl
203dnl OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag);
204dnl NetBSD: 2012,  strnvis(char *dst, size_t dlen, const char *src, int flag);
205if test "x$ac_cv_func_strnvis" = "xyes"; then
206 AC_MSG_CHECKING([for working strnvis])
207 AC_RUN_IFELSE(
208  [AC_LANG_PROGRAM([[
209#include <signal.h>
210#include <stdlib.h>
211#include <string.h>
212#include <vis.h>
213static void sighandler(int sig) { _exit(1); }
214  ]], [[
215 char dst[16];
216
217 signal(SIGSEGV, sighandler);
218 if (strnvis(dst, "src", 4, 0) && strcmp(dst, "src") == 0)
219  exit(0);
220 exit(1)
221  ]])],
222  [AC_MSG_RESULT([yes])],
223  [AC_MSG_RESULT([no])
224   ac_cv_broken_strnvis="yes" ],
225  [AC_MSG_WARN([cross compiling: assuming broken])
226   ac_cv_broken_strnvis="yes" ]
227 )
228fi
229
230
231# check functions that are expected to be in libutil
232AC_SEARCH_LIBS([ibuf_open], [util])
233AC_CHECK_FUNCS([ibuf_open])
234
235# check functions that may be in different libs on other systems
236AC_SEARCH_LIBS([fts_open],[fts])
237AC_CHECK_FUNCS([fts_open])
238
239# Share test results with automake
240AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
241AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
242AM_CONDITIONAL([HAVE_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" = xyes])
243AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes])
244AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
245AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
246AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
247AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
248AM_CONDITIONAL([HAVE_MEMRCHR], [test "x$ac_cv_func_memrchr" = xyes])
249AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
250AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
251AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
252AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes])
253AM_CONDITIONAL([HAVE_UNVEIL], [test "x$ac_cv_func_unveil" = xyes])
254AM_CONDITIONAL([HAVE_GETDTABLECOUNT], [test "x$ac_cv_func_getdtablecount" = xyes])
255AM_CONDITIONAL([HAVE_PIPE2], [test "x$ac_cv_func_pipe2" = xyes])
256AM_CONDITIONAL([HAVE_PPOLL], [test "x$ac_cv_func_ppoll" = xyes])
257AM_CONDITIONAL([HAVE_STRNVIS], [test "x$ac_cv_func_strnvis" = xyes])
258AM_CONDITIONAL([BROKEN_STRNVIS], [test "x$ac_cv_broken_strnvis" = xyes])
259AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
260
261AC_CHECK_HEADERS([err.h sha2.h])
262
263AC_CHECK_HEADERS([openssl/cms.h openssl/err.h openssl/evp.h openssl/ssl.h openssl/x509.h openssl/x509v3.h], [], [AC_MSG_ERROR([OpenSSL headers required])])
264AC_CHECK_LIB([crypto], [ASN1_STRING_get0_data], [], [AC_MSG_ERROR([OpenSSL libraries required])])
265AC_CHECK_FUNCS([X509_up_ref], [], [AC_MSG_ERROR([OpenSSL libraries required])])
266
267AC_CHECK_FUNCS([ASN1_time_parse ASN1_time_tm_cmp])
268AM_CONDITIONAL([HAVE_ASN1_TIME_PARSE], [test "x$ac_cv_func_ASN1_time_parse" = xyes])
269AM_CONDITIONAL([HAVE_ASN1_TIME_TM_CMP], [test "x$ac_cv_func_ASN1_time_tm_cmp" = xyes])
270
271AC_CHECK_HEADERS([tls.h], [], [AC_MSG_ERROR([LibreSSL libtls headers required])])
272AC_SEARCH_LIBS([tls_read],[tls-standalone tls retls], [], [AC_MSG_ERROR([LibreSSL libtls library required])], [-lssl -lcrypto])
273AC_CHECK_FUNCS([tls_default_ca_cert_file tls_config_set_ca_mem], [], [AC_MSG_ERROR([LibreSSL libtls library required])])
274
275AC_CHECK_HEADERS([expat.h], [], [AC_MSG_ERROR([Expat headers required])])
276AC_CHECK_LIB([expat], [XML_Parse], [], [AC_MSG_ERROR([Expat library required])])
277AC_CHECK_FUNCS([XML_Parse XML_SetUserData], [], [AC_MSG_ERROR([Expat library required])])
278
279AC_ARG_WITH([user],
280	AS_HELP_STRING([--with-user=user],
281		[User for rpki-client to use when run as root]),
282	RPKI_USER="$withval",
283	RPKI_USER="_rpki-client"
284)
285AC_DEFINE_UNQUOTED(RPKI_CLIENT_USER, "$RPKI_USER", [Unprivileged user])
286AC_SUBST(RPKI_USER)
287
288AC_ARG_WITH([rsync],
289	AS_HELP_STRING([--with-rsync=command],
290		[Rsync command to use]),
291	RSYNC="$withval"
292)
293if test X"$RSYNC" = X; then
294	AC_CHECK_PROGS([RSYNC], [openrsync rsync])
295fi
296if test X"$RSYNC" = X; then
297   AC_MSG_ERROR([No rsync binary found in $PATH])
298fi
299AC_DEFINE_UNQUOTED(RPKI_RSYNC_CMD, "$RSYNC", [Rsync command])
300
301AC_ARG_WITH([tal-dir],
302	AS_HELP_STRING([--with-tal-dir=path],
303		[Path to the default TAL directory]),
304	RPKI_TAL_DIR="$withval",
305	RPKI_TAL_DIR="$sysconfdir/rpki"
306)
307AC_SUBST(RPKI_TAL_DIR)
308
309AC_ARG_WITH([base-dir],
310	AS_HELP_STRING([--with-base-dir=path],
311		[Location to store the RPKI cache repository]),
312	RPKI_BASE_DIR="$withval",
313	RPKI_BASE_DIR="$localstatedir/cache/rpki-client"
314)
315AC_SUBST(RPKI_BASE_DIR)
316
317AC_ARG_WITH([output-dir],
318	AS_HELP_STRING([--with-output-dir=path],
319		[Path to the default output directory]),
320	RPKI_OUT_DIR="$withval",
321	RPKI_OUT_DIR="$localstatedir/db/rpki-client"
322)
323AC_SUBST(RPKI_OUT_DIR)
324
325AC_CONFIG_FILES([
326	Makefile
327	include/Makefile
328	compat/Makefile
329	src/Makefile
330])
331
332AC_OUTPUT
333