eosio_build.sh 9.0 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 30 31
# 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.
#
# https://github.com/EOSIO/eos/blob/master/LICENSE.txt
##########################################################################
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 38 39 40
		exit 1
	fi

   	function usage()
   	{ 
41
		printf "\\tUsage: %s [Build Option -o <Debug|Release|RelWithDebInfo|MinSizeRel>] [CodeCoverage -c ] [Doxygen -d]\\n\\n" "$0" 1>&2
42 43 44
		exit 1
	}

45
	ARCH=$( uname )
46 47
	BUILD_DIR="${PWD}/build"
	CMAKE_BUILD_TYPE=Release
48
	DISK_MIN=20
49 50 51
	DOXYGEN=false
	ENABLE_COVERAGE_TESTING=false
	TEMP_DIR="/tmp"
52
	TIME_BEGIN=$( date -u +%s )
53
	VERSION=1.2
54

55
	txtbld=$(tput bold)
56 57 58
	bldred=${txtbld}$(tput setaf 1)
	txtrst=$(tput sgr0)

59 60 61 62
	if [ $# -ne 0 ]; then
		while getopts ":cdo:" opt; do
			case "${opt}" in
				o )
63 64
					options=( "Debug" "Release" "RelWithDebInfo" "MinSizeRel" )
					if [[ "${options[*]}" =~ "${OPTARG}" ]]; then
65
						CMAKE_BUILD_TYPE="${OPTARG}"
66
					else
67
						printf "\\n\\tInvalid argument: %s\\n" "${OPTARG}" 1>&2
68 69
						usage
						exit 1
70 71 72 73 74 75 76 77 78
					fi
				;;
				c )
					ENABLE_COVERAGE_TESTING=true
				;;
				d )
					DOXYGEN=true
				;;
				\? )
79
					printf "\\n\\tInvalid Option: %s\\n" "-${OPTARG}" 1>&2
80 81 82 83
					usage
					exit 1
				;;		
				: )
84
					printf "\\n\\tInvalid Option: %s requires an argument.\\n" "-${OPTARG}" 1>&2
85 86 87 88 89 90 91 92 93 94 95
					usage
					exit 1
				;;
				* )
					usage
					exit 1
				;;
			esac
		done
	fi

96
	if [ ! -d .git ]; then
97 98 99
		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"
100 101
		exit 1
	fi
102

103
	STALE_SUBMODS=$(( $(git submodule status | grep -c "^[+\-]") ))
104
	if [ $STALE_SUBMODS -gt 0 ]; then
105 106
		printf "\\n\\tgit submodules are not up to date.\\n"
		printf "\\tPlease run the command 'git submodule update --init --recursive'.\\n"
107 108 109
		exit 1
	fi

110 111 112 113 114 115
	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 )"
	printf "\\tCurrent branch: %s\\n" "$( git branch | grep \* )"
	printf "\\n\\tARCHITECTURE: %s\\n" "${ARCH}"
116

117
	if [ "$ARCH" == "Linux" ]; then
118
		
119
		if [ ! -e /etc/os-release ]; then
120 121 122 123 124 125 126 127
			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"
128 129
			exit 1
		fi
130
	
131
		OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )
132
	
133
		case "$OS_NAME" in
134
			"Amazon Linux AMI")
135
				FILE="${PWD}/scripts/eosio_build_amazon.sh"
136 137
				CXX_COMPILER=g++
				C_COMPILER=gcc
138
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
139 140
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
				export CMAKE=${HOME}/opt/cmake/bin/cmake
141
				export PATH=${HOME}/opt/mongodb/bin:$PATH
142
			;;
143
			"CentOS Linux")
144
				FILE="${PWD}/scripts/eosio_build_centos.sh"
145 146
				CXX_COMPILER=g++
				C_COMPILER=gcc
147
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
148 149
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
				export CMAKE=${HOME}/opt/cmake/bin/cmake
150
				export PATH=${HOME}/opt/mongodb/bin:$PATH
151
			;;
B
Bill Hamilton 已提交
152
			"elementary OS")
153
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
B
Bill Hamilton 已提交
154 155 156 157 158
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
			;;
159
			"Fedora")
160
				FILE="${PWD}/scripts/eosio_build_fedora.sh"
161 162
				CXX_COMPILER=g++
				C_COMPILER=gcc
163
				MONGOD_CONF=/etc/mongod.conf
164
				export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
165 166
			;;
			"Linux Mint")
167
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
168 169
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
170 171
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
172
			;;
173
			"Ubuntu")
174
				FILE="${PWD}/scripts/eosio_build_ubuntu.sh"
175 176
				CXX_COMPILER=clang++-4.0
				C_COMPILER=clang-4.0
177 178
				MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
				export PATH=${HOME}/opt/mongodb/bin:$PATH
179
			;;
180
			*)
181
				printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n"
182 183
				exit 1
		esac
B
basarrcan 已提交
184

185
		export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
186
		OPENSSL_ROOT_DIR=/usr/include/openssl
187
		WASM_ROOT="${HOME}/opt/wasm"
188 189
	fi

190
	if [ "$ARCH" == "Darwin" ]; then
191
		FILE="${PWD}/scripts/eosio_build_darwin.sh"
192 193
		CXX_COMPILER=clang++
		C_COMPILER=clang
194
		MONGOD_CONF=/usr/local/etc/mongod.conf
195
		OPENSSL_ROOT_DIR=/usr/local/opt/openssl
196
		WASM_ROOT=/usr/local/wasm
197 198
	fi

199
	. "$FILE"
200

201
	printf "\\n\\n>>>>>>>> ALL dependencies sucessfully found or installed . Installing EOS.IO\\n\\n"
202

203
	if [ ! -d "${BUILD_DIR}" ]; then
204 205 206 207 208 209 210 211 212 213 214
		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;
215
	fi
216 217 218
	
	if [ -z "$CMAKE" ]; then
		CMAKE=$( command -v cmake )
219
	fi
220
	
221 222 223 224 225 226
	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}" -DBUILD_MONGO_DB_PLUGIN=true \
		-DENABLE_COVERAGE_TESTING="${ENABLE_COVERAGE_TESTING}" -DBUILD_DOXYGEN="${DOXYGEN}" ..
	then
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> CMAKE building EOSIO has exited with the above error.\\n\\n"
227 228 229
		exit -1
	fi

230 231 232
	if ! make -j"${CPU_CORE}"
	then
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> MAKE building EOSIO has exited with the above error.\\n\\n"
233 234
		exit -1
	fi
235
	
236
	TIME_END=$(( $(date -u +%s) - ${TIME_BEGIN} ))
237

238
	printf "\n\n${bldred}\t _______  _______  _______ _________ _______\n"
239
	printf '\t(  ____ \(  ___  )(  ____ \\\\__   __/(  ___  )\n'
240 241 242 243 244
	printf "\t| (    \/| (   ) || (    \/   ) (   | (   ) |\n"
	printf "\t| (__    | |   | || (_____    | |   | |   | |\n"
	printf "\t|  __)   | |   | |(_____  )   | |   | |   | |\n"
	printf "\t| (      | |   | |      ) |   | |   | |   | |\n"
	printf "\t| (____/\| (___) |/\____) |___) (___| (___) |\n"
245
	printf "\t(_______/(_______)\_______)\_______/(_______)\n${txtrst}"
246

247 248
	printf "\\n\\tEOS.IO has been successfully built. %d:%d:%d\\n\\n" $(($TIME_END/3600)) $(($TIME_END%3600/60)) $(($TIME_END%60))
	printf "\\tTo verify your installation run the following commands:\\n"
249 250 251
	
	print_instructions

252 253 254 255 256
	printf "\\tFor more information:\\n"
	printf "\\tEOS.IO website: https://eos.io\\n"
	printf "\\tEOS.IO Telegram channel @ https://t.me/EOSProject\\n"
	printf "\\tEOS.IO resources: https://eos.io/resources/\\n"
	printf "\\tEOS.IO wiki: https://github.com/EOSIO/eos/wiki\\n\\n\\n"
257
				
258 259 260 261 262 263 264 265 266
	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 已提交
267

268 269 270 271 272
		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 已提交
273

274 275
		printf "\\n\\t>>>>>>>>>>>>>>>>>>>> eos.io package has been successfully built.\\n\\n"
	fi