#*****************************************************************************
#  This sample is supplied as is with no implied warranty.  
#  It is designed to assist you in using the Cisco AnyConnect VPN API. 
#  It is assumed that you will build a production application and 
#  refer to this sample as a reference only.
#*****************************************************************************
CXX = clang++
CPPFLAGS = -DHAVE_CONFIG_H -DPLATFORM_DARWIN -DPLATFORM_DESKTOP
CXXFLAGS = -arch x86_64 -arch arm64 -g -O0 -Wall -std=c++20
CXXFLAGS += -I. -I../../include -I/usr/include/libxml2
LIB_DIR = ../../lib/MAC/Intel
CURL_VER = 4
LIBS = -lxml2 -lvpnapi -lvpncommoncrypt -lvpncommon -lacciscocrypto -lacciscossl
FRAMEWORKS = -framework SystemConfiguration -framework Security -framework CoreFoundation -framework CoreServices -framework IOKit
LDFLAGS = -arch x86_64 -arch arm64 -headerpad_max_install_names
DYLIB_DIR = /opt/cisco/secureclient/lib
VPN_DYLIB_DIR = /opt/cisco/secureclient/bin/Cisco Secure Client - AnyConnect VPN Service.app/Contents/Frameworks

all: client client_dylib

client: CLIClientMain.o CLIClientImpl.o
	@echo "\nLinking using static libs..."
	${CXX} -o client CLIClientMain.o CLIClientImpl.o \
		${FRAMEWORKS} -L"${LIB_DIR}" ${LIBS} -laccurl ${LDFLAGS}
	install_name_tool -change libacciscocrypto.dylib ${LIB_DIR}/libacciscocrypto.dylib client
	install_name_tool -change libacciscossl.dylib ${LIB_DIR}/libacciscossl.dylib client

client_dylib: CLIClientMain.o CLIClientImpl.o
	@echo "\nLinking using dynamic libs..."
	${CXX} -o client_dylib CLIClientMain.o CLIClientImpl.o \
		${FRAMEWORKS} -L"${DYLIB_DIR}" -L"${VPN_DYLIB_DIR}" -laccurl.${CURL_VER} ${LIBS} ${LDFLAGS} \
		-Wl,-rpath,"${VPN_DYLIB_DIR}"
	install_name_tool -change libacciscocrypto.dylib ${DYLIB_DIR}/libacciscocrypto.dylib client_dylib
	install_name_tool -change libacciscossl.dylib ${DYLIB_DIR}/libacciscossl.dylib client_dylib
	install_name_tool -change libaccurl.${CURL_VER}.dylib ${DYLIB_DIR}/libaccurl.${CURL_VER}.dylib client_dylib

clean:
	rm -f *.o client client_dylib
