1#! /bin/bash
2
3#    Copyright (C) 2007-2009  Ludovic Rousseau  <ludovic.rousseau@free.fr>
4#
5#    This program is free software; you can redistribute it and/or modify
6#    it under the terms of the GNU General Public License as published by
7#    the Free Software Foundation; either version 2 of the License, or
8#    (at your option) any later version.
9#
10#    This program is distributed in the hope that it will be useful,
11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#    GNU General Public License for more details.
14#
15#    You should have received a copy of the GNU General Public License
16#    along with this program; if not, write to the Free Software
17#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18#    02110-1301 USA.
19
20# $Id: configure 6792 2013-11-25 13:03:21Z rousseau $
21
22# to use
23# ./MacOSX/configure
24# make
25# make install
26# the driver is installed in /usr/libexec/SmartCardServices/drivers
27
28# Colors
29RED="\033[31m"
30NORMAL="\033[0m"
31
32# run this script as ./MacOSX/configure to configure for Mac OS X
33if [ ! -d MacOSX ]
34then
35	echo -e $RED
36	echo "ERROR!"
37	echo "run ./MacOSX/configure from the source top directory"
38	echo -e $NORMAL
39	exit;
40fi
41
42# find pcsc-lite header files in MacOSX/
43# use ${varname:-word} to return word only if varname is not already defined
44PCSC_CFLAGS=${PCSC_CFLAGS:--I$(pwd)/MacOSX}
45PCSC_LIBS=${PCSC_LIBS:--framework PCSC}
46
47# use libusb-1.0 (or libusbx-1.0)
48LIBUSB_ARCHIVE=$(pkg-config --variable=libdir libusb-1.0)/libusb-1.0.a
49LIBUSB_CFLAGS=$(pkg-config --cflags --static libusb-1.0)
50LIBUSB_LIBS=$(pkg-config --libs --static libusb-1.0)
51
52# RESPONSECODE is already defined by PCSC/wintypes.h
53# define needed here to compile examples/scardcontrol.c since config.h is
54# not included
55CFLAGS="$CFLAGS -DRESPONSECODE_DEFINED_IN_WINTYPES_H"
56
57# Build a Universal Binary
58UB=$(file $LIBUSB_ARCHIVE | grep "Mach-O universal binary")
59echo $UB
60if [ -z "$UB" ]
61then
62	echo -en $RED
63	echo "*************************"
64	echo "No Universal Binary build"
65	echo "*************************"
66	echo -en $NORMAL
67else
68	echo "Universal Binary build"
69	CFLAGS="$CFLAGS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -arch i386 -arch x86_64"
70fi
71echo
72
73CONFIGURE_ARGS="--disable-dependency-tracking"
74
75# do not build a static driver
76# (building fails when linking statically with libusb)
77CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-static"
78
79# do not use pcscd debug feature
80CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-pcsclite"
81
82# simulate a composite device as multi slots
83CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-composite-as-multislot"
84
85# set BUNDLE_ID to a specific value for a specific driver
86#BUNDLE_ID="vendor-reader"
87if [ ! -z "$BUNDLE_ID" ]
88then
89	# do not build a class driver (not yet used by pcsc-lite on Mac OS X)
90	CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-class"
91
92	# use a specific bundle name to NOT overwrite the official CCID driver
93	CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-bundle=ifd-ccid-$BUNDLE_ID.bundle"
94
95	# differentiate each libccid library by the dynamic linker
96	CONFIGURE_ARGS="$CONFIGURE_ARGS	--prefix=/fake/$BUNDLE_ID"
97fi
98
99set -x
100./configure \
101	CFLAGS="$CFLAGS" \
102	PCSC_CFLAGS="$PCSC_CFLAGS" \
103	PCSC_LIBS="$PCSC_LIBS" \
104	LIBUSB_CFLAGS="$LIBUSB_CFLAGS" \
105	LIBUSB_LIBS="$LIBUSB_LIBS" \
106	LDFLAGS="$LDFLAGS" \
107	--enable-usbdropdir=/usr/libexec/SmartCardServices/drivers \
108	$CONFIGURE_ARGS \
109	"$@"
110
111# force a regeneration of Info.plist
112rm -f src/Info.plist
113
114