forked from arras-energy/gridlabd-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gldmake
executable file
·96 lines (88 loc) · 2.46 KB
/
gldmake
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
#!/bin/bash
#
# Syntax:
# gldmake [-h|--help] [TARGET]
#
# This script will automatically choose the correct build process
# given the status of the source tree.
#
# Option 1: new build --> autoreconf -isf && ./configure && make ...
#
# Option 2: recent build --> make ...
#
# Option 3: old build --> make reconfigure && make ...
#
# When run without command line options an interactive menu is used
#
function nprocs ()
{
OS=$(uname -s)
if [ "$OS" == "Linux" ]; then
nproc --all
elif [ "$OS" == "Darwin" ]; then
sysctl -n hw.ncpu
else
getconf _NPROCESSORS_ONLN
fi
}
OPTIONS="-j$(( $(nprocs)*3 ))"
if [ $# -gt 0 ]; then
SOURCE=$(./build-aux/version.sh --install)
TARGET=$(gridlabd --version=install)
if [ "$1" == "-h" -o "$1" == "--help" ]; then
echo "Syntax: $0 [-h|--help] [TARGET]"
exit
elif [ ! -f Makefile ]; then
echo "$0: no makefile --> first time build"
COMMAND='autoreconf -isf && ./configure && make $OPTIONS $*'
elif [ "$SOURCE" != "$TARGET" ]; then
echo "$0: build and install versions match --> simple rebuild"
COMMAND='make reconfigure && make $OPTIONS $*'
else
echo "$0: build and install versions do not match --> full rebuild"
COMMAND='make $OPTIONS $*'
fi
echo "$COMMAND $*"
echo "$COMMAND $*" | bash
exit
fi
DEFAULT=-1
COMMANDS=(autoreconf+-isf ./configure make+${OPTIONS// /+}+system make+${OPTIONS// /+}+install make+${OPTIONS// /+} gridlabd+-T+0+--validate gridlabd+version+list gridlabd+version+set make+clean make+distclean exit)
TESTS=(configure Makefile)
echo ""
echo "HiPAS GridLAB-D Build Manager Version 1.0"
while [ true ]; do
export PATH=$SOURCE:/usr/local/bin:/usr/bin:/bin
echo ""
echo "Main menu"
echo "---------"
echo ""
N=0
for COMMAND in ${COMMANDS[*]}; do
echo "$N. Run '${COMMAND//+/ }'"
N=$(($N+1))
done
echo ""
DEFAULT=0
for TEST in ${TESTS[*]}; do
if [ ! -f $TEST ]; then
break
else
DEFAULT=$(($DEFAULT+1))
fi
done
SOURCE=$(./build-aux/version.sh --install)
TARGET=$(gridlabd --version=install 2>/dev/null || echo "(none found)")
echo "Configured version: $SOURCE"
echo "Target version: $TARGET"
if [ "$TARGET" != "$SOURCE" -a $DEFAULT -gt 1 ]; then
echo ""
echo "WARNING: 'make' will fail when target and source versions do not match; if you have not already done so, command '9' will fix this"
DEFAULT=9
fi
echo ""
read -p "Selection: [$DEFAULT] " ANS
COMMAND=${COMMANDS[${ANS:-DEFAULT}]//+/ }
echo "Running '${COMMAND}'..."
eval ${COMMAND} || echo "WARNING: '${COMMAND}' failed!"
done