github.com/igggame/nebulas-go@v2.1.0+incompatible/Makefile (about)

     1  
     2  # Copyright (C) 2017 go-nebulas authors
     3  #
     4  # This file is part of the go-nebulas library.
     5  #
     6  # the go-nebulas library is free software: you can redistribute it and/or modify
     7  # it under the terms of the GNU General Public License as published by
     8  # the Free Software Foundation, either version 3 of the License, or
     9  # (at your option) any later version.
    10  #
    11  # the go-nebulas library is distributed in the hope that it will be useful,
    12  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  # GNU General Public License for more details.
    15  #
    16  # You should have received a copy of the GNU General Public License
    17  # along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    18  #
    19  
    20  SHELL := /bin/bash 
    21  
    22  VERSION?=2.0
    23  
    24  COMMIT=$(shell git rev-parse HEAD)
    25  BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
    26  
    27  CURRENT_DIR=$(shell pwd)
    28  BUILD_DIR=${CURRENT_DIR}
    29  BINARY=neb
    30  
    31  VET_REPORT=vet.report
    32  LINT_REPORT=lint.report
    33  TEST_REPORT=test.report
    34  TEST_XUNIT_REPORT=test.report.xml
    35  
    36  OS := $(shell uname -s)
    37  ifeq ($(OS),Darwin)
    38  	DYLIB=.dylib
    39  	INSTALL=install
    40  	LDCONFIG=
    41  	NEBBINARY=$(BINARY)
    42  	BUUILDLOG=
    43  else
    44  	DYLIB=.so
    45  	INSTALL=sudo install
    46  	LDCONFIG=sudo /sbin/ldconfig
    47  	NEBBINARY=$(BINARY)-$(COMMIT)
    48  	BUUILDLOG=-rm -f $(BINARY); ln -s $(BINARY)-$(COMMIT) $(BINARY)
    49  endif
    50  
    51  NATIVELIB := native-lib
    52  ifeq ($(NATIVELIB),$(wildcard $(NATIVELIB)))
    53      CGO_CFLAGS=
    54  	CGO_LDFLAGS=CGO_LDFLAGS="-L$(CURRENT_DIR)/native-lib -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
    55  else
    56      CGO_CFLAGS=
    57  	CGO_LDFLAGS=
    58  endif
    59  
    60  ifeq ($(shell command -v dep 2> /dev/null || echo "uninstalled"),uninstalled)
    61  	DEPINSTALL=mkdir -p $(GOPATH)/bin && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
    62  else
    63  	DEPINSTALL=
    64  endif
    65  
    66  # $(warning  $(CGO_LDFLAGS))
    67  
    68  # Setup the -ldflags option for go build here, interpolate the variable values
    69  LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH} -X main.compileAt=`date +%s`"
    70  
    71  # Build the project
    72  .PHONY: build build-linux clean dep lint run test vet link-libs all
    73  
    74  all: clean vet fmt lint build test
    75  
    76  dep:
    77  	$(DEPINSTALL) dep ensure -v
    78  
    79  build:
    80  	cd cmd/neb; $(CGO_CFLAGS) $(CGO_LDFLAGS) go build $(LDFLAGS) -o ../../$(NEBBINARY)
    81  	$(BUUILDLOG)
    82  
    83  build-linux:
    84  	cd cmd/neb; GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o ../../$(BINARY)-linux
    85  
    86  LIST := ./account/... ./cmd/... ./common/... ./consensus ./core/... ./crypto/... ./metrics/... ./neblet/... ./net/... ./nf/... ./rpc/... ./storage/... ./sync/... ./util/... ./nip/... ./nr/...
    87  # LIST := $(ls -d */|grep -Ev "vendor|logs|nebtestkit|.db")/...
    88  
    89  test:
    90  	env GOCACHE=off $(CGO_CFLAGS) $(CGO_LDFLAGS) go test $(LIST) 2>&1 | tee $(TEST_REPORT); go2xunit -fail -input $(TEST_REPORT) -output $(TEST_XUNIT_REPORT)
    91  
    92  vet:
    93  	go vet $$(go list $(LIST)) 2>&1 | tee $(VET_REPORT)
    94  
    95  fmt:
    96  	goimports -w $$(go list -f "{{.Dir}}" $(LIST) | grep -v /vendor/)
    97  
    98  lint:
    99  	golint $$(go list $(LIST)) | sed "s:^$(BUILD_DIR)/::" | tee $(LINT_REPORT)
   100  
   101  clean:
   102  	-rm -f $(VET_REPORT)
   103  	-rm -f $(LINT_REPORT)
   104  	-rm -f $(TEST_REPORT)
   105  	-rm -f $(TEST_XUNIT_REPORT)
   106  	-rm -f $(BINARY)
   107  	-rm -f $(BINARY)-$(COMMIT)
   108