|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Build the lastest GMT source codes. |
| 4 | +# |
| 5 | +# Usage: |
| 6 | +# |
| 7 | +# 1. Install GMT dependencies following the [wiki](https://github.com/GenericMappingTools/gmt/wiki) |
| 8 | +# 2. curl https://raw.githubusercontent.com/GenericMappingTools/gmt/master/ci/build-gmt-master.sh | bash |
| 9 | +# |
| 10 | +# Environmental variables that affect the building process: |
| 11 | +# |
| 12 | +# - GMT_INSTALL_DIR: GMT installation location |
| 13 | +# |
| 14 | + |
| 15 | +set -x -e |
| 16 | + |
| 17 | +# Following variables can be modified via environment variables |
| 18 | +GMT_INSTALL_DIR=${GMT_INSTALL_DIR:-${HOME}/gmt-install-dir} |
| 19 | + |
| 20 | +# General settings |
| 21 | +GSHHG_VERSION="2.3.7" |
| 22 | +DCW_VERSION="1.1.4" |
| 23 | +GSHHG="gshhg-gmt-${GSHHG_VERSION}" |
| 24 | +DCW="dcw-gmt-${DCW_VERSION}" |
| 25 | +EXT="tar.gz" |
| 26 | + |
| 27 | +cwd=${PWD} |
| 28 | +# 1. Create temporary directory for building |
| 29 | +GMT_BUILD_TMPDIR=$(mktemp -d ${TMPDIR:-/tmp/}gmt.XXXXXX) |
| 30 | +cd ${GMT_BUILD_TMPDIR} |
| 31 | + |
| 32 | +# 2. Download GMT, GSHHG and DCW from GitHub |
| 33 | +git clone --depth 1 https://github.com/GenericMappingTools/gmt.git gmt |
| 34 | +curl -SLO https://github.com/GenericMappingTools/gshhg-gmt/releases/download/${GSHHG_VERSION}/${GSHHG}.${EXT} |
| 35 | +curl -SLO https://github.com/GenericMappingTools/dcw-gmt/releases/download/${DCW_VERSION}/${DCW}.${EXT} |
| 36 | + |
| 37 | +# 3. Extract tarballs |
| 38 | +tar -xvf ${GSHHG}.${EXT} |
| 39 | +tar -xvf ${DCW}.${EXT} |
| 40 | +mv ${GSHHG} gmt/share/gshhg-gmt |
| 41 | +mv ${DCW} gmt/share/dcw-gmt |
| 42 | + |
| 43 | +# 4. Configure GMT |
| 44 | +cd gmt/ |
| 45 | +cat > cmake/ConfigUser.cmake << EOF |
| 46 | +set (CMAKE_INSTALL_PREFIX "${GMT_INSTALL_DIR}") |
| 47 | +set (CMAKE_C_FLAGS "-Wall -Wdeclaration-after-statement \${CMAKE_C_FLAGS}") |
| 48 | +set (CMAKE_C_FLAGS "-Wextra \${CMAKE_C_FLAGS}") |
| 49 | +EOF |
| 50 | + |
| 51 | +# 5. Build and install GMT |
| 52 | +mkdir build |
| 53 | +cd build |
| 54 | +cmake .. |
| 55 | +make |
| 56 | +make install |
| 57 | + |
| 58 | +# 6. Cleanup |
| 59 | +cd ${cwd} |
| 60 | +rm -rf ${GMT_BUILD_TMPDIR} |
| 61 | + |
| 62 | +set -x -e |
0 commit comments