#!/bin/sh

#*****************************************************************************
#  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.
#*****************************************************************************

#
# AnyConnect Linux API libraries built using gcc version 4.2.0
#

PLATFORM=$1

case $PLATFORM in
  Linux_embedded_ppc)
    compiler="/opt/Embedix/usr/local/powerpc-linux-gnuspe/gcc-3.4.3-e500-glibc-2.3.3-spe/bin/powerpc-linux-gnuspe-g++"
    libxml_header="-I/opt/Embedix/usr/local/powerpc-linux-gnuspe/gcc-3.4.3-e500-glibc-2.3.3-spe/include"
    libxml_zlib_lib="-L/opt/Embedix/usr/local/powerpc-linux-gnuspe/gcc-3.4.3-e500-glibc-2.3.3-spe/lib -lxml2 -lz"
    API_LIB_PATH=lib/Linux/embedded_ppc
    ;;
  Linux_embedded_arm)
    compiler="/opt/arm-2007q3/bin/arm-none-linux-gnueabi-g++"
    libxml_header="-I/opt/arm-2007q3/include"
    libxml_zlib_lib="-L/opt/arm-2007q3/lib -lxml2 -lz"
    API_LIB_PATH=lib/Linux/embedded_arm
    ;;
  Linux)
    compiler="g++"
    libxml_header="-I/usr/include/libxml2"
    libxml_zlib_lib="-lxml2 -lz"
    API_LIB_PATH=lib/Linux/Intel
    ;;
  Linux_64)
    compiler="g++"
    libxml_header="-I/usr/include/libxml2"
    libxml_zlib_lib="-lxml2 -lz"
    API_LIB_PATH=lib/Linux/Intel_64
    ;;
  Darwin_i386)
    API_LIB_PATH=lib/MAC/Intel
    ;;
  *)
    echo "Improper VPNAPI platform"
    exit 1
esac

case $PLATFORM in
  Linux | Linux_64 | Linux_embedded_ppc | Linux_embedded_arm)
    ${compiler} -DHAVE_CONFIG_H -I. -I. -I../../include -I. ${libxml_header}   -D _NOEXPORTDLL -g -O0 -Wall -MT CLIClientMain.o -MD -MP -c -o CLIClientMain.o CLIClientMain.cpp

    ${compiler} -DHAVE_CONFIG_H -I. -I. -I../../include -I. ${libxml_header}   -D _NOEXPORTDLL -g -O0 -Wall -MT CLIClientImpl.o -MD -MP -c -o CLIClientImpl.o CLIClientImpl.cpp

#the -Wl,-rpath flags are necessary to dynamically link to OpenSSL libs using relative path. Note: we don't want to use the path /opt/cisco/anyconnect/lib because it doesn't exist on the build servers. 
    ${compiler} -D _NOEXPORTDLL -g -O0 -Wall  -static-libgcc -L../../${API_LIB_PATH}  -o client  CLIClientMain.o CLIClientImpl.o -lvpnapi ${libxml_zlib_lib} -lvpncommoncrypt -lvpncommon ../../${API_LIB_PATH}/libaccurl.a ../../${API_LIB_PATH}/libacciscocrypto.so ../../${API_LIB_PATH}/libacciscossl.so -lpthread -Wl,-rpath=../../${API_LIB_PATH}/
    ;;

  Darwin_powerpc | Darwin_i386)
    touch -t 8101060007 ../../${API_LIB_PATH}/libvpnapi.a
    touch -t 8101060007 ../../${API_LIB_PATH}/libvpncommoncrypt.a
    touch -t 8101060007 ../../${API_LIB_PATH}/libvpncommon.a
    touch -t 8101060007 ../../${API_LIB_PATH}/libaccurl.a
	
    g++-4.0 -DHAVE_CONFIG_H -I. -I../../include -I. -I/usr/include/libxml2   -D _NOEXPORTDLL -g -O0 -Wall -MT CLIClientMain.o -MD -MP -c -o CLIClientMain.o CLIClientMain.cpp

    g++-4.0 -DHAVE_CONFIG_H -I. -I../../include -I. -I/usr/include/libxml2   -D _NOEXPORTDLL -g -O0 -Wall -MT CLIClientImpl.o -MD -MP -c -o CLIClientImpl.o CLIClientImpl.cpp

    g++-4.0 -D _NOEXPORTDLL -g -O0 -Wall   -o client -framework SystemConfiguration -framework Security -framework CoreFoundation -framework CoreServices CLIClientMain.o CLIClientImpl.o -L../../${API_LIB_PATH} -lvpnapi -lxml2 -lvpncommoncrypt -lvpncommon ../../${API_LIB_PATH}/libaccurl.a -lz ../../${API_LIB_PATH}/libacciscocrypto.dylib ../../${API_LIB_PATH}/libacciscossl.dylib -lresolv

    install_name_tool -change libacciscocrypto.dylib ../../${API_LIB_PATH}/libacciscocrypto.dylib client

    install_name_tool -change libacciscossl.dylib ../../${API_LIB_PATH}/libacciscossl.dylib client
   
    ;;
esac
