Blame MacOSX/configure

Packit 9f0df5
#! /bin/bash
Packit 9f0df5
Packit 9f0df5
#    Copyright (C) 2007-2009  Ludovic Rousseau  <ludovic.rousseau@free.fr>
Packit 9f0df5
#
Packit 9f0df5
#    This program is free software; you can redistribute it and/or modify
Packit 9f0df5
#    it under the terms of the GNU General Public License as published by
Packit 9f0df5
#    the Free Software Foundation; either version 2 of the License, or
Packit 9f0df5
#    (at your option) any later version.
Packit 9f0df5
#
Packit 9f0df5
#    This program is distributed in the hope that it will be useful,
Packit 9f0df5
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 9f0df5
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 9f0df5
#    GNU General Public License for more details.
Packit 9f0df5
#
Packit 9f0df5
#    You should have received a copy of the GNU General Public License
Packit 9f0df5
#    along with this program; if not, write to the Free Software
Packit 9f0df5
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 9f0df5
#    02110-1301 USA.
Packit 9f0df5
Packit 9f0df5
# to use
Packit 9f0df5
# ./MacOSX/configure
Packit 9f0df5
# make
Packit 9f0df5
# make install
Packit 9f0df5
# the driver is installed in /usr/libexec/SmartCardServices/drivers
Packit 9f0df5
Packit 9f0df5
# Colors
Packit 9f0df5
RED="\033[31m"
Packit 9f0df5
NORMAL="\033[0m"
Packit 9f0df5
Packit 9f0df5
# run this script as ./MacOSX/configure to configure for Mac OS X
Packit 9f0df5
if [ ! -d MacOSX ]
Packit 9f0df5
then
Packit 9f0df5
	echo -e $RED
Packit 9f0df5
	echo "ERROR!"
Packit 9f0df5
	echo "run ./MacOSX/configure from the source top directory"
Packit 9f0df5
	echo -e $NORMAL
Packit 9f0df5
	exit;
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
# find pcsc-lite header files in MacOSX/
Packit 9f0df5
# use ${varname:-word} to return word only if varname is not already defined
Packit 9f0df5
PCSC_CFLAGS=${PCSC_CFLAGS:--I$(pwd)/MacOSX}
Packit 9f0df5
PCSC_LIBS=${PCSC_LIBS:--framework PCSC}
Packit 9f0df5
Packit 9f0df5
# use libusb-1.0
Packit 9f0df5
LIBUSB_DIR=$(pkg-config --variable=libdir libusb-1.0)
Packit 9f0df5
LIBUSB_ARCHIVE="$LIBUSB_DIR"/libusb-1.0.a
Packit 9f0df5
LIBUSB_CFLAGS=$(pkg-config --cflags --static libusb-1.0)
Packit 9f0df5
LIBUSB_LIBS=$(pkg-config --libs --static libusb-1.0)
Packit 9f0df5
Packit 9f0df5
if ls "$LIBUSB_DIR"/*.dylib 2> /dev/null
Packit 9f0df5
then
Packit 9f0df5
	echo -en $RED
Packit 9f0df5
	echo "*****************************"
Packit 9f0df5
	echo "Dynamic library libusb found in $LIBUSB_DIR"
Packit 9f0df5
	echo "*****************************"
Packit 9f0df5
	echo -en $NORMAL
Packit 9f0df5
	echo "Rename it to force a static link"
Packit 9f0df5
	exit
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
# RESPONSECODE is already defined by PCSC/wintypes.h
Packit 9f0df5
# define needed here to compile examples/scardcontrol.c since config.h is
Packit 9f0df5
# not included
Packit 9f0df5
CFLAGS="$CFLAGS -DRESPONSECODE_DEFINED_IN_WINTYPES_H"
Packit 9f0df5
Packit 9f0df5
# get the Mac OS X major version. Example: El Capitan 10.11 -> 10011
Packit 9f0df5
MAC_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 * 1000 + $2}')
Packit 9f0df5
Packit 9f0df5
# check for Universal Binary only on macOS Mavericks 10.9 and earlier
Packit 9f0df5
if [ $MAC_VERSION -le 10009 ]
Packit 9f0df5
then
Packit 9f0df5
	# Build a Universal Binary?
Packit 9f0df5
	UB=$(file $LIBUSB_ARCHIVE | grep "Mach-O universal binary")
Packit 9f0df5
	echo $UB
Packit 9f0df5
	if [ -z "$UB" ]
Packit 9f0df5
	then
Packit 9f0df5
		echo -en $RED
Packit 9f0df5
		echo "*************************"
Packit 9f0df5
		echo "No Universal Binary build"
Packit 9f0df5
		echo "*************************"
Packit 9f0df5
		echo -en $NORMAL
Packit 9f0df5
	else
Packit 9f0df5
		echo "Universal Binary build"
Packit 9f0df5
		CFLAGS="$CFLAGS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -arch i386 -arch x86_64"
Packit 9f0df5
	fi
Packit 9f0df5
	echo
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
CONFIGURE_ARGS="--disable-dependency-tracking"
Packit 9f0df5
Packit 9f0df5
# Are we on a CryptoTokenKit system? (like Mac OS X 10.10 Yosemite)
Packit 9f0df5
if [ -d /System/Library/CryptoTokenKit ]
Packit 9f0df5
then
Packit 9f0df5
	# so we use syslog(3) to log errors
Packit 9f0df5
	CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-syslog"
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
# Check where to install the driver
Packit 9f0df5
if [ 10011 -gt $MAC_VERSION ]
Packit 9f0df5
then
Packit 9f0df5
	# Mac OS X < 10.11
Packit 9f0df5
	DROPDIR="/usr/libexec/SmartCardServices/drivers"
Packit 9f0df5
else
Packit 9f0df5
	# Mac OS X >= 10.11 (El Capitan)
Packit 9f0df5
	DROPDIR="/usr/local/libexec/SmartCardServices/drivers"
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
# do not build a static driver
Packit 9f0df5
# (building fails when linking statically with libusb)
Packit 9f0df5
CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-static"
Packit 9f0df5
Packit 9f0df5
# do not use pcscd debug feature
Packit 9f0df5
CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-pcsclite"
Packit 9f0df5
Packit 9f0df5
# simulate a composite device as multi slots
Packit 9f0df5
CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-composite-as-multislot"
Packit 9f0df5
Packit 9f0df5
# set BUNDLE_ID to a specific value for a specific driver
Packit 9f0df5
#BUNDLE_ID="vendor-reader"
Packit 9f0df5
if [ ! -z "$BUNDLE_ID" ]
Packit 9f0df5
then
Packit 9f0df5
	# do not build a class driver (not yet used by pcsc-lite on Mac OS X)
Packit 9f0df5
	CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-class"
Packit 9f0df5
Packit 9f0df5
	# use a specific bundle name to NOT overwrite the official CCID driver
Packit 9f0df5
	CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-bundle=ifd-ccid-$BUNDLE_ID.bundle"
Packit 9f0df5
Packit 9f0df5
	# differentiate each libccid library by the dynamic linker
Packit 9f0df5
	CONFIGURE_ARGS="$CONFIGURE_ARGS	--prefix=/fake/$BUNDLE_ID"
Packit 9f0df5
fi
Packit 9f0df5
Packit 9f0df5
set -x
Packit 9f0df5
./configure \
Packit 9f0df5
	CFLAGS="$CFLAGS" \
Packit 9f0df5
	PCSC_CFLAGS="$PCSC_CFLAGS" \
Packit 9f0df5
	PCSC_LIBS="$PCSC_LIBS" \
Packit 9f0df5
	LIBUSB_CFLAGS="$LIBUSB_CFLAGS" \
Packit 9f0df5
	LIBUSB_LIBS="$LIBUSB_LIBS" \
Packit 9f0df5
	LDFLAGS="$LDFLAGS" \
Packit 9f0df5
	--enable-usbdropdir="$DROPDIR" \
Packit 9f0df5
	$CONFIGURE_ARGS \
Packit 9f0df5
	"$@"
Packit 9f0df5
Packit 9f0df5
r=$?
Packit 9f0df5
Packit 9f0df5
# force a regeneration of Info.plist
Packit 9f0df5
rm -f src/Info.plist
Packit 9f0df5
Packit 9f0df5
# exit with the return code from ./configure
Packit 9f0df5
exit $r