| 1 | #!/usr/bin/env bash |
| 2 | # ========================================================================== |
| 3 | # ____ _ _ _ _____ _ |
| 4 | # | __ ) _ _(_) | __| | |_ _|__ ___ | |___ |
| 5 | # | _ \| | | | | |/ _` |_____| |/ _ \ / _ \| / __| |
| 6 | # | |_) | |_| | | | (_| |_____| | (_) | (_) | \__ \ |
| 7 | # |____/ \__,_|_|_|\__,_| |_|\___/ \___/|_|___/ |
| 8 | # |
| 9 | # --- Build-Tools --- |
| 10 | # https://www.nntb.no/~dreibh/system-tools/ |
| 11 | # ========================================================================== |
| 12 | # |
| 13 | # GitHub Actions Scripts |
| 14 | # Copyright (C) 2021-2026 by Thomas Dreibholz |
| 15 | # |
| 16 | # This program is free software: you can redistribute it and/or modify |
| 17 | # it under the terms of the GNU General Public License as published by |
| 18 | # the Free Software Foundation, either version 3 of the License, or |
| 19 | # (at your option) any later version. |
| 20 | # |
| 21 | # This program is distributed in the hope that it will be useful, |
| 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | # GNU General Public License for more details. |
| 25 | # |
| 26 | # You should have received a copy of the GNU General Public License |
| 27 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | # |
| 29 | # Contact: [email protected] |
| 30 | |
| 31 | # Bash options: |
| 32 | set -euo pipefail |
| 33 | |
| 34 | |
| 35 | # ====== Check arguments ==================================================== |
| 36 | if [ $# -lt 1 ] ; then |
| 37 | echo >&2 "Usage: $0 compile|package ..." |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | |
| 42 | # ====== Check/set environment variables ==================================== |
| 43 | DIRNAME="$(dirname "$0")" |
| 44 | UNAME="$(uname)" |
| 45 | if [ ! -e /etc/os-release ] ; then |
| 46 | echo >&2 "ERROR: /etc/os-release does not exist!" |
| 47 | exit 1 |
| 48 | fi |
| 49 | . /etc/os-release |
| 50 | |
| 51 | |
| 52 | # ###### Configure ########################################################## |
| 53 | |
| 54 | # ====== Configure with CMake =============================================== |
| 55 | if [ -e CMakeLists.txt ] ; then |
| 56 | cmake . |
| 57 | |
| 58 | # ====== Configure with autoconf/automake (via bootstrap script) ============ |
| 59 | elif [ -e configure.ac ] || [ -e configure.in ] ; then |
| 60 | if [ -e autogen.sh ] ; then |
| 61 | ./autogen.sh |
| 62 | elif [ -e bootstrap ] ; then |
| 63 | ./bootstrap |
| 64 | ./configure |
| 65 | else |
| 66 | ./configure |
| 67 | fi |
| 68 | else |
| 69 | echo >&2 "WARNING: No build system detected. Trying to just call \"make\" ..." |
| 70 | fi |
| 71 | |
| 72 | # ====== Obtain MAKEFLAGS to utilise all cores ============================== |
| 73 | if [ "${UNAME}" == "Linux" ] ; then |
| 74 | cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || true) |
| 75 | MAKEFLAGS="-j${cores}" |
| 76 | elif [ "${UNAME}" == "FreeBSD" ] ; then |
| 77 | cores=$(sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2 | tr -d ' ') |
| 78 | MAKEFLAGS="-j${cores}" |
| 79 | else |
| 80 | MAKEFLAGS="" |
| 81 | fi |
| 82 | |
| 83 | |
| 84 | # ###### Perform builds ##################################################### |
| 85 | while [ $# -gt 0 ] ; do |
| 86 | TOOL="$1" |
| 87 | shift |
| 88 | |
| 89 | |
| 90 | # ====== Compile ========================================================= |
| 91 | if [ "${TOOL}" == "compile" ] ; then |
| 92 | |
| 93 | MAKEFLAGS=${MAKEFLAGS} make # VERBOSE=1 |
| 94 | |
| 95 | |
| 96 | # # ====== Coverity Scan =================================================== |
| 97 | # elif [ "${TOOL}" == "coverity" ] ; then |
| 98 | # # ------ Build -------------------------------------------------------- |
| 99 | # cd coverity |
| 100 | # export PATH="coverity/$(ls -d cov*)/bin:$PATH" |
| 101 | # cd .. |
| 102 | # |
| 103 | # MAKEFLAGS=${MAKEFLAGS} cov-build --dir cov-int make |
| 104 | # tar czf coverity-results.tar.gz cov-int |
| 105 | # ls -l coverity-results.tar.gz |
| 106 | # |
| 107 | # # ------ Upload results ----------------------------------------------- |
| 108 | # if [ "${TRAVIS_BRANCH}" == "${COVERITY_SCAN_BRANCH}" ] ; then |
| 109 | # curl --form token=${COVERITY_SCAN_TOKEN} \ |
| 110 | # --form email=${COVERITY_SCAN_NOTIFICATION_EMAIL} \ |
| 111 | # --form [email protected] \ |
| 112 | # --form version="master branch head" \ |
| 113 | # --form description="$(git log -1|head -1)" \ |
| 114 | # https://scan.coverity.com/builds?project=${COVERITY_PROJECT} |
| 115 | # CURL_RESULT=$? |
| 116 | # echo "curl returned ${CURL_RESULT}" |
| 117 | # if [ $CURL_RESULT -ne 0 ]; then |
| 118 | # echo >&2 "ERROR: Upload to Coverity Scan failed; curl returned ${CURL_RESULT}!" |
| 119 | # exit 1 |
| 120 | # fi |
| 121 | # else |
| 122 | # echo >&2 "###### NOTE: This branch \"${TRAVIS_BRANCH}\" is not the scan branch \"${COVERITY_SCAN_BRANCH}\"! Skipping upload! ######" |
| 123 | # fi |
| 124 | |
| 125 | |
| 126 | # ====== Package ======================================================= |
| 127 | elif [ "${TOOL}" == "package" ] ; then |
| 128 | |
| 129 | if [ ! -v OS ] || [ "${OS}" == "" ] ; then |
| 130 | OS="${ID}" |
| 131 | fi |
| 132 | if [ ! -v ARCH ] || [ "${ARCH}" == "" ] ; then |
| 133 | ARCH="$(uname -m)" |
| 134 | fi |
| 135 | |
| 136 | if [ "${OS}" == "ubuntu" ] || [ "${OS}" == "debian" ] ; then |
| 137 | architecture="${ARCH//x86_64/amd64}" |
| 138 | if [ ! -v DIST ] || [ "${DIST}" == "" ] ; then |
| 139 | distribution="${VERSION_CODENAME}" |
| 140 | else |
| 141 | distribution="${DIST}" |
| 142 | fi |
| 143 | "${DIRNAME}"/build-tool build-deb "${distribution}" --skip-signing --architecture="${architecture}" |
| 144 | |
| 145 | # ====== Fedora ========================================================== |
| 146 | elif [ "${OS}" == "fedora" ] ; then |
| 147 | |
| 148 | architecture="${ARCH}" |
| 149 | if [ ! -v DIST ] || [ "${DIST}" == "" ] ; then |
| 150 | distribution="${VERSION_ID}" |
| 151 | else |
| 152 | distribution="${DIST}" |
| 153 | fi |
| 154 | LD_PRELOAD=/usr/lib64/nosync/nosync.so \ |
| 155 | "${DIRNAME}"/build-tool build-rpm "fedora-${distribution}" --skip-signing --architecture="${architecture}" |
| 156 | |
| 157 | # ====== Unknown ========================================================= |
| 158 | else |
| 159 | echo >&2 "ERROR: Unsupported distribution ${ID} for packaging!" |
| 160 | exit 1 |
| 161 | fi |
| 162 | |
| 163 | |
| 164 | # ====== Invalid setting ================================================= |
| 165 | else |
| 166 | echo >&2 "ERROR: Invalid setting of TOOL=${TOOL}!" |
| 167 | exit 1 |
| 168 | fi |
| 169 | |
| 170 | done |