eosio_build.sh 10.1 KB
Newer Older
1 2
#!/bin/bash
##########################################################################
3
# This is the EOSIO automated install script for Linux and Mac OS.
4 5 6 7 8
# This file was downloaded from https://github.com/EOSIO/eos
#
# Copyright (c) 2017, Respective Authors all rights reserved.
#
# After June 1, 2018 this software is available under the following terms:
9
# 
10
# The MIT License
11
# 
12 13 14 15 16 17
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
18
# 
19 20
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
21
# 
22 23 24 25 26 27 28 29
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
30
# https://github.com/EOSIO/eos/blob/master/LICENSE
31
##########################################################################
32

33 34
	CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
	if [ "${CWD}" != "${PWD}" ]; then
35
		printf "\\n\\tPlease cd into directory %s to run this script.\\n \\tExiting now.\\n\\n" "${CWD}"
36 37
		exit 1
	fi
38
	if [ -f "${PWD}/CMakeCache.txt" ]; then
39
		printf "\\n\\tPlease remove file %s/CMakeCache.txt before building EOSIO.\\n \\tExiting now.\\n\\n" "${PWD}"
40 41
		exit 1
	fi
42 43 44

   	function usage()
   	{ 
45
		printf "\\tUsage: %s \\n\\t[Build Option -o <Debug|Release|RelWithDebInfo|MinSizeRel>] \\n\\t[CodeCoverage -c ] \\n\\t[Doxygen -d] \\n\\t[CoreSymbolName -s <1-7 characters>]\\n\\n" "$0" 1>&2
46 47 48
		exit 1
	}

49
	ARCH=$( uname )
50 51
	BUILD_DIR="${PWD}/build"
	CMAKE_BUILD_TYPE=Release
52
	DISK_MIN=20
53 54
	DOXYGEN=false
	ENABLE_COVERAGE_TESTING=false
55
	CORE_SYMBOL_NAME="EOS"
56
	TEMP_DIR="/tmp"
57
	TIME_BEGIN=$( date -u +%s )
58
	VERSION=1.2
59

60
	txtbld=$(tput bold)
61 62 63
	bldred=${txtbld}$(tput setaf 1)
	txtrst=$(tput sgr0)

64
	if [ $# -ne 0 ]; then
65
		while getopts ":cdo:s:" opt; do
66 67
			case "${opt}" in
				o )
68 69
					options=( "Debug" "Release" "RelWithDebInfo" "MinSizeRel" )
					if [[ "${options[*]}" =~ "${OPTARG}" ]]; then
70
						CMAKE_BUILD_TYPE="${OPTARG}"
71
					else
72
						printf "\\n\\tInvalid argument: %s\\n" "${OPTARG}" 1>&2
73 74
						usage
						exit 1
75 76 77 78 79 80 81 82
					fi
				;;
				c )
					ENABLE_COVERAGE_TESTING=true
				;;
				d )
					DOXYGEN=true
				;;
83 84 85 86 87 88 89 90 91
				s)
					if [ "${#OPTARG}" -gt 6 ] || [ -z "${#OPTARG}" ]; then
						printf "\\n\\tInvalid argument: %s\\n" "${OPTARG}" 1>&2
						usage
						exit 1
					else
						CORE_SYMBOL_NAME="${OPTARG}"
					fi
				;;
92
				\? )
93
					printf "\\n\\tInvalid Option: %s\\n" "-${OPTARG}" 1>&2
94 95 96 97
					usage
					exit 1
				;;		
				: )
98
					printf "\\n\\tInvalid Option: %s requires an argument.\\n" "-${OPTARG}" 1>&2
99 100 101 102 103 104 105 106 107 108
					usage
					exit 1
				;;
				* )
					usage
					exit 1
				;;
			esac
		done
	fi
109

110
	if [ ! -d .git ]; then
111 112 113
		printf "\\n\\tThis build script only works with sources cloned from git\\n"
		printf "\\tPlease clone a new eos directory with 'git clone https://github.com/EOSIO/eos --recursive'\\n"
		printf "\\tSee the wiki for instructions: https://github.com/EOSIO/eos/wiki\\n"
114 115
		exit 1
	fi
116

117
	STALE_SUBMODS=$(( $(git submodule status | grep -c "^[+\-]") ))
118
	if [ $STALE_SUBMODS -gt 0 ]; then
119 120
		printf "\\n\\tgit submodules are not up to date.\\n"
		printf "\\tPlease run the command 'git submodule update --init --recursive'.\\n"
121 122 123
		exit 1
	fi

124 125 126 127
	printf "\\n\\tBeginning build version: %s\\n" "${VERSION}"
	printf "\\t%s\\n" "$( date -u )"
	printf "\\tUser: %s\\n" "$( whoami )"
	printf "\\tgit head id: %s\\n" "$( cat .git/refs/heads/master )"
128
	printf "\\tCurrent branch: %s\\n" "$( git rev-parse --abbrev-ref HEAD )"
129
	printf "\\n\\tARCHITECTURE: %s\\n" "${ARCH}"
130

131
	if [ "$ARCH" == "Linux" ]; then
132
		
133
		if [ ! -e /etc/os-release ]; then
134 135 136 137 138 139 140 141
			printf "\\n\\tEOSIO currently supports Amazon, Centos, Fedora, Mint & Ubuntu Linux only.\\n"
			printf "\\tPlease install on the latest version of one of these Linux distributions.\\n"
			printf "\\thttps://aws.amazon.com/amazon-linux-ami/\\n"
			printf "\\thttps://www.centos.org/\\n"
			printf "\\thttps://start.fedoraproject.org/\\n"
			printf "\\thttps://linuxmint.com/\\n"
			printf "\\thttps://www.ubuntu.com/\\n"
			printf "\\tExiting now.\\n"
142 143
			exit 1
		fi
144
	
145
		OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )
146
	
147
		case "$OS_NAME" in
148
			"Amazon Linux AMI")
149
				FILE="${PWD}/scripts/eosio_build_amazon.sh"
150 151
				CXX_COMPILER=g++
				C_COMPILER=gcc
152
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
153 154
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
				export CMAKE=${HOME}/opt/cmake/bin/cmake
155
				export PATH=${HOME}/opt/mongodb/bin:$PATH
156
			;;
157
			"CentOS Linux")
158
				FILE="${PWD}/scripts/eosio_build_centos.sh"
159 160
				CXX_COMPILER=g++
				C_COMPILER=gcc
161
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
162 163
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
				export CMAKE=${HOME}/opt/cmake/bin/cmake
164
				export PATH=${HOME}/opt/mongodb/bin:$PATH
165
			;;
B
Bill Hamilton 已提交
166
			"elementary OS")
167
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
B
Bill Hamilton 已提交
168 169 170 171 172
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
			;;
173
			"Fedora")
174
				FILE="${PWD}/scripts/eosio_build_fedora.sh"
175 176
				CXX_COMPILER=g++
				C_COMPILER=gcc
177
				MONGOD_CONF=/etc/mongod.conf
178
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
179 180
			;;
			"Linux Mint")
181
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
182 183
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
184 185
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
186
			;;
187
			"Ubuntu")
188
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
189 190
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
191 192
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
193
			;;
N
niclas 已提交
194 195 196 197 198 199 200
			"Debian GNU/Linux")
				FILE=${PWD}/scripts/eosio_build_ubuntu.sh
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
			;;
201
			*)
202
				printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n"
203 204
				exit 1
		esac
B
basarrcan 已提交
205

206
		export BOOST_ROOT="${HOME}/opt/boost"
207
		OPENSSL_ROOT_DIR=/usr/include/openssl
208 209
	fi

210
	if [ "$ARCH" == "Darwin" ]; then
211
		FILE="${PWD}/scripts/eosio_build_darwin.sh"
212 213
		CXX_COMPILER=clang++
		C_COMPILER=clang
214
		MONGOD_CONF=/usr/local/etc/mongod.conf
215
		OPENSSL_ROOT_DIR=/usr/local/opt/openssl
216
	fi
217 218 219
   
   ${PWD}/scripts/clean_old_install.sh
   if [ $? -ne 0 ]; then
B
Bucky Kittinger 已提交
220
      printf "\n\tError occurred while trying to remove old installation!\n\n"
221 222
      exit -1
   fi
223

224
	. "$FILE"
225

226
	printf "\\n\\n>>>>>>>> ALL dependencies sucessfully found or installed . Installing EOSIO\\n\\n"
227 228 229
	printf ">>>>>>>> CMAKE_BUILD_TYPE=%s\\n" "${CMAKE_BUILD_TYPE}"
	printf ">>>>>>>> ENABLE_COVERAGE_TESTING=%s\\n" "${ENABLE_COVERAGE_TESTING}"
	printf ">>>>>>>> DOXYGEN=%s\\n\\n" "${DOXYGEN}"
230

231
	if [ ! -d "${BUILD_DIR}" ]; then
232 233 234 235 236 237 238 239 240 241 242
		if ! mkdir -p "${BUILD_DIR}"
		then
			printf "Unable to create build directory %s.\\n Exiting now.\\n" "${BUILD_DIR}"
			exit 1;
		fi
	fi
	
	if ! cd "${BUILD_DIR}"
	then
		printf "Unable to enter build directory %s.\\n Exiting now.\\n" "${BUILD_DIR}"
		exit 1;
243
	fi
244 245 246
	
	if [ -z "$CMAKE" ]; then
		CMAKE=$( command -v cmake )
247
	fi
248
	
249
	if ! "${CMAKE}" -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" -DCMAKE_CXX_COMPILER="${CXX_COMPILER}" \
250
		-DCMAKE_C_COMPILER="${C_COMPILER}" -DWASM_ROOT="${WASM_ROOT}" -DCORE_SYMBOL_NAME="${CORE_SYMBOL_NAME}" \
251
		-DOPENSSL_ROOT_DIR="${OPENSSL_ROOT_DIR}" -DBUILD_MONGO_DB_PLUGIN=true \
252
		-DENABLE_COVERAGE_TESTING="${ENABLE_COVERAGE_TESTING}" -DBUILD_DOXYGEN="${DOXYGEN}" -DCMAKE_INSTALL_PREFIX="/usr/local/eosio" ..
253 254
	then
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> CMAKE building EOSIO has exited with the above error.\\n\\n"
255 256 257
		exit -1
	fi

258 259 260
	if ! make -j"${CPU_CORE}"
	then
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> MAKE building EOSIO has exited with the above error.\\n\\n"
261 262
		exit -1
	fi
263
	
264
	TIME_END=$(( $(date -u +%s) - ${TIME_BEGIN} ))
265

266
	printf "\n\n${bldred}\t _______  _______  _______ _________ _______\n"
267
	printf '\t(  ____ \(  ___  )(  ____ \\\\__   __/(  ___  )\n'
268 269 270 271 272
	printf "\t| (    \/| (   ) || (    \/   ) (   | (   ) |\n"
	printf "\t| (__    | |   | || (_____    | |   | |   | |\n"
	printf "\t|  __)   | |   | |(_____  )   | |   | |   | |\n"
	printf "\t| (      | |   | |      ) |   | |   | |   | |\n"
	printf "\t| (____/\| (___) |/\____) |___) (___| (___) |\n"
273
	printf "\t(_______/(_______)\_______)\_______/(_______)\n${txtrst}"
274

275
	printf "\\n\\tEOSIO has been successfully built. %02d:%02d:%02d\\n\\n" $(($TIME_END/3600)) $(($TIME_END%3600/60)) $(($TIME_END%60))
276
	printf "\\tTo verify your installation run the following commands:\\n"
277 278 279
	
	print_instructions

280
	printf "\\tFor more information:\\n"
281 282 283
	printf "\\tEOSIO website: https://eos.io\\n"
	printf "\\tEOSIO Telegram channel @ https://t.me/EOSProject\\n"
	printf "\\tEOSIO resources: https://eos.io/resources/\\n"
284
	printf "\\tEOSIO Stack Exchange: https://eosio.stackexchange.com\\n"
285
	printf "\\tEOSIO wiki: https://github.com/EOSIO/eos/wiki\\n\\n\\n"
286
				
287 288 289 290 291 292 293 294 295
	if [ "x${EOSIO_BUILD_PACKAGE}" != "x" ]; then
	  # Build eos.io package
		if ! "$CMAKE" -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" -DCMAKE_CXX_COMPILER="${CXX_COMPILER}" \
			-DCMAKE_C_COMPILER="${C_COMPILER}" -DWASM_ROOT="${WASM_ROOT}" \
			-DOPENSSL_ROOT_DIR="${OPENSSL_ROOT_DIR}" -DCMAKE_INSTALL_PREFIX="/usr" ..
		then
			printf "\\n\\t>>>>>>>>>>>>>>>>>>>> CMAKE building eos.io package has exited with the above error.\\n\\n"
			exit -1
		fi
J
Jonathan Giszczak 已提交
296

297 298 299 300 301
		if ! make -j${CPU_CORE} VERBOSE=0 package
		then
			printf "\\n\\t>>>>>>>>>>>>>>>>>>>> MAKE building eos.io package has exited with the above error.\\n\\n"
			exit -1
		fi
J
Jonathan Giszczak 已提交
302

303
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> eos.io package has been successfully built.\\n\\n"
304
	fi