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