Installing the Go Chilkat Package on MacOS
Prerequisites
The install script will first check to verify the following command are available on your MacOS system: unzip, curl, sha256sum, and tar. If any of the commands are not available, the installChilkat.sh will exit with an error message prior to doing anything.
Installing
Run the following to download, build, and install. The install script (shown below) will download the required Chilkat native "C" library based on the CPU architecture, and also the Chilkat Go sources. It will validate the SHA256 checksums against the expected values. If all is OK, the downloads are extracted and the Chilkat Go module is built.
cd ~/temp curl https://chilkatdownload.com/11.1.0/build_chilkat_golang.zip -o build_chilkat_golang.zip unzip build_chilkat_golang.zip cd build_on_macos chmod a+x *.sh ./installChilkat.sh ./buildExample1.sh ./buildExample2.sh
The installChilkat.sh script contains the following:
#!/bin/bash
# Installs Chilkat v11.1.0 Go module on MacOS
# Change to any desired directory.
installDir=~
#----------------------------------------
# Check if the "tar" command exists
which tar
# Check the exit status
if [ $? -ne 0 ]; then
echo "tar command does not exist."
exit 1
fi
#----------------------------------------
# Check if the "unzip" command exists
which unzip
# Check the exit status
if [ $? -ne 0 ]; then
echo "unzip command does not exist."
exit 1
fi
#----------------------------------------
# Check if the "curl" command exists
which curl
# Check the exit status
if [ $? -ne 0 ]; then
echo "curl command does not exist."
exit 1
fi
#----------------------------------------
# Check if the "sha256sum" command exists
which sha256sum
# Check the exit status
if [ $? -ne 0 ]; then
echo "sha256sum command does not exist."
exit 1
fi
# ------------------------------
echo "Installing to $installDir"
# Create the install directory if needed.
if [ ! -d "$installDir" ]; then
if mkdir $installDir; then
echo "Created $installDir"
else
echo "Failed to create $installDir"
exit 1
fi
fi
cd $installDir
# -------------------------------------------------------------------------
# Create the "chilkatsoft.com" directory underneath the install directory.
if [ ! -d "chilkatsoft.com" ]; then
if mkdir chilkatsoft.com; then
echo "Created chilkatsoft.com"
else
echo "Failed to create chilkatsoft.com"
exit 1
fi
fi
cd chilkatsoft.com
# --------------------------------------------------------------------
# The native "C" library download is based on the machine architecture
# Download and verify the SHA256 digest of the download is a expected.
# Possible machine architectures are:
# x86_64
# arm64
# If your machine architecture is different, please let Chilkat know.
machineArch=`uname -m`
if [ "$machineArch" = "x86_64" ]; then
echo "x86_64"
archSubdir=macosx-x86_64-clang
curl https://chilkatdownload.com/11.1.0/chilkatext-macosx-x86_64-clang.tar.gz -o chilkat_native_c.tar.gz
if [ $? -ne 0 ]; then
echo "curl download of the Chilkat native "C" library failed."
exit 1
fi
digestSha256=`sha256sum chilkat_native_c.tar.gz`
echo $digestSha256
if [[ $digestSha256 == *bf1e58d73192325486040bdfced50cb9f627726836f6d498569de2be04337480* ]]; then
echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
else
echo "Digest of Chilkat native C library is not the expected value."
exit 1
fi
elif [ "$machineArch" = "arm64" ]; then
echo "aarch64"
archSubdir=macosx-arm64-clang
curl https://chilkatdownload.com/11.1.0/chilkatext-macosx-arm64-clang.tar.gz -o chilkat_native_c.tar.gz
if [ $? -ne 0 ]; then
echo "curl download of the Chilkat native "C" library failed."
exit 1
fi
digestSha256=`sha256sum chilkat_native_c.tar.gz`
echo $digestSha256
if [[ $digestSha256 == *d2cd79c43ca10a96e58f0b08544979de0d355c989aa9bf2f2756bc2cff3e8478* ]]; then
echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected."
else
echo "Digest of Chilkat native C library is not the expected value."
exit 1
fi
else
echo "Unsupported architecture: $machineArch"
exit 1
fi
# ---------------------------------------------------------
# Extract and rename the subdirectory to "native_c_lib"
#
# the resulting Chilkat native "C" static library is $installDir/chilkatsoft.com/native_c_lib/libchilkatext.a
if [ -d "native_c_lib" ]; then
rm -rf native_c_lib
fi
if [ -d "$archSubdir" ]; then
rm -rf $archSubdir
fi
tar xvf chilkat_native_c.tar.gz
if [ $? -ne 0 ]; then
echo "extracting from .tar.gz failed."
exit 1
fi
mv $archSubdir native_c_lib
rm -f chilkat_native_c.tar.gz
# --------------------------------------------------------
# Delete the "chilkat", "chilkat_example1", and "chilkat_example2" subdirectories
# from previous install attempts if they exist.
# (at this point, we are in the $installDir/chilkatsoft.com directory)
if [ -d "chilkat" ]; then
rm -rf chilkat
fi
if [ -d "chilkat_example1" ]; then
rm -rf chilkat_example1
fi
if [ -d "chilkat_example2" ]; then
rm -rf chilkat_example2
fi
# also check for any previously downloaded "license.pdf"
if [ -e "license.pdf" ]; then
rm -f license.pdf
fi
# --------------------------------------------------------
# Download the chilkat_golang.zip containing the Go source files that implement the Chilkat module,
# which do so by calling into the Chilkat native "C" lib.
curl https://chilkatdownload.com/11.1.0/chilkat_golang.zip -o chilkat_golang.zip
if [ $? -ne 0 ]; then
echo "curl download of chilkat_golang.zip failed."
exit 1
fi
# Verify the SHA256 digest is correct.
digestSha256=`sha256sum chilkat_golang.zip`
echo $digestSha256
if [[ $digestSha256 == *668bfa743d508ec067cbde892488b8bd2f752dad23495be353b877953a54e4a3* ]]; then
echo "Good, the SHA256 digest of chilkat_golang.zip is as expected."
else
echo "Digest of chilkat_golang.zip is not the expected value."
exit 1
fi
# Unzip to create three subdirectories under $installDir/chilkatsoft.com:
# chilkat
# chilkat_example1
# chilkat_example2
unzip -q chilkat_golang.zip
if [ $? -ne 0 ]; then
echo "unzipping chilkat_golang.zip failed."
exit 1
fi
rm -f chilkat_golang.zip
# --------------------------------------------------------
echo "Let's build the Chilkat module..."
echo "This can take a minute or two, or three..."
CGO_LDFLAGS="-L$installDir/chilkatsoft.com/native_c_lib -lchilkatext_$machineArch -lpthread -lresolv -ldl -lstdc++"
cd chilkat
go mod init chilkatsoft.com/chilkat
go build
if [ $? -ne 0 ]; then
echo "go build failed."
exit 1
fi
echo "Successfully built the Chilkat Go module on MacOS $machineArch."