-
Notifications
You must be signed in to change notification settings - Fork 13
/
make.sh
executable file
·156 lines (137 loc) · 3.46 KB
/
make.sh
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
#!/usr/bin/env bash
# make.sh
#
# Copyright (C) 2020 Kristofer Berggren
# All rights reserved.
#
# See LICENSE for redistribution information.
# exiterr
exiterr()
{
>&2 echo "${1}"
exit 1
}
# process arguments
DEPS="0"
BUILD="0"
DBGBUILD="0"
TESTS="0"
DBGTESTS="0"
DOC="0"
INSTALL="0"
case "${1%/}" in
deps)
DEPS="1"
;;
build)
BUILD="1"
;;
dbgbuild)
DBGBUILD="1"
;;
test*)
BUILD="1"
TESTS="1"
;;
dbgtest*)
DBGBUILD="1"
DBGTESTS="1"
;;
doc)
BUILD="1"
DOC="1"
;;
install)
BUILD="1"
INSTALL="1"
;;
all)
DEPS="1"
BUILD="1"
TESTS="1"
DOC="1"
INSTALL="1"
;;
*)
echo "usage: make.sh <deps|build|tests|doc|install|all>"
echo " deps - install project dependencies"
echo " build - perform build"
echo " dbgbuild - perform debug build"
echo " tests - perform build and run tests"
echo " dbgtests - perform debug build and run tests"
echo " doc - perform build and generate documentation"
echo " install - perform build and install"
echo " all - perform all actions above"
exit 1
;;
esac
# deps
if [[ "${DEPS}" == "1" ]]; then
OS="$(uname)"
if [ "${OS}" == "Linux" ]; then
DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')"
if [[ "${DISTRO}" == "Ubuntu" ]]; then
true || exiterr "deps failed (linux), exiting."
else
exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting."
fi
elif [ "${OS}" == "Darwin" ]; then
brew install pidof || exiterr "deps failed (mac), exiting."
else
exiterr "deps failed (unsupported os ${OS}), exiting."
fi
fi
# build
if [[ "${BUILD}" == "1" ]]; then
OS="$(uname)"
MAKEARGS=""
if [ "${OS}" == "Linux" ]; then
MAKEARGS="-j$(nproc)"
elif [ "${OS}" == "Darwin" ]; then
MAKEARGS="-j$(sysctl -n hw.ncpu)"
fi
mkdir -p build && cd build && cmake .. && make ${MAKEARGS} && cd .. || exiterr "build failed, exiting."
fi
# dbgbuild
if [[ "${DBGBUILD}" == "1" ]]; then
OS="$(uname)"
MAKEARGS=""
if [ "${OS}" == "Linux" ]; then
MAKEARGS="-j$(nproc)"
elif [ "${OS}" == "Darwin" ]; then
MAKEARGS="-j$(sysctl -n hw.ncpu)"
fi
mkdir -p dbgbuild && cd dbgbuild && cmake -DCMAKE_BUILD_TYPE=Debug .. && make ${MAKEARGS} && cd .. || exiterr "dbgbuild failed, exiting."
fi
# tests
if [[ "${TESTS}" == "1" ]]; then
cd build && ctest --output-on-failure && cd .. || exiterr "tests failed, exiting."
fi
# dbgtests
if [[ "${DBGTESTS}" == "1" ]]; then
cd dbgbuild && ctest --output-on-failure && cd .. || exiterr "dbgtests failed, exiting."
fi
# doc
if [[ "${DOC}" == "1" ]]; then
if [[ -x "$(command -v help2man)" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
SED="gsed -i"
else
SED="sed -i"
fi
cd src && help2man -n "measure stack usage in applications" -N -o stackusage.1 ./stackusage && cd .. && ${SED} "s/\.\\\\\" DO NOT MODIFY THIS FILE\! It was generated by help2man.*/\.\\\\\" DO NOT MODIFY THIS FILE\! It was generated by help2man./g" src/stackusage.1 || exiterr "doc failed, exiting."
fi
fi
# install
if [[ "${INSTALL}" == "1" ]]; then
OS="$(uname)"
if [ "${OS}" == "Linux" ]; then
cd build && sudo make install && cd .. || exiterr "install failed (linux), exiting."
elif [ "${OS}" == "Darwin" ]; then
cd build && make install && cd .. || exiterr "install failed (mac), exiting."
else
exiterr "install failed (unsupported os ${OS}), exiting."
fi
fi
# exit
exit 0