eosio_build.sh 8.8 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 ${CWD} to run this script.\n \tExiting now.\n\n"
36 37 38 39 40 41 42 43 44
		exit 1
	fi

   	function usage()
   	{ 
		printf "\tUsage: $0 [Build Option -o <Debug|Release|RelWithDebInfo|MinSizeRel>] [CodeCoverage -c ] [Doxygen -d]\n\n" 1>&2
		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 54
	ULIMIT=$( ulimit -u )
	VERSION=1.2
55

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

60 61 62 63
	if [ $# -ne 0 ]; then
		while getopts ":cdo:" opt; do
			case "${opt}" in
				o )
64 65
					options=( "Debug" "Release" "RelWithDebInfo" "MinSizeRel" )
					if [[ "${options[*]}" =~ "${OPTARG}" ]]; then
66
						CMAKE_BUILD_TYPE="${OPTARG}"
67 68 69 70
					else
						printf "\n\tInvalid argument: ${OPTARG}\n" 1>&2
						usage
						exit 1
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
					fi
				;;
				c )
					ENABLE_COVERAGE_TESTING=true
				;;
				d )
					DOXYGEN=true
				;;
				\? )
					printf "\n\tInvalid Option: -${OPTARG}\n" 1>&2
					usage
					exit 1
				;;		
				: )
					printf "\n\tInvalid Option: -${OPTARG} requires an argument\n" 1>&2
					usage
					exit 1
				;;
				* )
					usage
					exit 1
				;;
			esac
		done
	fi

97
	if [ ! -d .git ]; then
98
		printf "\n\tThis build script only works with sources cloned from git\n"
99 100 101 102
		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"
		exit 1
	fi
103

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

111 112
	printf "\n\tBeginning build version: ${VERSION}\n"
	printf "\t$( date -u )\n"
113
	printf "\tUser: $( whoami )\n"
114 115
	printf "\tgit head id: $( cat .git/refs/heads/master )\n"
	printf "\tCurrent branch: $( git branch | grep \* )\n"
116
	printf "\tMake version: $( make --version )\n\n"
117 118
	printf "\n\tARCHITECTURE: ${ARCH}\n"

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

187
		export BOOST_ROOT=${HOME}/opt/boost_1_66_0
188 189
		OPENSSL_ROOT_DIR=/usr/include/openssl
		WASM_ROOT=${HOME}/opt/wasm
190 191 192
	fi

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

202 203
	. $FILE

204 205
	printf "\n\n>>>>>>>> ALL dependencies sucessfully found or installed . Installing EOS.IO\n\n"

206 207
	if [ ! -d "${BUILD_DIR}" ]; then
		mkdir -p "${BUILD_DIR}"
208
	fi
209
	cd "${BUILD_DIR}"
210

211 212 213
	if [ -z $CMAKE ]; then
		CMAKE=$( which cmake )
	fi
214
	
215
	$CMAKE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
216
	-DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_ROOT=${WASM_ROOT} \
217
	-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} -DBUILD_MONGO_DB_PLUGIN=true \
218
	-DENABLE_COVERAGE_TESTING=${ENABLE_COVERAGE_TESTING} -DBUILD_DOXYGEN=${DOXYGEN} \
219
	..
220
	
221 222
	if [ $? -ne 0 ]; then
		printf "\n\t>>>>>>>>>>>>>>>>>>>> CMAKE building EOSIO has exited with the above error.\n\n"
223 224 225
		exit -1
	fi

226
	make -j${CPU_CORE} -s
227 228 229 230 231

	if [ $? -ne 0 ]; then
		printf "\n\t>>>>>>>>>>>>>>>>>>>> MAKE building EOSIO has exited with the above error.\n\n"
		exit -1
	fi
232 233 234
	
	TIME_END=$(( `date -u +%s` - $TIME_BEGIN ))

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

	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"
246 247 248
	
	print_instructions

249 250 251 252 253
	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"
254
				
255
   if [ "x${EOSIO_BUILD_PACKAGE}" != "x" ]; then
J
Jonathan Giszczak 已提交
256 257 258
      # Build eos.io package
      $CMAKE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
      -DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_ROOT=${WASM_ROOT} \
259
      -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} -DCMAKE_INSTALL_PREFIX=/usr ..
J
Jonathan Giszczak 已提交
260 261 262 263 264 265

      if [ $? -ne 0 ]; then
         printf "\n\t>>>>>>>>>>>>>>>>>>>> CMAKE building eos.io package has exited with the above error.\n\n"
         exit -1
      fi

266
      make -j${CPU_CORE} VERBOSE=0 package
J
Jonathan Giszczak 已提交
267 268 269 270 271 272 273

      if [ $? -ne 0 ]; then
         printf "\n\t>>>>>>>>>>>>>>>>>>>> MAKE building eos.io package has exited with the above error.\n\n"
         exit -1
      fi

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