1# Process this file with autoconf to produce a configure script.
2# You may need to use autoconf 2.56 or newer
3
4# Require autoconf 2.61
5AC_PREREQ([2.69])
6
7AC_INIT([ccid],[1.4.36])
8AC_CONFIG_SRCDIR(src/ifdhandler.c)
9AC_CONFIG_AUX_DIR([.])
10AM_INIT_AUTOMAKE(1.8 dist-bzip2 no-dist-gzip subdir-objects foreign)
11AC_CONFIG_MACRO_DIR([m4])
12
13# silent build by default
14m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
15
16# Default install dir
17AC_PREFIX_DEFAULT(/usr/local)
18
19# Automake boilerplate.
20AC_CANONICAL_HOST
21
22# create a config.h file (Automake will add -DHAVE_CONFIG_H)
23AC_CONFIG_HEADERS([config.h])
24
25# Options
26AM_MAINTAINER_MODE
27
28# Checks for programs.
29AC_PROG_CC
30AM_PROG_CC_C_O
31AC_PROG_CPP
32AC_PROG_INSTALL
33AC_PROG_MAKE_SET
34AC_PROG_LN_S
35AM_PROG_LEX
36AM_PROG_AR
37PKG_PROG_PKG_CONFIG
38
39# check pcsc-lite version
40PCSC_NEEDED_VERSION="1.8.3"
41PKG_CHECK_EXISTS([libpcsclite],
42	[PKG_CHECK_MODULES(PCSC, libpcsclite >= $PCSC_NEEDED_VERSION, [],
43	[
44	if test -f /usr/local/lib/pkgconfig/libpcsclite.pc -a "x$PKG_CONFIG" != x ; then
45		AC_MSG_ERROR([use PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure])
46	  else
47		AC_MSG_WARN([install pcsc-lite $PCSC_NEEDED_VERSION or later])
48	  fi
49	])],
50	[AC_MSG_WARN([libpcsclite not found by pkg-config])]
51)
52
53saved_CPPFLAGS="$CPPFLAGS"
54CPPFLAGS="$CPPFLAGS $PCSC_CFLAGS"
55PCSC_ERROR_MSG="install pcsc-lite $PCSC_NEEDED_VERSION or later, or use ./configure PCSC_CFLAGS=..."
56AC_CHECK_HEADER(ifdhandler.h,, [AC_MSG_ERROR([$PCSC_ERROR_MSG])])
57AC_CHECK_HEADER(reader.h,, [AC_MSG_ERROR([$PCSC_ERROR_MSG])])
58CPPFLAGS="$saved_CPPFLAGS"
59
60# Add libtool support.
61# Static lib is disabled by default. Use --enable-static if needed
62LT_INIT(disable-static)
63LT_INIT
64
65# Automatically update the libtool script if it becomes out-of-date.
66AC_SUBST(LIBTOOL_DEPS)
67
68# Checks for header files.
69AC_CHECK_HEADERS(errno.h fcntl.h stdlib.h unistd.h termios.h string.h sys/time.h sys/types.h stdarg.h arpa/inet.h stdio.h,,
70	[AC_MSG_ERROR([some header files not found])])
71
72# Checks for typedefs, structures, and compiler characteristics.
73AC_C_CONST
74AC_TYPE_SIZE_T
75
76# Checks for library functions.
77AC_CHECK_FUNCS(select strerror strncpy memcpy strlcpy strlcat)
78
79# Select OS specific versions of source files.
80AC_SUBST(BUNDLE_HOST)
81AC_SUBST(DYN_LIB_EXT)
82BUNDLE_HOST=`uname | sed -e s,/,_,`
83DYN_LIB_EXT="so"
84case "$BUNDLE_HOST" in
85Darwin)
86	BUNDLE_HOST=MacOS
87	DYN_LIB_EXT="dylib"
88	;;
89SunOS)
90	BUNDLE_HOST=Solaris
91	;;
92	esac
93
94# --disable-libusb
95AC_ARG_ENABLE(libusb,
96	AS_HELP_STRING([--disable-libusb],[do not use libusb]),
97	[ use_libusb="${enableval}" ], [ use_libusb=yes ] )
98
99# check if libusb is used
100LIBUSB_NEEDED_VERSION="1.0.9"
101if test "x$use_libusb" != xno ; then
102	PKG_CHECK_EXISTS([libusb-1.0], [
103	PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= $LIBUSB_NEEDED_VERSION, [],
104		[
105		AC_MSG_WARN([install libusb $LIBUSB_NEEDED_VERSION or later])
106		PKG_CHECK_MODULES(LIBUSB, libusb-1.0)
107		])
108	])
109
110	saved_CPPFLAGS="$CPPFLAGS"
111	saved_LIBS="$LIBS"
112
113	CPPFLAGS="$CPPFLAGS $LIBUSB_CFLAGS"
114	LIBS="$LDFLAGS $LIBUSB_LIBS"
115
116	AC_CHECK_HEADERS(libusb.h, [],
117		[ AC_MSG_ERROR([libusb.h not found, install libusb or use ./configure LIBUSB_CFLAGS=...]) ])
118
119	AC_MSG_CHECKING([for libusb_init])
120	AC_TRY_LINK_FUNC(libusb_init, [ AC_MSG_RESULT([yes]) ],
121		[ AC_MSG_ERROR([libusb not found, use ./configure LIBUSB_LIBS=...]) ])
122
123	CPPFLAGS="$saved_CPPFLAGS"
124	LIBS="$saved_LIBS"
125
126	use_libusb=yes
127fi
128AC_SUBST(LIBUSB_CFLAGS)
129AC_SUBST(LIBUSB_LIBS)
130AM_CONDITIONAL(WITH_LIBUSB, test "${use_libusb}" != "no")
131
132# --enable-composite-as-multislot
133use_composite_as_multislot=no
134AC_ARG_ENABLE(composite-as-multislot,
135	AS_HELP_STRING([--enable-composite-as-multislot],[composite device are seen as multi-slots]),
136	[ use_composite_as_multislot="${enableval}" ] )
137
138if test "x$use_composite_as_multislot" = xyes; then
139	AC_DEFINE(USE_COMPOSITE_AS_MULTISLOT, 1, [composite device are seen as multi-slots])
140fi
141
142# check if the compiler support -fvisibility=hidden (GCC >= 4)
143saved_CFLAGS="$CFLAGS"
144CFLAGS="$CFLAGS -fvisibility=hidden"
145AC_MSG_CHECKING([for -fvisibility=hidden])
146AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
147    [   AC_MSG_RESULT([yes])
148        SYMBOL_VISIBILITY="-fvisibility=hidden" ],
149    AC_MSG_RESULT([no]))
150CFLAGS="$saved_CFLAGS"
151AC_SUBST(SYMBOL_VISIBILITY)
152
153# --disable-multi-thread
154AC_ARG_ENABLE(multi-thread,
155	AS_HELP_STRING([--disable-multi-thread],[disable multi threading]),
156	[ multithread="${enableval}" ], [ multithread=yes ] )
157
158if test "${multithread}" != no ; then
159	AX_PTHREAD(
160		[ AC_DEFINE(HAVE_PTHREAD, 1,
161			[Define if you have POSIX threads libraries and header files.])
162	   	], [ AC_MSG_ERROR([POSIX thread support required]) ])
163
164	multithread=yes
165fi
166
167# --enable-bundle=NAME
168AC_ARG_ENABLE(bundle,
169	AS_HELP_STRING([--enable-bundle=NAME],[bundle directory name
170	(default ifd-ccid.bundle)]),
171	[bundle="${enableval}"], [bundle=false])
172if test "${bundle}" = false ; then
173	bundle="ifd-ccid.bundle"
174fi
175AC_DEFINE_UNQUOTED(BUNDLE, "$bundle", [bundle directory name])
176
177# --enable-usbdropdir=DIR
178AC_ARG_ENABLE(usbdropdir,
179	AS_HELP_STRING([--enable-usbdropdir=DIR],[directory containing USB
180	drivers (default to pcscd config or $(prefix)/pcsc/drivers)]),
181	[usbdropdir="${enableval}"], [usbdropdir=false])
182if test "${usbdropdir}" = false ; then
183	usbdropdir=`$PKG_CONFIG libpcsclite --variable=usbdropdir`
184fi
185AC_DEFINE_UNQUOTED(PCSCLITE_HP_DROPDIR, "$usbdropdir", [directory containing USB drivers])
186if test "${usbdropdir}" = "" ; then
187	AC_MSG_ERROR([use --enable-usbdropdir=DIR])
188fi
189
190# --enable-twinserial
191AC_ARG_ENABLE(twinserial,
192	AS_HELP_STRING([--enable-twinserial],[also compile and install the serial Twin driver]),
193	[twinserial="${enableval}"], [twinserial=no])
194AM_CONDITIONAL(WITH_TWIN_SERIAL, test "${twinserial}" != "no")
195
196# --enable-ccidtwindir=DIR
197AC_ARG_ENABLE(ccidtwindir,
198	AS_HELP_STRING([--enable-ccidtwindir=DIR],[directory to install the
199	serial Twin driver (default to pcscd config or $(prefix)/pcsc/drivers/serial)]),
200	[ccidtwindir="${enableval}"], [ccidtwindir=false])
201if test "${ccidtwindir}" = false ; then
202	ccidtwindir=$usbdropdir/serial
203fi
204
205# --enable-serialconfdir=DIR
206AC_ARG_ENABLE(serialconfdir,
207	AS_HELP_STRING([--enable-serialconfdir=dir],[directory containing
208		serial drivers (default to pcscd config)]),
209	[serialconfdir="${enableval}"], [serialconfdir=false])
210if test "${serialconfdir}" = false ; then
211	serialconfdir=`$PKG_CONFIG libpcsclite --variable=serialconfdir`
212fi
213
214# --disable-pcsclite
215AC_ARG_ENABLE(pcsclite,
216	AS_HELP_STRING([--disable-pcsclite],[do not use pcsc-lite debug support]),
217	[ pcsclite="${enableval}" ], [ pcsclite=yes ] )
218
219if test "${pcsclite}" != no ; then
220	# check that pcsc-lite is installed
221	OLD_LIBS="$LIBS"
222	OLD_CFLAGS="$CFLAGS"
223	LIBS="$LIBS $PCSC_LIBS"
224	CFLAGS="$CFLAGS $PCSC_CFLAGS"
225	AC_MSG_CHECKING([for SCardEstablishContext])
226	AC_TRY_LINK_FUNC(SCardEstablishContext,
227	    [ AC_MSG_RESULT([yes]) ],
228		[ AC_MSG_ERROR([SCardEstablishContext() not found, install pcsc-lite, or use PCSC_LIBS=...  ./configure]) ])
229	LIBS="$OLD_LIBS"
230	CFLAGS="$OLD_CFLAGS"
231
232	pcsclite=yes
233fi
234AM_CONDITIONAL(WITHOUT_PCSC, test "${pcsclite}" != "yes")
235
236
237
238# --enable-syslog
239AC_ARG_ENABLE(syslog,
240	AS_HELP_STRING([--enable-syslog],[use syslog(3) instead of printf() for debug (Yosemite 10.10)]),
241	[ use_syslog="${enableval}" ], [ use_syslog=no ] )
242
243if test x$use_syslog = xyes; then
244  AC_DEFINE(USE_SYSLOG, 1, [Use syslog(3) for debug])
245fi
246
247# --enable-oslog
248AC_ARG_ENABLE(oslog,
249	AS_HELP_STRING([--enable-oslog],[use os_log(3) instead of printf() for debug (Sierra 10.12)]),
250	[ use_oslog="${enableval}" ], [ use_oslog=no ] )
251
252if test x$use_oslog = xyes; then
253  AC_DEFINE(USE_OS_LOG, 1, [Use os_log(3) for debug])
254fi
255
256
257# --disable-class
258AC_ARG_ENABLE(class,
259	AS_HELP_STRING([--disable-class],[remove the CCIDCLASSDRIVER from Info.plist]),
260	[class="${enableval}"], [class=yes])
261if test "${class}" != yes ; then
262	NOCLASS="--no-class"
263fi
264AC_SUBST(NOCLASS)
265
266# --enable-embedded
267AC_ARG_ENABLE(embedded,
268  AS_HELP_STRING([--enable-embedded],[limit RAM and CPU ressources by disabling features (log)]),
269  [ use_embedded="${enableval}" ])
270
271if test x$use_embedded = xyes; then
272  AC_DEFINE(NO_LOG, 1, [Disable logging support])
273fi
274
275# --enable-zlp
276AC_ARG_ENABLE(zlp,
277  AS_HELP_STRING([--enable-zlp],[enable the Zero Length Packet patch for some Gemalto readers]),
278  [ use_zlp="${enableval}" ])
279
280if test x$use_zlp = xyes; then
281  AC_DEFINE(ENABLE_ZLP, 1, [Enable Zero Length Packet patch])
282fi
283
284# Setup dist stuff
285AC_SUBST(ac_aux_dir)
286AC_SUBST(bundle)
287AC_SUBST(usbdropdir)
288AC_SUBST(ccidtwindir)
289AC_SUBST(serialconfdir)
290
291cat << EOF
292
293libccid has been configured with following options:
294
295Version:             ${PACKAGE_VERSION}
296Host:                ${host}
297Compiler:            ${CC}
298Preprocessor flags:  ${CPPFLAGS}
299Compiler flags:      ${CFLAGS}
300Preprocessor flags:  ${CPPFLAGS}
301Linker flags:        ${LDFLAGS}
302Libraries:           ${LIBS}
303
304PCSC_CFLAGS:         ${PCSC_CFLAGS}
305PCSC_LIBS:           ${PCSC_LIBS}
306PTHREAD_CFLAGS:      ${PTHREAD_CFLAGS}
307PTHREAD_LIBS:        ${PTHREAD_LIBS}
308BUNDLE_HOST:         ${BUNDLE_HOST}
309DYN_LIB_EXT:         ${DYN_LIB_EXT}
310LIBUSB_CFLAGS:       ${LIBUSB_CFLAGS}
311LIBUSB_LIBS:         ${LIBUSB_LIBS}
312SYMBOL_VISIBILITY:   ${SYMBOL_VISIBILITY}
313NOCLASS:             ${NOCLASS}
314
315libusb support:          ${use_libusb}
316composite as multislot:  ${use_composite_as_multislot}
317multi threading:         ${multithread}
318bundle directory name:   ${bundle}
319USB drop directory:      ${usbdropdir}
320serial Twin support:     ${twinserial}
321serial twin install dir: ${ccidtwindir}
322serial config directory: ${serialconfdir}
323compiled for pcsc-lite:  ${pcsclite}
324syslog debug:            ${use_syslog}
325os_log debug:            ${use_oslog}
326class driver:            ${class}
327
328EOF
329
330# Write Makefiles.
331AC_CONFIG_FILES(Makefile
332	src/Makefile
333	readers/Makefile
334	contrib/Makefile
335	contrib/Kobil_mIDentity_switch/Makefile
336	contrib/RSA_SecurID/Makefile
337	examples/Makefile)
338
339AC_OUTPUT
340
341