-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·162 lines (152 loc) · 3.9 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
usage () {
echo ""
echo "usage: $0 [-h|--help] [-p|--prefix <INSTALL-PREFIX>] [-b|--build-type <BUILD-TYPE>] [-s|--static] [-t|--threads]"
echo " -h|--help Show help message and exit."
echo " -s|--static Build statically linked binaries. Default: dynamic."
echo " -t|--threads Compile with multithreading. Default: No multithreading."
echo " -p|--prefix Install path. Default: './build'."
echo " -b|--build-type Build type. Options: debug, release, relwithdebinfo."
echo " Default: relwithdebinfo."
echo ""
}
build_ecoevolity () {
cmake_args=$@
if [ -n "$ECOEVOLITY_BASE_DIR" ]
then
base_dir="$ECOEVOLITY_BASE_DIR"
else
echo "ERROR: ECOEVOLITY_BASE_DIR was not defined prior to calling "
echo "build_ecoevolity."
exit 1
fi
if [ -n "$ECOEVOLITY_BUILD_DIR" ]
then
build_dir="$ECOEVOLITY_BUILD_DIR"
else
build_dir="${base_dir}/build"
fi
if [ -d "$build_dir" ]
then
echo "ERROR: build directory '$build_dir' already exists."
echo "To reconfigure, please remove this directory and re-run this script."
exit 1
else
mkdir -p "$build_dir"
fi
# configure make files and build
cd "$build_dir"
echo "Configuring make files..."
echo "${base_dir}/ $cmake_args" | xargs cmake || exit 1
echo "Building..."
make clean || exit 1
make -j $COMPILETHREADS || exit 1
echo "Installing..."
make install || exit 1
cd "$base_dir"
echo "Done!"
}
# get location of script
ECOEVOLITY_BASE_DIR=""
this_dir=`dirname "$0"`
if [ "$this_dir" = "." ]
then
export ECOEVOLITY_BASE_DIR="$(pwd)"
else
cd "$this_dir"
export ECOEVOLITY_BASE_DIR="$(pwd)"
fi
export ECOEVOLITY_BUILD_DIR="${ECOEVOLITY_BASE_DIR}/build"
# make sure submodules are here and up to date
# git submodule init
# git submodule update
# process args
extra_args=""
static=""
threads=""
absolute_root_size=""
install_prefix="$ECOEVOLITY_BUILD_DIR"
universal_mac_build=""
linux_dist_build=""
mbit=64
build_type="RELWITHDEBINFO"
COMPILETHREADS="4"
if [ "$(echo "$@" | grep -c "=")" -gt 0 ]
then
echo "ERROR: Do not use '=' for arguments. For example, use"
echo "'--prefix /usr/local' instead of '--prefix=/usr/local'."
exit 1
fi
while [ "$1" != "" ]
do
case $1 in
-h| --help)
usage
exit
;;
-p| --prefix)
shift
install_prefix="$1"
;;
-b| --build-type)
shift
build_type="$1"
;;
-s| --static)
static=1
;;
-t| --threads)
threads=1
;;
-j)
shift
COMPILETHREADS="$1"
;;
-m)
shift
mbit="$1"
;;
--universal-mac-build)
universal_mac_build=1
static=1
;;
--linux-dist-build)
linux_dist_build=1
static=1
;;
--absolute-root-size)
absolute_root_size=1
;;
* )
extra_args="$extra_args $1"
esac
shift
done
export COMPILETHREADS
args="-DCMAKE_BUILD_TYPE=${build_type} -DFORCE_BUNDLED_NCL=yes -DFORCE_BUNDLED_YAML_CPP=yes -DCMAKE_INSTALL_PREFIX=${install_prefix}"
if [ -n "$static" ]
then
args="${args} -DSTATIC_LINKING=yes"
fi
if [ -n "$threads" ]
then
args="${args} -DBUILD_WITH_THREADS=yes"
fi
if [ -n "$absolute_root_size" ]
then
args="${args} -DBUILD_WITH_ABSOLUTE_ROOT_SIZE=yes"
fi
if [ -n "$extra_args" ]
then
args="${args} ${extra_args}"
fi
if [ -n "$linux_dist_build" ]
then
args="${args} -DCMAKE_CXX_FLAGS=-m${mbit} -DCMAKE_LD_FLAGS=-m${mbit}"
fi
if [ -n "$universal_mac_build" ]
then
args="${args} -DCMAKE_CXX_FLAGS=\"-arch ppc -arch i386 -arch x86_64\""
fi
# check for build directory
build_ecoevolity $args