|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# make.sh |
| 4 | +# |
| 5 | +# Copyright (C) 2020 Kristofer Berggren |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# See LICENSE for redistribution information. |
| 9 | + |
| 10 | +# exiterr |
| 11 | +exiterr() |
| 12 | +{ |
| 13 | + >&2 echo "${1}" |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +# process arguments |
| 18 | +DEPS="0" |
| 19 | +BUILD="0" |
| 20 | +TESTS="0" |
| 21 | +DOC="0" |
| 22 | +INSTALL="0" |
| 23 | +case "${1%/}" in |
| 24 | + deps) |
| 25 | + DEPS="1" |
| 26 | + ;; |
| 27 | + |
| 28 | + build) |
| 29 | + BUILD="1" |
| 30 | + ;; |
| 31 | + |
| 32 | + test*) |
| 33 | + BUILD="1" |
| 34 | + TESTS="1" |
| 35 | + ;; |
| 36 | + |
| 37 | + doc) |
| 38 | + BUILD="1" |
| 39 | + DOC="1" |
| 40 | + ;; |
| 41 | + |
| 42 | + install) |
| 43 | + BUILD="1" |
| 44 | + INSTALL="1" |
| 45 | + ;; |
| 46 | + |
| 47 | + all) |
| 48 | + DEPS="1" |
| 49 | + BUILD="1" |
| 50 | + TESTS="1" |
| 51 | + DOC="1" |
| 52 | + INSTALL="1" |
| 53 | + ;; |
| 54 | + |
| 55 | + *) |
| 56 | + echo "usage: make.sh <deps|build|tests|doc|install|all>" |
| 57 | + echo " deps - install project dependencies" |
| 58 | + echo " build - perform build" |
| 59 | + echo " tests - perform build and run tests" |
| 60 | + echo " doc - perform build and generate documentation" |
| 61 | + echo " install - perform build and install" |
| 62 | + echo " all - perform all actions above" |
| 63 | + exit 1 |
| 64 | + ;; |
| 65 | +esac |
| 66 | + |
| 67 | +# deps |
| 68 | +if [[ "${DEPS}" == "1" ]]; then |
| 69 | + OS="$(uname)" |
| 70 | + if [ "${OS}" == "Linux" ]; then |
| 71 | + DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" |
| 72 | + if [[ "${DISTRO}" == "Ubuntu" ]]; then |
| 73 | + pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." |
| 74 | + else |
| 75 | + exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." |
| 76 | + fi |
| 77 | + elif [ "${OS}" == "Darwin" ]; then |
| 78 | + pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." |
| 79 | + else |
| 80 | + exiterr "deps failed (unsupported os ${OS}), exiting." |
| 81 | + fi |
| 82 | +fi |
| 83 | + |
| 84 | +# build |
| 85 | +if [[ "${BUILD}" == "1" ]]; then |
| 86 | + mkdir -p build && cd build && cmake .. && make && cd .. || exiterr "build failed, exiting." |
| 87 | +fi |
| 88 | + |
| 89 | +# tests |
| 90 | +if [[ "${TESTS}" == "1" ]]; then |
| 91 | + cd build && ctest --output-on-failure && cd .. || exiterr "tests failed, exiting." |
| 92 | +fi |
| 93 | + |
| 94 | +# doc |
| 95 | +if [[ "${DOC}" == "1" ]]; then |
| 96 | + true || exiterr "doc failed, exiting." |
| 97 | +fi |
| 98 | + |
| 99 | +# install |
| 100 | +if [[ "${INSTALL}" == "1" ]]; then |
| 101 | + OS="$(uname)" |
| 102 | + if [ "${OS}" == "Linux" ]; then |
| 103 | + cd build && sudo make install && cd .. || exiterr "install failed (linux), exiting." |
| 104 | + elif [ "${OS}" == "Darwin" ]; then |
| 105 | + cd build && make install && cd .. || exiterr "install failed (mac), exiting." |
| 106 | + else |
| 107 | + exiterr "install failed (unsupported os ${OS}), exiting." |
| 108 | + fi |
| 109 | +fi |
| 110 | + |
| 111 | +# exit |
| 112 | +exit 0 |
0 commit comments