-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathautogen.sh
More file actions
executable file
·135 lines (123 loc) · 4.27 KB
/
Copy pathautogen.sh
File metadata and controls
executable file
·135 lines (123 loc) · 4.27 KB
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
#!/usr/bin/env bash
#
# Build Scripts
# Copyright (C) 2002-2026 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 -euo pipefail
CMAKE_OPTIONS=""
COMMAND=""
CORES=0
while [ $# -gt 0 ] ; do
if [[ "$1" =~ ^(-|--)use-clang$ ]] ; then
# Use these settings for CLang:
export CXX=clang++
export CC=clang
elif [[ "$1" =~ ^(-|--)use-clang-scan-build$ ]] ; then
# Use these settings for CLang:
export CXX=clang++
export CC=clang
# Ensure build with CLang Static Analyzer
mkdir -p scan-build-reports
COMMAND="scan-build -o scan-build-reports"
elif [[ "$1" =~ ^(-|--)use-gcc$ ]] ; then
# Use these settings for GCC:
export CXX=g++
export CC=gcc
elif [[ "$1" =~ ^(-|--)use-gcc-analyzer$ ]] ; then
# Use these settings for GCC:
export CXX=g++
export CC=gcc
export CFLAGS=-fanalyzer
export CXXFLAGS=-fanalyzer
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON"
elif [[ "$1" =~ ^(-|--)debug$ ]] ; then
# Enable debugging build:
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug"
elif [[ "$1" =~ ^(-|--)release$ ]] ; then
# Enable debugging build:
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Release"
elif [[ "$1" =~ ^(-|--)release-with-debinfo$ ]] ; then
# Enable debugging build:
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
elif [[ "$1" =~ ^(-|--)verbose$ ]] ; then
# Enable verbose Makefile:
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON"
elif [[ "$1" =~ ^(-|--)cores ]] ; then
if [[ ! "$2" =~ ^[0-9]+$ ]] ; then
echo >&2 "ERROR: Number of cores must be an integer number!"
exit 1
fi
CORES="$2"
shift
elif [ "$1" == "--" ] ; then
shift
break
else
echo >&2 "Usage: autogen.sh [--use-clang|--use-clang-scan-build|--use-gcc|--use-gcc-analyzer] [--debug|--release|--release-with-debinfo] [--cores N] [--verbose] -- (further CMake/Configure options)"
exit 1
fi
shift
done
UNAME="$(uname)"
case "${UNAME}" in
Linux)
installPrefix="/usr"
;;
NetBSD)
installPrefix="/usr/pkg"
;;
*)
installPrefix="/usr/local"
;;
esac
# ====== Configure with CMake ===============================================
if [ -e CMakeLists.txt ] ; then
rm -f CMakeCache.txt
if [ $# -gt 0 ] ; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} $*"
fi
echo "CMake options:${CMAKE_OPTIONS} . -DCMAKE_INSTALL_PREFIX=\"${installPrefix}\""
# shellcheck disable=SC2048,SC2086
${COMMAND} cmake ${CMAKE_OPTIONS} . -DCMAKE_INSTALL_PREFIX="${installPrefix}"
# ====== Configure with AutoConf/AutoMake ===================================
elif [ -e bootstrap ] ; then
./bootstrap
# shellcheck disable=SC2068
./configure $@
else
echo >&2 "ERROR: Failed to configure with CMake or AutoMake/AutoConf!"
exit 1
fi
# ====== Obtain number of cores =============================================
if [ "${CORES}" -lt 1 ] ; then
if [ "${UNAME}" == "Linux" ] ; then
CORES="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1")"
elif [ "${UNAME}" == "FreeBSD" ] ; then
CORES="$(sysctl -n hw.ncpu || echo "1")"
elif [ "${UNAME}" == "NetBSD" ] || [ "${UNAME}" == "OpenBSD" ] ; then
CORES="$(sysctl -n hw.ncpuonline || echo "1")"
elif [ "${UNAME}" == "Darwin" ] ; then
CORES="$(sysctl -n machdep.cpu.core_count)"
else
CORES=1
fi
echo "This system has ${CORES} cores!"
fi
# ====== Build ==============================================================
echo "Starting build using up to ${CORES} cores ..."
${COMMAND} make -j"${CORES}"