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([acsccid], [1.1.8])
8AC_CONFIG_SRCDIR(src/ifdhandler.c)
9AC_CONFIG_AUX_DIR([config])
10AM_INIT_AUTOMAKE(1.8 dist-bzip2 no-dist-gzip foreign subdir-objects)
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 iconv.
69AM_ICONV
70
71# Checks for header files.
72AC_HEADER_STDC
73AC_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,,
74	[AC_MSG_ERROR([some header files not found])])
75
76# Checks for typedefs, structures, and compiler characteristics.
77AC_C_CONST
78AC_TYPE_SIZE_T
79AC_HEADER_TIME
80
81# Checks for library functions.
82AC_CHECK_FUNCS(select strerror strncpy memcpy strlcpy strlcat)
83
84# Select OS specific versions of source files.
85AC_SUBST(BUNDLE_HOST)
86AC_SUBST(DYN_LIB_EXT)
87BUNDLE_HOST=`uname | sed -e s,/,_,`
88DYN_LIB_EXT="so"
89case "$BUNDLE_HOST" in
90Darwin)
91	BUNDLE_HOST=MacOS
92	DYN_LIB_EXT="dylib"
93	;;
94SunOS)
95	BUNDLE_HOST=Solaris
96	;;
97	esac
98
99# --disable-libusb
100AC_ARG_ENABLE(libusb,
101	AS_HELP_STRING([--disable-libusb],[do not use libusb]),
102	[ use_libusb="${enableval}" ], [ use_libusb=yes ] )
103
104# check if libusb is used
105LIBUSB_NEEDED_VERSION="1.0.9"
106if test "x$use_libusb" != xno ; then
107	PKG_CHECK_EXISTS([libusb-1.0], [
108	PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= $LIBUSB_NEEDED_VERSION, [],
109		[
110		AC_MSG_WARN([install libusb $LIBUSB_NEEDED_VERSION or later])
111		PKG_CHECK_MODULES(LIBUSB, libusb-1.0)
112		])
113	])
114
115	saved_CPPFLAGS="$CPPFLAGS"
116	saved_LIBS="$LIBS"
117
118	CPPFLAGS="$CPPFLAGS $LIBUSB_CFLAGS"
119	LIBS="$LDFLAGS $LIBUSB_LIBS"
120
121	AC_CHECK_HEADERS(libusb.h, [],
122		[ AC_MSG_ERROR([libusb.h not found, install libusb or use ./configure LIBUSB_CFLAGS=...]) ])
123
124	AC_MSG_CHECKING([for libusb_init])
125	AC_TRY_LINK_FUNC(libusb_init, [ AC_MSG_RESULT([yes]) ],
126		[ AC_MSG_ERROR([libusb not found, use ./configure LIBUSB_LIBS=...]) ])
127
128	CPPFLAGS="$saved_CPPFLAGS"
129	LIBS="$saved_LIBS"
130
131	use_libusb=yes
132fi
133AC_SUBST(LIBUSB_CFLAGS)
134AC_SUBST(LIBUSB_LIBS)
135AM_CONDITIONAL(WITH_LIBUSB, test "${use_libusb}" != "no")
136
137# --enable-composite-as-multislot
138use_composite_as_multislot=no
139AC_ARG_ENABLE(composite-as-multislot,
140	AS_HELP_STRING([--enable-composite-as-multislot],[composite device are seen as multi-slots]),
141	[ use_composite_as_multislot="${enableval}" ] )
142
143if test "x$use_composite_as_multislot" = xyes; then
144	AC_DEFINE(USE_COMPOSITE_AS_MULTISLOT, 1, [composite device are seen as multi-slots])
145fi
146
147# check if the compiler support -fvisibility=hidden (GCC >= 4)
148saved_CFLAGS="$CFLAGS"
149CFLAGS="$CFLAGS -fvisibility=hidden"
150AC_MSG_CHECKING([for -fvisibility=hidden])
151AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
152    [   AC_MSG_RESULT([yes])
153        SYMBOL_VISIBILITY="-fvisibility=hidden" ],
154    AC_MSG_RESULT([no]))
155CFLAGS="$saved_CFLAGS"
156AC_SUBST(SYMBOL_VISIBILITY)
157
158# --disable-multi-thread
159AC_ARG_ENABLE(multi-thread,
160	AS_HELP_STRING([--disable-multi-thread],[disable multi threading]),
161	[ multithread="${enableval}" ], [ multithread=yes ] )
162
163if test "${multithread}" != no ; then
164	AX_PTHREAD(
165		[ AC_DEFINE(HAVE_PTHREAD, 1,
166			[Define if you have POSIX threads libraries and header files.])
167	   	], [ AC_MSG_ERROR([POSIX thread support required]) ])
168
169	multithread=yes
170fi
171
172# bundle name is acsccid.bundle
173bundle="ifd-acsccid.bundle"
174AC_DEFINE_UNQUOTED(BUNDLE, "$bundle", [bundle directory name])
175
176# --enable-usbdropdir=DIR
177AC_ARG_ENABLE(usbdropdir,
178	AS_HELP_STRING([--enable-usbdropdir=DIR],[directory containing USB
179	drivers (default to pcscd config or $(prefix)/pcsc/drivers)]),
180	[usbdropdir="${enableval}"], [usbdropdir=false])
181if test "${usbdropdir}" = false ; then
182	usbdropdir=`$PKG_CONFIG libpcsclite --variable=usbdropdir`
183fi
184AC_DEFINE_UNQUOTED(PCSCLITE_HP_DROPDIR, "$usbdropdir", [directory containing USB drivers])
185if test "${usbdropdir}" = "" ; then
186	AC_MSG_ERROR([use --enable-usbdropdir=DIR])
187fi
188
189# --disable-pcsclite
190AC_ARG_ENABLE(pcsclite,
191	AS_HELP_STRING([--disable-pcsclite],[do not use pcsc-lite debug support]),
192	[ pcsclite="${enableval}" ], [ pcsclite=yes ] )
193
194if test "${pcsclite}" != no ; then
195	# check that pcsc-lite is installed
196	OLD_LIBS="$LIBS"
197	OLD_CFLAGS="$CFLAGS"
198	LIBS="$LIBS $PCSC_LIBS"
199	CFLAGS="$CFLAGS $PCSC_CFLAGS"
200	AC_MSG_CHECKING([for SCardEstablishContext])
201	AC_TRY_LINK_FUNC(SCardEstablishContext,
202	    [ AC_MSG_RESULT([yes]) ],
203		[ AC_MSG_ERROR([SCardEstablishContext() not found, install pcsc-lite, or use PCSC_LIBS=...  ./configure]) ])
204	LIBS="$OLD_LIBS"
205	CFLAGS="$OLD_CFLAGS"
206
207	pcsclite=yes
208fi
209AM_CONDITIONAL(WITHOUT_PCSC, test "${pcsclite}" != "yes")
210
211# --enable-syslog
212AC_ARG_ENABLE(syslog,
213	AS_HELP_STRING([--enable-syslog],[use syslog instead of printf for debug (Yosemite)]),
214	[ use_syslog="${enableval}" ], [ use_syslog=no ] )
215
216if test x$use_syslog = xyes; then
217  AC_DEFINE(USE_SYSLOG, 1, [Use syslog(3) for debug])
218fi
219
220# class driver is disabled
221class=no
222NOCLASS="--no-class"
223AC_SUBST(NOCLASS)
224
225# --enable-embedded
226AC_ARG_ENABLE(embedded,
227  AS_HELP_STRING([--enable-embedded],[limit RAM and CPU ressources by disabling features (log)]),
228  [ use_embedded="${enableval}" ])
229
230if test x$use_embedded = xyes; then
231  AC_DEFINE(NO_LOG, 1, [Disable logging support])
232fi
233
234# Setup dist stuff
235AC_SUBST(ac_aux_dir)
236AC_SUBST(bundle)
237AC_SUBST(usbdropdir)
238
239cat << EOF
240
241libacsccid has been configured with following options:
242
243Version:             ${PACKAGE_VERSION}
244
245Host:                ${host}
246Compiler:            ${CC}
247Preprocessor flags:  ${CPPFLAGS}
248Compiler flags:      ${CFLAGS}
249Preprocessor flags:  ${CPPFLAGS}
250Linker flags:        ${LDFLAGS}
251Libraries:           ${LIBS}
252
253PCSC_CFLAGS:         ${PCSC_CFLAGS}
254PCSC_LIBS:           ${PCSC_LIBS}
255PTHREAD_CFLAGS:      ${PTHREAD_CFLAGS}
256PTHREAD_LIBS:        ${PTHREAD_LIBS}
257BUNDLE_HOST:         ${BUNDLE_HOST}
258DYN_LIB_EXT:         ${DYN_LIB_EXT}
259LIBUSB_CFLAGS:       ${LIBUSB_CFLAGS}
260LIBUSB_LIBS:         ${LIBUSB_LIBS}
261SYMBOL_VISIBILITY:   ${SYMBOL_VISIBILITY}
262NOCLASS:             ${NOCLASS}
263
264libusb support:          ${use_libusb}
265composite as multislot:  ${use_composite_as_multislot}
266multi threading:         ${multithread}
267bundle directory name:   ${bundle}
268USB drop directory:      ${usbdropdir}
269compiled for pcsc-lite:  ${pcsclite}
270syslog debug:            ${use_syslog}
271class driver:            ${class}
272
273EOF
274
275# Write Makefiles.
276AC_CONFIG_FILES(Makefile
277	src/Makefile)
278
279AC_OUTPUT
280