github.com/amazechain/amc@v0.1.3/Makefile (about)

     1  BUILD_TIME := $(shell date +"%Y-%m-%d %H:%M:%S")
     2  #GIT_COMMIT := $(shell git show -s --pretty=format:%h)
     3  GO_VERSION := $(shell go version)
     4  BUILD_PATH := ./build/bin/
     5  APP_NAME := amazechain
     6  APP_PATH := ./cmd/amc
     7  SHELL := /bin/bash
     8  GO = go
     9  #LDFLAGS := -ldflags "-w -s -X github.com/amazechain/amc/version.BuildNumber=${GIT_COMMIT} -X 'github.com/amazechain/amc/version.BuildTime=${BUILD_TIME}' -X 'github.com/amazechain/amc/version.GoVersion=${GO_VERSION}'"
    10  
    11  
    12  # Variables below for building on host OS, and are ignored for docker
    13  #
    14  # Pipe error below to /dev/null since Makefile structure kind of expects
    15  # Go to be available, but with docker it's not strictly necessary
    16  CGO_CFLAGS := $(shell $(GO) env CGO_CFLAGS 2>/dev/null) # don't lose default
    17  CGO_CFLAGS += -DMDBX_FORCE_ASSERTIONS=0 # Enable MDBX's asserts by default in 'devel' branch and disable in releases
    18  #CGO_CFLAGS += -DMDBX_DISABLE_VALIDATION=1 # This feature is not ready yet
    19  #CGO_CFLAGS += -DMDBX_ENABLE_PROFGC=0 # Disabled by default, but may be useful for performance debugging
    20  #CGO_CFLAGS += -DMDBX_ENABLE_PGOP_STAT=0 # Disabled by default, but may be useful for performance debugging
    21  #CGO_CFLAGS += -DMDBX_ENV_CHECKPID=0 # Erigon doesn't do fork() syscall
    22  CGO_CFLAGS += -O
    23  CGO_CFLAGS += -D__BLST_PORTABLE__
    24  CGO_CFLAGS += -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes
    25  #CGO_CFLAGS += -Wno-error=strict-prototypes
    26  
    27  GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
    28  GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
    29  GIT_TAG    ?= $(shell git describe --tags '--match=v*' --dirty)
    30  PACKAGE = github.com/amazechain/amc
    31  
    32  BUILD_TAGS = nosqlite,noboltdb
    33  GO_FLAGS += -trimpath -tags $(BUILD_TAGS) -buildvcs=false
    34  GO_FLAGS += -ldflags  "-X ${PACKAGE}/params.GitCommit=${GIT_COMMIT} -X ${PACKAGE}/params.GitBranch=${GIT_BRANCH} -X ${PACKAGE}/params.GitTag=${GIT_TAG}"
    35  GOBUILD = CGO_CFLAGS="$(CGO_CFLAGS)" go build -v $(GO_FLAGS)
    36  
    37  
    38  # if using volume-mounting data dir, then must exist on host OS
    39  DOCKER_UID ?= $(shell id -u)
    40  DOCKER_GID ?= $(shell id -g)
    41  
    42  
    43  # == mobiles
    44  #OSFLAG=$(shell uname -sm)
    45  
    46  ANDROID_SDK=$(ANDROID_HOME)
    47  NDK_VERSION=21.1.6352462
    48  NDK_HOME=$(ANDROID_SDK)/ndk/$(NDK_VERSION)
    49  #ANDROID_SDK=/Users/mac/Library/Android/sdk
    50  MOBILE_GO_FLAGS = -ldflags "-X ${PACKAGE}/cmd/evmsdk/common.VERSION=${GIT_COMMIT}"
    51  MOBILE_PACKAGE= $(shell pwd)/cmd/evmsdk
    52  BUILD_MOBILE_PATH = ./build/mobile/
    53  
    54  
    55  # --build-arg UID=${DOCKER_UID} --build-arg GID=${DOCKER_GID}
    56  
    57  ## go-version:                        print and verify go version
    58  go-version:
    59  	@if [ $(shell go version | cut -c 16-17) -lt 18 ]; then \
    60  		echo "minimum required Golang version is 1.18"; \
    61  		exit 1 ;\
    62  	fi
    63  gen:
    64  	@echo "Generate go code ..."
    65  	go generate ./...
    66  	@echo "Generate done!"
    67  deps: go-version
    68  	@echo "setup go deps..."
    69  	go mod tidy
    70  	@echo "deps done!"
    71  
    72  amc: deps
    73  	@echo "start build $(APP_NAME)..."
    74  	#go build -v ${LDFLAGS} -o $(BUILD_PATH)$(APP_NAME)  ${APP_PATH}
    75  	$(GOBUILD) -o $(BUILD_PATH)$(APP_NAME)  ${APP_PATH}
    76  	@echo "Compile done!"
    77  
    78  images:
    79  	@echo "docker images build ..."
    80  	DOCKER_BUILDKIT=1 docker build -t amazechain/amc:local .
    81  	@echo "Compile done!"
    82  
    83  up:
    84  	@echo "docker compose up $(APP_NAME) ..."
    85  	docker-compose  --project-name $(APP_NAME) up -d
    86  	docker-compose  --project-name $(APP_NAME) logs -f
    87  down:
    88  	@echo "docker compose down $(APP_NAME) ..."
    89  	docker-compose  --project-name $(APP_NAME) down
    90  	docker volume ls -q | grep 'amazechain' | xargs -I % docker volume rm %
    91  	@echo "done!"
    92  stop:
    93  	@echo "docker compose stop $(APP_NAME) ..."
    94  	docker-compose  --project-name $(APP_NAME) stop
    95  	@echo "done!"
    96  start:
    97  	@echo "docker compose stop $(APP_NAME) ..."
    98  	docker-compose  --project-name $(APP_NAME) start
    99  	docker-compose  --project-name $(APP_NAME) logs -f
   100  clean:
   101  	go clean
   102  	@rm -rf  build
   103  
   104  devtools:
   105  	env GOBIN= go install github.com/fjl/gencodec@latest
   106  	env GOBIN= go install github.com/golang/protobuf/protoc-gen-go@latest
   107  	env GOBIN= go install github.com/prysmaticlabs/fastssz/sszgen@latest
   108  	env GOBIN= go install github.com/prysmaticlabs/protoc-gen-go-cast@latest
   109  
   110  
   111  PACKAGE_NAME          := github.com/WeAreAmaze/amc
   112  GOLANG_CROSS_VERSION  ?= v1.20.7
   113  
   114  .PHONY: release
   115  release:
   116  	@docker run \
   117  		--rm \
   118  		--privileged \
   119  		-e CGO_ENABLED=1 \
   120  		-e GITHUB_TOKEN \
   121  		-e DOCKER_USERNAME \
   122  		-e DOCKER_PASSWORD \
   123  		-v /var/run/docker.sock:/var/run/docker.sock \
   124  		-v `pwd`:/go/src/$(PACKAGE_NAME) \
   125  		-w /go/src/$(PACKAGE_NAME) \
   126  		ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
   127  		--clean --skip-validate
   128  
   129  		@docker image push --all-tags amazechain/amc
   130  
   131  
   132  #== mobiles start
   133  mobile: clean mobile-dir android ios
   134  
   135  mobile-dir:
   136  	#go get golang.org/x/mobile/bind/objc
   137  	mkdir -p $(BUILD_MOBILE_PATH)/android
   138  ios:
   139  	ANDROID_HOME=$(ANDROID_SDK) ANDROID_NDK_HOME=$(NDK_HOME) gomobile bind ${MOBILE_GO_FLAGS} -androidapi 21 -o $(BUILD_MOBILE_PATH)/evmsdk.xcframework -target=ios $(MOBILE_PACKAGE)
   140  android:
   141  	ANDROID_HOME=$(ANDROID_SDK) ANDROID_NDK_HOME=$(NDK_HOME) gomobile bind -x ${MOBILE_GO_FLAGS} -androidapi 21 -o $(BUILD_MOBILE_PATH)/android/evmsdk.aar -target=android $(MOBILE_PACKAGE)
   142  
   143  open-output:
   144  	open ./mobile
   145  
   146  #== mobiles end