Initial commit
[platform/upstream/ccid.git] / MacOSX / configure
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 # to use
21 # ./MacOSX/configure
22 # make
23 # make install
24 # the driver is installed in /usr/libexec/SmartCardServices/drivers
25
26 # Colors
27 RED="\033[31m"
28 NORMAL="\033[0m"
29
30 # run this script as ./MacOSX/configure to configure for Mac OS X
31 if [ ! -d MacOSX ]
32 then
33         echo -e $RED
34         echo "ERROR!"
35         echo "run ./MacOSX/configure from the source top directory"
36         echo -e $NORMAL
37         exit -1
38 fi
39
40 # find pcsc-lite header files in MacOSX/
41 # use ${varname:-word} to return word only if varname is not already defined
42 PCSC_CFLAGS=${PCSC_CFLAGS:--I$(pwd)/MacOSX}
43 PCSC_LIBS=${PCSC_LIBS:--framework PCSC}
44
45 # use libusb-1.0
46 LIBUSB_DIR=$(pkg-config --variable=libdir libusb-1.0)
47 LIBUSB_ARCHIVE="$LIBUSB_DIR"/libusb-1.0.a
48 LIBUSB_CFLAGS=$(pkg-config --cflags --static libusb-1.0)
49 LIBUSB_LIBS=$(pkg-config --libs --static libusb-1.0)
50
51 if ls "$LIBUSB_DIR"/libusb-1.0*.dylib 2> /dev/null
52 then
53         echo -en $RED
54         echo "*****************************"
55         echo "Dynamic library libusb found in $LIBUSB_DIR"
56         echo "*****************************"
57         echo -en $NORMAL
58         echo "Rename it to force a static link"
59         exit -1
60 fi
61
62 # RESPONSECODE is already defined by PCSC/wintypes.h
63 # define needed here to compile examples/scardcontrol.c since config.h is
64 # not included
65 CFLAGS="$CFLAGS -DRESPONSECODE_DEFINED_IN_WINTYPES_H"
66
67 # get the Mac OS X major version. Example: El Capitan 10.11 -> 10011
68 MAC_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 * 1000 + $2}')
69
70 # check for Universal Binary only on macOS Mavericks 10.9 and earlier
71 if [ $MAC_VERSION -le 10009 ]
72 then
73         # Build a Universal Binary?
74         UB=$(file $LIBUSB_ARCHIVE | grep "Mach-O universal binary")
75         echo $UB
76         if [ -z "$UB" ]
77         then
78                 echo -en $RED
79                 echo "*************************"
80                 echo "No Universal Binary build"
81                 echo "*************************"
82                 echo -en $NORMAL
83         else
84                 echo "Universal Binary build"
85                 CFLAGS="$CFLAGS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -arch i386 -arch x86_64"
86         fi
87         echo
88 fi
89
90 CONFIGURE_ARGS="--disable-dependency-tracking"
91
92 # Are we on a CryptoTokenKit system? (like Mac OS X 10.10 Yosemite)
93 if [ -d /System/Library/CryptoTokenKit ]
94 then
95         if [ 10012 -gt $MAC_VERSION ]
96         then
97                 # use syslog(3) to logs for macOS < 10.12
98                 CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-syslog"
99         else
100                 # use os_log(3) to logs for macOS >= 10.12
101                 CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-oslog"
102         fi
103 fi
104
105 # Check where to install the driver
106 if [ 10011 -gt $MAC_VERSION ]
107 then
108         # Mac OS X < 10.11
109         DROPDIR="/usr/libexec/SmartCardServices/drivers"
110 else
111         # Mac OS X >= 10.11 (El Capitan)
112         DROPDIR="/usr/local/libexec/SmartCardServices/drivers"
113 fi
114
115 # do not build a static driver
116 # (building fails when linking statically with libusb)
117 CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-static"
118
119 # do not use pcscd debug feature
120 CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-pcsclite"
121
122 # simulate a composite device as multi slots
123 CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-composite-as-multislot"
124
125 # set BUNDLE_ID to a specific value for a specific driver
126 #BUNDLE_ID="vendor-reader"
127 if [ ! -z "$BUNDLE_ID" ]
128 then
129         # do not build a class driver (not yet used by pcsc-lite on Mac OS X)
130         CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-class"
131
132         # use a specific bundle name to NOT overwrite the official CCID driver
133         CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-bundle=ifd-ccid-$BUNDLE_ID.bundle"
134
135         # differentiate each libccid library by the dynamic linker
136         CONFIGURE_ARGS="$CONFIGURE_ARGS --prefix=/fake/$BUNDLE_ID"
137 fi
138
139 set -x
140 ./configure \
141         CFLAGS="$CFLAGS" \
142         PCSC_CFLAGS="$PCSC_CFLAGS" \
143         PCSC_LIBS="$PCSC_LIBS" \
144         LIBUSB_CFLAGS="$LIBUSB_CFLAGS" \
145         LIBUSB_LIBS="$LIBUSB_LIBS" \
146         LDFLAGS="$LDFLAGS" \
147         --enable-usbdropdir="$DROPDIR" \
148         $CONFIGURE_ARGS \
149         "$@"
150
151 r=$?
152
153 # force a regeneration of Info.plist
154 rm -f src/Info.plist
155
156 # exit with the return code from ./configure
157 exit $r