summaryrefslogtreecommitdiff
path: root/configure.ac
blob: d6bf1ad1f9ef49d99f67818b19dffea1ca32d253 (plain)
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
AC_PREREQ(2.61)

AC_INIT([p11-kit],
	[0.16.0],
	[https://bugs.freedesktop.org/enter_bug.cgi?product=p11-glue],
	[p11-kit],
	[http://p11-glue.freedesktop.org/p11-kit.html])

AC_USE_SYSTEM_EXTENSIONS

# ------------------------------------------------------------------------------
# p11-kit libtool versioning
# CURRENT : REVISION : AGE
#   +1    :     0    : +1   == new interface that does not break old one.
#   +1    :     0    :  0   == removed an interface. Breaks old apps.
#    ?    :    +1    :  ?   == internal changes that doesn't break anything.

P11KIT_CURRENT=0
P11KIT_REVISION=0
P11KIT_AGE=0

# ------------------------------------------------------------------------------

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([build/m4])
AM_INIT_AUTOMAKE([1.10])
AM_SANITY_CHECK
AM_MAINTAINER_MODE([enable])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],)

LT_PREREQ([2.2.6])
LT_INIT([dlopen disable-static])
AM_GNU_GETTEXT([external], [need-ngettext])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AM_PROG_CC_C_O

LINGUAS=""
AM_GNU_GETTEXT([external], [need-ngettext])

if test "$enable_static" = "yes"; then
	AC_MSG_ERROR([p11-kit cannot be used as a static library])
fi

AC_MSG_CHECKING([for win32])
case "$host" in
	*-*-mingw*)
		AC_DEFINE_UNQUOTED(OS_WIN32, 1, [Building for win32])
		os_win32=yes
		os_unix=no
		;;
	*)
		AC_DEFINE_UNQUOTED(OS_UNIX, 1, [Building for unix])
		os_win32=no
		os_unix=yes
		;;
esac
AC_MSG_RESULT([$os_win32])
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")

AC_C_BIGENDIAN

# ------------------------------------------------------------------------------
# Checks for libraries and headers

if test "$os_unix" = "yes"; then
	AC_CHECK_LIB(pthread, pthread_mutex_lock,,
		[AC_MSG_ERROR([could not find pthread_mutex_lock])])
	AC_SEARCH_LIBS([dlopen], [dl dld], [],
		[AC_MSG_ERROR([could not find dlopen])])
	AC_SEARCH_LIBS([nanosleep], [rt], [],
		[AC_MSG_ERROR([could not find nanosleep])])

	# These are thngs we can work around
	AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include <dirent.h>])
	AC_CHECK_FUNCS([getprogname getexecname basename mkstemp mkdtemp])
	AC_CHECK_FUNCS([strnstr memdup strndup])
	AC_CHECK_FUNCS([asprintf vasprintf vsnprintf])
	AC_CHECK_FUNCS([timegm])

	# Required functions
	AC_CHECK_FUNCS([gmtime_r],
		[AC_DEFINE([HAVE_GMTIME_R], 1, [Whether gmtime_r() is available])],
		[AC_MSG_ERROR([could not find required gmtime_r() function])])

	# Check if these are declared and/or available to link against
	AC_CHECK_DECLS([program_invocation_short_name])
	AC_MSG_CHECKING([whether program_invocation_short_name is available])
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <argp.h>]],
	                                [[program_invocation_short_name = "test";]])],
	               [AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
	                          [Whether program_invocation_short_name available])
	                AC_MSG_RESULT([yes])],
	               [AC_MSG_RESULT([no])])
	AC_CHECK_DECLS([__progname])
	AC_LINK_IFELSE([AC_LANG_SOURCE([extern char *__progname; void main() { }])],
		[AC_DEFINE(HAVE___PROGNAME, [1], [Whether __progname available])])
fi

AC_CHECK_LIB(intl, dgettext)

# ------------------------------------------------------------------------------
# PKCS#11 Directories

AC_ARG_WITH([system-config],
            [AS_HELP_STRING([--with-system-config], [Change PKCS#11 system config directory])],
            [system_config_dir=$withval],
            [system_config_dir=$sysconfdir/pkcs11])

AC_ARG_WITH([module-path],
            [AS_HELP_STRING([--with-module-path], [Load modules with relative path names from here])],
            [module_path=$withval],
            [module_path=$libdir/pkcs11])

# We expand these so we have concrete paths
p11_system_config=$system_config_dir
p11_system_config_file=$p11_system_config/pkcs11.conf
p11_system_config_modules=$p11_system_config/modules
p11_package_config_modules='${pkgdatadir}/modules'
p11_user_config="~/.pkcs11"
p11_user_config_file="$p11_user_config/pkcs11.conf"
p11_user_config_modules="$p11_user_config/modules"
p11_module_path="$module_path"

AC_SUBST(p11_system_config)
AC_SUBST(p11_system_config_file)
AC_SUBST(p11_system_config_modules)
AC_SUBST(p11_package_config_modules)
AC_SUBST(p11_user_config)
AC_SUBST(p11_user_config_file)
AC_SUBST(p11_user_config_modules)
AC_SUBST(p11_module_path)

# --------------------------------------------------------------------
# libtasn1 support

AC_ARG_WITH([libtasn1],
            AS_HELP_STRING([--without-libtasn1],
                           [Disable dependency on libtasn1])
)

AS_IF([test "$with_libtasn1" != "no"], [
	PKG_CHECK_MODULES([LIBTASN1], [libtasn1 >= 2.14], [],
		[AC_MSG_ERROR([libtasn1 not found. Building without it results in significant loss of functionality. To proceed use --without-libtasn1])]
	)
	AC_SUBST(LIBTASN1_CFLAGS)
	AC_SUBST(LIBTASN1_LIBS)
	with_libtasn1="yes"
	AC_DEFINE_UNQUOTED(WITH_ASN1, 1, [Build with libtasn1 and certificate support])
])

AM_CONDITIONAL(WITH_ASN1, test "$with_libtasn1" = "yes")

# --------------------------------------------------------------------
# Trust Module

AC_ARG_ENABLE([trust-module],
              AS_HELP_STRING([--disable-trust-module],
                             [Disable building the trust module])
)

AC_MSG_CHECKING([if trust module is enabled])
AS_IF([test "$with_libtasn1" != "yes"], [
	AS_IF([test "$enable_trust_module" = "yes"], [
		AC_MSG_ERROR([--with-libtasn1 is needed in order to build the trust module])
	])
	AS_IF([test "$enable_trust_module" != "no"], [
		AC_MSG_WARN([--with-libtasn1 is needed in order to build the trust module, disabling])
	])
	enable_trust_module="no"
])

AS_IF([test "$enable_trust_module" != "no"], [enable_trust_module="yes"])
AM_CONDITIONAL(WITH_TRUST_MODULE, test "$enable_trust_module" = "yes")
AC_MSG_RESULT([$enable_trust_module])

AC_ARG_WITH([system-anchors],
            AS_HELP_STRING([--with-system-anchors=@<:@path@:>@]:
                           [files or directories containing system CA anchors])
)

AC_MSG_CHECKING([location of system CA anchors])

if test "$enable_trust_module" != "yes"; then
	if test "$with_system_anchors" != ""; then
		AC_MSG_ERROR([need --enable-trust-module in order to use system anchors.])
	fi
	with_system_anchors="no"
fi

# This option was disabled, no anchors
if test "$with_system_anchors" = "no"; then
	with_system_anchors=""
	AC_MSG_RESULT([disabled])

# Option was not set, try to detect
elif test "$with_system_anchors" = ""; then
	for f in /etc/pki/tls/certs/ca-bundle.crt \
		/etc/ssl/certs/ca-certificates.crt \
		/etc/ssl/ca-bundle.pem \
		/etc/ssl/ca-bundle.crt; do
		if test -f "$f"; then
			with_system_anchors="$f"
			break
		fi
	done

	if test "$with_system_anchors" = ""; then
		AC_MSG_ERROR([could not find. Use --with-system-anchors=path to set, or --without-system-anchors to disable])
	fi

	AC_MSG_RESULT($with_system_anchors)
else
	AC_MSG_RESULT($with_system_anchors)
fi

AC_DEFINE_UNQUOTED(SYSTEM_ANCHORS, ["$with_system_anchors"], [The system anchor paths])
AC_SUBST(with_system_anchors)

AC_ARG_WITH([system-certificates],
            AS_HELP_STRING([--with-system-certificates=@<:@path@:>@]:
                           [files or directories containing additional system certificates])
)

AC_MSG_CHECKING([location of additional system certificates])

if test "$enable_trust_module" != "yes"; then
	if test "$with_system_certificates" != ""; then
		AC_MSG_ERROR([need --enable-trust-module in order to use additional system certificates.])
	fi
	with_system_certificates=""
fi

# This option was disabled, no additional certificates
if test "$with_system_certificates" = "no"; then
	with_system_certificates=""
fi

if test "$with_system_certificates" = ""; then
	AC_MSG_RESULT([disabled])
else
	AC_MSG_RESULT($with_system_certificates)
fi

AC_DEFINE_UNQUOTED(SYSTEM_CERTIFICATES, ["$with_system_certificates"], [Additional system certificate paths])
AC_SUBST(with_system_certificates)

# --------------------------------------------------------------------
# GTK Doc

dnl check for tools
AC_PATH_PROG([GTKDOC_CHECK],[gtkdoc-check])
AC_PATH_PROGS([GTKDOC_REBASE],[gtkdoc-rebase],[true])
AC_PATH_PROG([GTKDOC_MKPDF],[gtkdoc-mkpdf])
AC_PATH_PROG([GTKDOC_SCAN],[gtkdoc-scan])
AC_PATH_PROG([XSLTPROC], [xsltproc])

dnl for overriding the documentation installation directory
AC_ARG_WITH([html-dir],
	AS_HELP_STRING([--with-html-dir=PATH], [path to installed docs]),,
	               [with_html_dir='${datadir}/gtk-doc/html'])
HTML_DIR="$with_html_dir"
AC_SUBST([HTML_DIR])

dnl enable/disable documentation building
AC_ARG_ENABLE([doc],
	AS_HELP_STRING([--enable-doc],
	               [build documentation using gtk-doc [[default=no]]]),,
              [enable_doc=no])

if test x$enable_doc = xyes; then
	if test -z "$GTKDOC_SCAN"; then
		AC_MSG_ERROR([gtk-doc not installed and --enable-doc requested])
	fi
	if test -z "$XSLTPROC"; then
		AC_MSG_ERROR([the xsltproc command was not found and --enable-doc requested])
	fi
	doc_status="yes (manual, gtk-doc reference)"
else
	enable_doc=no
	doc_status="no (no manual, reference)"
fi

AC_MSG_CHECKING([whether to build documentation])
AC_MSG_RESULT($enable_doc)

dnl enable/disable output formats
AC_ARG_ENABLE([doc-html],
	AS_HELP_STRING([--enable-doc-html],
	               [build documentation in html format [[default=yes]]]),,
	          [enable_doc_html=yes])
AC_ARG_ENABLE([doc-pdf],
	AS_HELP_STRING([--enable-doc-pdf],
	               [build documentation in pdf format [[default=no]]]),,
              [enable_doc_pdf=no])

if test -z "$GTKDOC_MKPDF"; then
	enable_doc_pdf=no
fi

AM_CONDITIONAL(ENABLE_GTK_DOC, [test x$enable_doc = xyes])
AM_CONDITIONAL(GTK_DOC_BUILD_HTML, [test x$enable_doc_html = xyes])
AM_CONDITIONAL(GTK_DOC_BUILD_PDF, [test x$enable_doc_pdf = xyes])
AM_CONDITIONAL(GTK_DOC_USE_LIBTOOL, [test -n "$LIBTOOL"])
AM_CONDITIONAL(GTK_DOC_USE_REBASE, [test -n "$GTKDOC_REBASE"])

# --------------------------------------------------------------------
# Compilation and linking options

AC_MSG_CHECKING([for debug mode])
AC_ARG_ENABLE(debug,
              AC_HELP_STRING([--enable-debug=no/default/yes],
              [Turn on or off debugging]))

if test "$enable_debug" != "no"; then
	AC_DEFINE_UNQUOTED(WITH_DEBUG, 1, [Print debug output])
	AC_DEFINE_UNQUOTED(_DEBUG, 1, [In debug mode])
	CFLAGS="$CFLAGS -g"
fi

if test "$enable_debug" = "yes"; then
	debug_status="yes (-g, -O0, debug output)"
	CFLAGS="$CFLAGS -O0"
elif test "$enable_debug" = "no"; then
	debug_status="no (no debug output, NDEBUG)"
	AC_DEFINE_UNQUOTED(NDEBUG, 1, [Disable glib assertions])
else
	debug_status="default (-g, debug output)"
fi

AC_MSG_RESULT($debug_status)

AC_MSG_CHECKING(for more warnings)
if test "$GCC" = "yes"; then
	CFLAGS="$CFLAGS \
		-Wall -Wstrict-prototypes -Wmissing-declarations \
		-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
		-Wdeclaration-after-statement -Wformat=2 -Winit-self \
		-Waggregate-return -Wno-missing-format-attribute \
		-fno-strict-aliasing"

	for option in -Wmissing-include-dirs -Wundef; do
		SAVE_CFLAGS="$CFLAGS"
		CFLAGS="$CFLAGS $option"
		AC_MSG_CHECKING([whether gcc understands $option])
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
				  [has_option=yes],
				  [has_option=no])
		AC_MSG_RESULT($has_option)
		if test $has_option = no; then
			CFLAGS="$SAVE_CFLAGS"
		fi
	done
else
	AC_MSG_RESULT(no)
fi

AC_ARG_ENABLE(strict,
              [AS_HELP_STRING([--enable-strict], [Strict code compilation])]
             )

AC_MSG_CHECKING([build strict])

if test "$enable_strict" = "yes"; then
	CFLAGS="$CFLAGS -Werror"
	AC_DEFINE_UNQUOTED(WITH_STRICT, 1, [More strict checks])
	strict_status="yes (-Werror, fatals)"
else
	strict_status="no"
fi

AC_MSG_RESULT($strict_status)

AC_MSG_CHECKING([whether to build with gcov testing])
AC_ARG_ENABLE([coverage],
		[AS_HELP_STRING([--enable-coverage], [Whether to enable coverage testing ])],
		[],
		[enable_coverage=no])

AC_MSG_RESULT([$enable_coverage])

if test "$enable_coverage" = "yes"; then
	if test "$GCC" != "yes"; then
		AC_MSG_ERROR(Coverage testing requires GCC)
	fi

	AC_PATH_PROG(GCOV, gcov, no)
	if test "$GCOV" = "no" ; then
		AC_MSG_ERROR(gcov tool is not available)
	fi

	AC_PATH_PROG(LCOV, lcov, no)
	if test "$LCOV" = "no" ; then
		AC_MSG_ERROR(lcov tool is not installed)
	fi

	AC_PATH_PROG(GENHTML, genhtml, no)
	if test "$GENHTML" = "no" ; then
		AC_MSG_ERROR(lcov's genhtml tool is not installed)
	fi

	CFLAGS="$CFLAGS -O0 -g --coverage"
	LDFLAGS="$LDFLAGS --coverage"
fi

AM_CONDITIONAL([WITH_COVERAGE], [test "$enable_coverage" = "yes"])
AC_SUBST(LCOV)
AC_SUBST(GCOV)
AC_SUBST(GENHTML)

# ---------------------------------------------------------------------

P11KIT_LT_RELEASE=$P11KIT_CURRENT:$P11KIT_REVISION:$P11KIT_AGE
AC_SUBST(P11KIT_LT_RELEASE)

echo $PACKAGE_VERSION | tr '.' ' ' | while read major minor unused; do
	AC_DEFINE_UNQUOTED(PACKAGE_MAJOR, $major, [Major version of package])
	AC_DEFINE_UNQUOTED(PACKAGE_MINOR, $minor, [Minor version of package])
	break
done

eval SHLEXT=$shrext_cmds
AC_DEFINE_UNQUOTED(SHLEXT, ["$SHLEXT"], [File extension for shared libraries])
AC_SUBST(SHLEXT)

AC_CONFIG_FILES([Makefile
	build/Makefile
	build/certs/Makefile
	common/Makefile
	common/tests/Makefile
	doc/Makefile
	doc/version.xml
	po/Makefile.in
	p11-kit/Makefile
	p11-kit/tests/Makefile
	p11-kit/p11-kit-1.pc
	p11-kit/pkcs11.conf.example
	tools/Makefile
	tools/p11-kit-extract-trust
	tools/tests/Makefile
	trust/Makefile
	trust/tests/Makefile
])
AC_OUTPUT

AC_MSG_NOTICE([build options:

    Host:                            $host
    Debug build:                     $debug_status
    Strict build:                    $strict_status
    Build documentation:             $doc_status
    System global config:            $p11_system_config_file
    System module config directory:  $p11_system_config_modules
    Package module config directory: $p11_package_config_modules
    User global config:              $p11_user_config_file
    User module config directory:    $p11_user_config_modules
    Load relative module paths from: $p11_module_path

    With libtasn1 dependency:        $with_libtasn1

    Build trust module:              $enable_trust_module
    System certificate anchor paths: $with_system_anchors
    Other system certificate paths:  $with_system_certificates
])