Skip to content

Instantly share code, notes, and snippets.

@vincentsarago
Last active February 10, 2022 16:51
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vincentsarago/bf249e451b304314838a2214ea60e865 to your computer and use it in GitHub Desktop.
Save vincentsarago/bf249e451b304314838a2214ea60e865 to your computer and use it in GitHub Desktop.

Important

DO NOT USE VSCODE terminal and make sure uname -m returns arm64

  1. First Install Xcode command line tool
xcode-select --install
  1. Create and change /opt directories owner
sudo mkdir /opt/bin
sudo mkdir /opt/etc
sudo mkdir /opt/include
sudo mkdir /opt/lib
sudo mkdir /opt/share

sudo chown -R `whoami` /opt/*

ref: https://docs.brew.sh/FAQ#why-does-homebrew-prefer-i-install-to-usrlocal

  1. install cmake

-> https://github.com/Kitware/CMake/releases/download/v3.19.6/cmake-3.19.6-macos-universal.dmg

link cmake CLI

/Applications/CMake.app/Contents/bin/cmake-gui --install=/opt/bin
  1. Install GFortran

ref: https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/11-arm-alpha2

  1. :point-down:
# versions of packages
export \
  LIBPNG_VERSION=1.6.37 \
  LIBJPEG_TURBO_VERSION=2.0.6 \
  OPENJPEG_VERSION=2.3.1 \
  HDF4_VERSION=4.2.15 \
  HDF5_VERSION=1.12.0 \
  NETCDF_VERSION=4.7.4 \
  PG_VERSION=13.2 \
  SZIP_VERSION=2.1.1 \
  WEBP_VERSION=1.2.0 \
  ZSTD_VERSION=1.4.5 \
  GEOS_VERSION=3.9.1 \
  PROJ_VERSION=7.2.1 \
  LIBTIFF_VERSION=4.2.0 \
  LIBGEOTIFF_VERSION=1.6.0

export BUILD_DIR=/tmp/build
export PREFIX=/opt

export LDFLAGS="-L$PREFIX/lib"
export CPPFLAGS="-I$PREFIX/include"

# Those would have to be set in my env later
export PATH=/opt/bin:$PATH
export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH

# NASM 
mkdir $BUILD_DIR/nasm \
  && curl -sfL https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz | tar zxf - -C $BUILD_DIR/nasm --strip-components=1 \
  && cd $BUILD_DIR/nasm \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/nasm

# pkg-config
mkdir $BUILD_DIR/pkgconfig \
  && curl -sfL https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz | tar zxf - -C $BUILD_DIR/pkgconfig --strip-components=1 \
  && cd $BUILD_DIR/pkgconfig \
  && ./configure \
    --disable-debug \
    --prefix=$PREFIX \
    --disable-host-tool \
    --with-internal-glib \
    --with-system-include-path=/usr/include \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/pkgconfig

# png
mkdir $BUILD_DIR/png \
  && curl -sfL http://prdownloads.sourceforge.net/libpng/libpng-$LIBPNG_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/png --strip-components=1 \
  && cd $BUILD_DIR/png \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/png

# webp
mkdir $BUILD_DIR/webp \
  && curl -sfL https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-$WEBP_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/webp --strip-components=1 \
  && cd $BUILD_DIR/webp \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/webp

# liblzma 
mkdir $BUILD_DIR/lzma \
  && curl -sfL https://tukaani.org/xz/xz-5.2.5.tar.gz | tar zxf - -C $BUILD_DIR/lzma --strip-components=1 \
  && cd $BUILD_DIR/lzma \
  && ./configure --prefix=$PREFIX \
  && make -j4 PREFIX=$PREFIX --silent && make install \
  && rm -rf $BUILD_DIR/lzma 

# zstd
mkdir $BUILD_DIR/zstd \
  && curl -sfL https://github.com/facebook/zstd/archive/v$ZSTD_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/zstd --strip-components=1 \
  && cd $BUILD_DIR/zstd \
  && make -j4 PREFIX=$PREFIX --silent ZSTD_LEGACY_SUPPORT=0 && make install \
  && rm -rf $BUILD_DIR/zstd

# libexpat
mkdir $BUILD_DIR/libexpat \
  && curl -sfL https://github.com/libexpat/libexpat/releases/download/R_2_2_10/expat-2.2.10.tar.gz | tar zxf - -C $BUILD_DIR/libexpat --strip-components=1 \
  && cd $BUILD_DIR/libexpat \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/libexpat

# szip
mkdir $BUILD_DIR/szip \
  && curl -sfL https://support.hdfgroup.org/ftp/lib-external/szip/$SZIP_VERSION/src/szip-$SZIP_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/szip --strip-components=1 \
  && cd $BUILD_DIR/szip \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/szip

# openssl + crypto
sudo mkdir $PREFIX/ssl
sudo chown `whoami` $PREFIX/ssl
mkdir $BUILD_DIR/openssl \
  && curl -sfL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1j.tar.gz | tar zxf - -C $BUILD_DIR/openssl --strip-components=1 \
  && cd $BUILD_DIR/openssl \
  && SDKROOT=$(xcrun --show-sdk-path --sdk macosx) MACOSX_DEPLOYMENT_TARGET=11.3 ./configure shared enable-rc5 zlib darwin64-arm64-cc --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/openssl

# readline
mkdir $BUILD_DIR/readline \
  && curl -sfL https://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz | tar zxf - -C $BUILD_DIR/readline --strip-components=1 \
  && cd $BUILD_DIR/readline \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/readline

# libhdf5
mkdir $BUILD_DIR/hdf5 \
  && curl -sfL https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-$HDF5_VERSION/src/hdf5-$HDF5_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/hdf5 --strip-components=1 \
  && cd $BUILD_DIR/hdf5 \
  && ./configure \
  --prefix=$PREFIX \
  --enable-build-mode=production \
  --with-szlib \
  --enable-threadsafe \
  --enable-unsupported \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/hdf5

# NetCDF
mkdir $BUILD_DIR/netcdf \
  && curl -sfL https://github.com/Unidata/netcdf-c/archive/v$NETCDF_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/netcdf --strip-components=1 \
  && cd $BUILD_DIR/netcdf \
  && ./configure \
  --disable-debug \
  --with-default-chunk-size=67108864 \
  --with-chunk-cache-size=67108864 \
  --prefix=$PREFIX \
  --enable-dap \
  --with-pic \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/netcdf

# postgres
mkdir $BUILD_DIR/postgres \
  && curl -sfL https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/postgres --strip-components=1 \
  && cd $BUILD_DIR/postgres \
  && ./configure --prefix=$PREFIX \
    --disable-debug \
    --enable-thread-safety \
    --with-openssl \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/postgres

###############################################################################

# PROBLEM
# libjpeg_turbo
mkdir $BUILD_DIR/jpeg \
  && curl -sfL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/$LIBJPEG_TURBO_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/jpeg --strip-components=1 \
  && cd $BUILD_DIR/jpeg \
  && cmake . -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release \
  && make -j4 install \
  && rm -rf $BUILD_DIR/jpeg

# PROBLEM
# libdeflate seems to be a static! I don't know why the other software gets lost 
# libdeflate
# mkdir $BUILD_DIR/libdeflate \
#   && curl -sfL https://github.com/ebiggers/libdeflate/archive/v1.7.tar.gz | tar zxf - -C $BUILD_DIR/libdeflate --strip-components=1 \
#   && cd $BUILD_DIR/libdeflate \
#   && make -j4 --silent PREFIX=$PREFIX && make install \
#   && rm -rf $BUILD_DIR/libdeflate

# libtiff
mkdir $BUILD_DIR/libtiff \
  && curl -sfL https://download.osgeo.org/libtiff/tiff-$LIBTIFF_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/libtiff --strip-components=1 \
  && cd $BUILD_DIR/libtiff \
  && ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/libtiff

# openjpeg
mkdir $BUILD_DIR/openjpeg \
  && curl -sfL https://github.com/uclouvain/openjpeg/archive/v$OPENJPEG_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/openjpeg --strip-components=1 \
  && cd $BUILD_DIR/openjpeg \
  && cmake . -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release \
  && make -j4 install \
  && rm -rf $BUILD_DIR/openjpeg

# geos
mkdir $BUILD_DIR/geos \
  && curl -sfL https://github.com/libgeos/geos/archive/$GEOS_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/geos --strip-components=1 \
  && cd $BUILD_DIR/geos \
  && cmake -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release . \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/geos

# proj
mkdir $BUILD_DIR/proj && mkdir $BUILD_DIR/proj/data \
  && curl -sfL http://download.osgeo.org/proj/proj-$PROJ_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/proj --strip-components=1 \
  && curl -sfL http://download.osgeo.org/proj/proj-datumgrid-latest.tar.gz | tar zxf - -C $BUILD_DIR/proj/data \
  && cd $BUILD_DIR/proj \
  && SQLITE3_LIBS="-L/usr/lib -lsqlite3" \
  SQLITE3_INCLUDE_DIR="/usr/include" \
  SQLITE3_CFLAGS="$CFLAGS -I/usr/include" \
  ./configure --prefix=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/proj

# libgeotiff
mkdir $BUILD_DIR/libgeotiff \
  && curl -sfL https://github.com/OSGeo/libgeotiff/releases/download/$LIBGEOTIFF_VERSION/libgeotiff-$LIBGEOTIFF_VERSION.tar.gz | tar zxf - -C $BUILD_DIR/libgeotiff --strip-components=1 \
  && cd $BUILD_DIR/libgeotiff \
  && ./configure \
    --prefix=$PREFIX \
    --with-proj=$PREFIX \
    --with-jpeg=$PREFIX \
    --with-zip=yes \
    --with-zlib \
    --with-libtiff=$PREFIX \
  && make -j4 --silent && make install \
  && rm -rf $BUILD_DIR/libgeotiff

# GDAL
mkdir $BUILD_DIR/gdal \
  && curl -sfL https://github.com/OSGeo/gdal/archive/release/3.2.tar.gz | tar zxf - -C $BUILD_DIR/gdal --strip-components=2 \
  && cd $BUILD_DIR/gdal \
  && PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LIBXML2_CFLAGS=$(xml2-config --cflags) LIBXML2_LIBS=$(xml2-config --libs) \
  ./configure \
      --disable-debug \
      --with-local=$PREFIX \
      --with-libtool \
      --with-opencl \
      --with-threads=yes \
      --prefix=$PREFIX \
      --with-hide-internal-symbols \
      --with-proj=$PREFIX \
      --with-libtiff=$PREFIX --with-rename-internal-libtiff-symbols \
      --with-geotiff=$PREFIX --with-rename-internal-libgeotiff-symbols \
      --with-crypto=yes \
      --with-curl \
      --with-liblzma=yes \
      --with-expat=$PREFIX \
      --with-geos=$PREFIX/bin/geos-config \
      --with-openjpeg=$PREFIX \
      --with-jpeg=$PREFIX \
      --with-netcdf=$PREFIX \
      --with-png=$PREFIX \
      --with-sqlite3 \
      --with-xml2=yes \
      --with-webp=$PREFIX \
      --with-zstd=$PREFIX \
      --with-threads=yes \
      --without-cfitsio \
      --without-ecw \
      --without-fme \
      --without-freexl \
      --without-jpeg12 \
      --without-gif \
      --without-gnm \
      --without-lerc \
      --without-pcraster \
      --without-pcidsk \
  && make -j4 --quiet && make install \
  && rm -rf $BUILD_DIR/gdal

  # Add this back when we'll figure how to setup libdeflate correctly
  #--with-libdeflate=$PREFIX \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment