Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'improve/makefile'
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Jun 12, 2018
2 parents b358535 + 83b9367 commit 100c522
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 89 deletions.
30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@ COMMIT=`git log --pretty=format:'%h' -n 1`
# Choose to install geth with or without SputnikVM.
WITH_SVM?=1

# Provide default value of GOPATH, if it's not set in environment
export GOPATH?=${HOME}/go

LDFLAGS=-ldflags "-X main.Version="`git describe --tags`

setup: ## Install all the build and lint dependencies
go get -u github.com/alecthomas/gometalinter
go get -u github.com/golang/dep/...
go get -u github.com/pierrre/gotestcover
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/omeid/go-resources/cmd/resources
dep ensure
gometalinter --install

build: cmd/abigen cmd/bootnode cmd/disasm cmd/ethtest cmd/evm cmd/gethrpctest cmd/rlpdump cmd/geth ## Build a local snapshot binary version of all commands
@ls -ld $(BINARY)/*

cmd/geth: ## Build a local snapshot binary version of geth. Use WITH_SVM=0 to disable building with SputnikVM (default: WITH_SVM=1)
if [ ${WITH_SVM} == 1 ]; then ./scripts/build_sputnikvm.sh build ; else mkdir -p ./${BINARY} && go build ${LDFLAGS} -o ${BINARY}/geth ./cmd/geth ; fi
cmd/geth: chainconfig ## Build a local snapshot binary version of geth. Use WITH_SVM=0 to disable building with SputnikVM (default: WITH_SVM=1)
ifeq (${WITH_SVM}, 1)
./scripts/build_sputnikvm.sh build
else
mkdir -p ./${BINARY}
go build ${LDFLAGS} -o ${BINARY}/geth -tags="netgo" ./cmd/geth
endif
@echo "Done building geth."
@echo "Run \"$(BINARY)/geth\" to launch geth."

Expand Down Expand Up @@ -69,9 +78,13 @@ install: ## Install all packages to $GOPATH/bin
go install ./cmd/{abigen,bootnode,disasm,ethtest,evm,gethrpctest,rlpdump}
$(MAKE) install_geth

install_geth: ## Install geth to $GOPATH/bin. Use WITH_SVM=0 to disable building with SputnikVM (default: WITH_SVM=1)
install_geth: chainconfig ## Install geth to $GOPATH/bin. Use WITH_SVM=0 to disable building with SputnikVM (default: WITH_SVM=1)
$(info Installing $$GOPATH/bin/geth)
if [ ${WITH_SVM} == 1 ]; then ./scripts/build_sputnikvm.sh install ; else go install ${LDFLAGS} ./cmd/geth ; fi
ifeq (${WITH_SVM}, 1)
./scripts/build_sputnikvm.sh install
else
go install ${LDFLAGS} -tags="netgo" ./cmd/geth ; fi
endif

fmt: ## gofmt and goimports all go files
find . -name '*.go' -not -wholename './vendor/*' -not -wholename './_vendor*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
Expand Down Expand Up @@ -106,8 +119,17 @@ test: ## Run all the tests
cover: test ## Run all the tests and opens the coverage report
go tool cover -html=coverage.txt

chainconfig: core/assets/assets.go ## Rebuild assets if source config files changed.

core/assets/assets.go: ${GOPATH}/bin/resources core/config/*.json core/config/*.csv
${GOPATH}/bin/resources -fmt -declare -var=DEFAULTS -package=assets -output=core/assets/assets.go core/config/*.json core/config/*.csv

${GOPATH}/bin/resources:
go get -u github.com/omeid/go-resources/cmd/resources

clean: ## Remove local snapshot binary directory
if [ -d ${BINARY} ] ; then rm -rf ${BINARY} ; fi
go clean -i ./...

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
Expand Down
2 changes: 2 additions & 0 deletions core/assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ mkdir config/assets
package)
~/gocode/src/github.com/ethereumproject/go-ethereum resourceful-json-configs *% ⟠ resources -fmt -declare -var=DEFAULTS -package=assets -output=core/assets/assets.go core/config/*.json core/config/*.csv
```

When using Makefile, changes in `.json` and `.csv` files will trigger rebuilding of binary assets.
114 changes: 29 additions & 85 deletions scripts/build_sputnikvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,41 @@ else
echo "With SputnikVM, running geth $OUTPUT ..."
fi

OS='Unknown OS'
case "$(uname -s)" in
Darwin)
OS="Mac";;
OS=`uname -s`

Linux)
OS="Linux";;
geth_path="github.com/ethereumproject/go-ethereum"
sputnik_path="github.com/ethereumproject/sputnikvm-ffi"
sputnik_dir="$GOPATH/src/$geth_path/vendor/$sputnik_path"

CYGWIN*|MINGW32*|MSYS*)
OS="Windows";;
geth_bindir="$GOPATH/src/$geth_path/bin"

*)
echo 'Unknown OS'
exit;;
esac
echo "Building SputnikVM"
make -C "$sputnik_dir/c"

if [ "$OS" == "Windows" ]; then
cd %GOPATH%\src\github.com\ethereumproject
# Check if git is happening in svm-ffi.
if [ -d "%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi" ]; then
cd sputnikvm-ffi
if [ -d "%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\.git" ]; then
remote_name=$(git remote -v | head -1 | awk '{print $1;}')
if [ ! "%remote_name%" == "" ]; then
echo "Updating SputnikVM FFI from branch [%remote_name%] ..."
git pull %remote_name% master
fi
fi
cd c\ffi
else
git clone https://github.com/ethereumproject/sputnikvm-ffi.git
cd sputnikvm-ffi\c\ffi
fi
cargo build --release
copy %GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\ffi\target\release\sputnikvm.lib \
%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\sputnikvm.lib
echo "Doing geth $OUTPUT ..."
cd "$GOPATH/src/$geth_path"

cd %GOPATH%\src\github.com\ethereumproject\go-ethereum\cmd\geth
set CGO_LDFLAGS=-Wl,--allow-multiple-definition \
%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\sputnikvm.lib -lws2_32 -luserenv
if [ "$OUTPUT" == "install" ]; then
go install -ldflags '-X main.Version='$(git describe --tags) -tags=sputnikvm .
elif [ "$OUTPUT" == "build" ]; then
mkdir -p %GOPATH%\src\github.com\ethereumproject\go-ethereum\bin
go build -ldflags '-X main.Version='$(git describe --tags) -o %GOPATH%\src\github.com\ethereumproject\go-ethereum\bin\geth -tags=sputnikvm .
fi
else
ep_gopath=$GOPATH/src/github.com/ethereumproject
sputnikffi_path="$ep_gopath/sputnikvm-ffi"
LDFLAGS="$sputnik_dir/c/libsputnikvm.a "
case $OS in
"Linux")
LDFLAGS+="-ldl"
;;

"Darwin")
LDFLAGS+="-ldl -lresolv"
;;

CYGWIN*|MINGW32*|MSYS*)
LDFLAGS="-Wl,--allow-multiple-definition $sputnik_dir/c/sputnikvm.lib -lws2_32 -luserenv"
;;
esac


# If sputnikvmffi has already been cloned/existing
if [ -d "$sputnikffi_path" ]; then
# Ensure git is happening in svm-ffi.
# Update if .git exists, otherwise don't try updating. We could possibly handle git-initing and adding remote but seems
# like an edge case.
if [ -d "$sputnikffi_path/.git" ]; then
cd $sputnikffi_path
remote_name=$(git remote -v | head -1 | awk '{print $1;}')
if [ ! "$remote_name" == "" ]; then
echo "Updating SputnikVM FFI from branch [$remote_name] ..."
git pull "$remote_name" master
fi
fi
else
echo "Cloning SputnikVM FFI ..."
cd $ep_gopath
git clone https://github.com/ethereumproject/sputnikvm-ffi.git
fi
cd "$sputnikffi_path/c/ffi"
echo "Building SputnikVM FFI ..."
cargo build --release
cp $sputnikffi_path/c/ffi/target/release/libsputnikvm_ffi.a \
$sputnikffi_path/c/libsputnikvm.a

geth_binpath="$ep_gopath/go-ethereum/bin"
echo "Doing geth $OUTPUT ..."
cd "$ep_gopath/go-ethereum"
if [ "$OS" == "Linux" ]; then
if [ "$OUTPUT" == "install" ]; then
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl" go install -ldflags '-X main.Version='$(git describe --tags) ./cmd/geth
elif [ "$OUTPUT" == "build" ]; then
mkdir -p "$geth_binpath"
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl" go build -ldflags '-X main.Version='$(git describe --tags) -o $geth_binpath/geth -tags=sputnikvm ./cmd/geth
fi
else
if [ "$OUTPUT" == "install" ]; then
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl -lresolv" go install -ldflags '-X main.Version='$(git describe --tags) -tags=sputnikvm ./cmd/geth
elif [ "$OUTPUT" == "build" ]; then
mkdir -p "$geth_binpath"
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl -lresolv" go build -ldflags '-X main.Version='$(git describe --tags) -o $geth_binpath/geth -tags=sputnikvm ./cmd/geth
fi
fi
if [ "$OUTPUT" == "install" ]; then
CGO_LDFLAGS=$LDFLAGS go install -ldflags '-X main.Version='$(git describe --tags) -tags="sputnikvm netgo" ./cmd/geth
elif [ "$OUTPUT" == "build" ]; then
mkdir -p "$geth_bindir"
CGO_LDFLAGS=$LDFLAGS go build -ldflags '-X main.Version='$(git describe --tags) -o $geth_bindir/geth -tags="sputnikvm netgo" ./cmd/geth
fi

0 comments on commit 100c522

Please sign in to comment.