-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·147 lines (141 loc) · 3.22 KB
/
build.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
#!/bin/bash
PREVDIR=`pwd`
SCRIPTDIR=`cd \`dirname $0\` && pwd`
BUILDARGS=
CLEAN=
FORCE=
PACKAGE=
CONF="Release"
TOOL="$0"
VERSION=
BUILDNUMBER=
FULLVERSION=
cd "$SCRIPTDIR"
return_to_previous_directory()
{
cd "$PREVDIR"
}
trap return_to_previous_directory INT TERM EXIT
check_for_tool_in_path()
{
if [ -z "`which $1 2>/dev/null`" ]; then
echo "Unable to find $1 in $PATH"
echo "Consider getting it from homebrew or apt?"
exit 1
fi
}
check_cmake_version()
{
CMAKEVER=`cmake --version | head -1 | cut -f3 -d' '`
echo "CMake $CMAKEVER found"
CMAKEMAJOR=`echo $CMAKEVER | cut -f1 -d.`
CMAKEMINOR=`echo $CMAKEVER | cut -f2 -d.`
CMAKEMICRO=`echo $CMAKEVER | cut -f3 -d.`
if [ $CMAKEMAJOR -lt 3 -o $CMAKEMINOR -lt 1 ]; then
echo "CMake version 3.8.2 or greater is required"
exit 1
fi
}
check_for_prerequisites()
{
check_for_tool_in_path cmake
check_for_tool_in_path dos2unix
check_cmake_version
}
set_version()
{
echo "Setting version information for build"
cp $SCRIPTDIR/version.txt /tmp/version.txt
dos2unix /tmp/version.txt
VERSION=`cat /tmp/version.txt`
cp $SCRIPTDIR/build.txt /tmp/build.txt
dos2unix /tmp/build.txt
BUILDNUMBER=`cat /tmp/build.txt`
FULLVERSION=`echo $VERSION.$BUILDNUMBER`
echo "FULLVERSION: $FULLVERSION"
}
configure()
{
if [ ! -f "$SCRIPTDIR/Build/CMakeCache.txt" ]; then
set -e
rm -rf "$SCRIPTDIR/Build"
mkdir -p "$SCRIPTDIR/Build"
cd "$SCRIPTDIR/Build"
cmake ../ -G "Unix Makefiles"
set +e
fi
}
build()
{
set -e
cd "$SCRIPTDIR/Build"
make
if [ $? -eq 0 ]; then
echo "Build succeeded -- Artifacts at $SCRIPTDIR/Build/"
else
echo "Build failed!"
exit 1
fi
make test
if [ $? -eq 0 ]; then
echo "Unit tests succeeded"
else
echo "Unit tests failed!"
exit 1
fi
if [ "$PACKAGE" = "true" ]; then
echo "TODO: Code Signing ..."
fi
cd "$SCRIPTDIR"
set +e
}
package()
{
set -e
echo "TODO: Packaging ..."
set +e
}
print_usage()
{
echo "USAGE: $TOOL [-c] [-d] [-f] [-p] [-h]"
echo "Build Magenta using CMake and Makefiles"
echo " -c Just clean up current build files"
echo " -d Build with debug configuration"
echo " -f Force a reconfigure and a rebuild"
echo " -h Print this message and exit"
echo " -p Build the package after successful build"
exit 1
}
# Main Script
argv=`getopt cdfhp "$@" 2>/dev/null`
if [ $? -ne 0 ]; then
echo "Invalid option(s)!"
print_usage
fi
set -- $argv
while [ $# -gt 0 ]; do
case $1 in
-c ) CLEAN="true"; shift ;;
-f ) FORCE="true"; shift ;;
-d ) CONF="Debug"; shift ;;
-h ) HELP="true"; shift ;;
-p ) PACKAGE="true"; shift ;;
-- ) shift; break ;;
* ) echo "Invalid option(s)!"; print_usage; ;;
esac
done
if [ "$HELP" = "true" ]; then
print_usage
fi
if [ "$FORCE" = "true" -o "$CLEAN" = "true" ]; then
rm -rf "$SCRIPTDIR/Build"
echo "Removed files at $SCRIPTDIR/Build"
if [ "$CLEAN" = "true" ]; then exit 0; fi
fi
check_for_prerequisites
set_version
configure
build
if [ "$PACKAGE" = "true" ]; then
package
fi