github.com/symblcrowd/bloom@v2.0.5+incompatible/Makefile (about)

     1  # MAKEFILE
     2  #
     3  # @author      Nicola Asuni <info@tecnick.com>
     4  # @link        https://github.com/willf/bloom
     5  # ------------------------------------------------------------------------------
     6  
     7  # List special make targets that are not associated with files
     8  .PHONY: help all test format fmtcheck vet lint coverage cyclo ineffassign misspell structcheck varcheck errcheck gosimple astscan qa deps clean nuke
     9  
    10  # Use bash as shell (Note: Ubuntu now uses dash which doesn't support PIPESTATUS).
    11  SHELL=/bin/bash
    12  
    13  # CVS path (path to the parent dir containing the project)
    14  CVSPATH=github.com/willf
    15  
    16  # Project owner
    17  OWNER=willf
    18  
    19  # Project vendor
    20  VENDOR=willf
    21  
    22  # Project name
    23  PROJECT=bloom
    24  
    25  # Project version
    26  VERSION=$(shell cat VERSION)
    27  
    28  # Name of RPM or DEB package
    29  PKGNAME=${VENDOR}-${PROJECT}
    30  
    31  # Current directory
    32  CURRENTDIR=$(shell pwd)
    33  
    34  # GO lang path
    35  ifneq ($(GOPATH),)
    36  	ifeq ($(findstring $(GOPATH),$(CURRENTDIR)),)
    37  		# the defined GOPATH is not valid
    38  		GOPATH=
    39  	endif
    40  endif
    41  ifeq ($(GOPATH),)
    42  	# extract the GOPATH
    43  	GOPATH=$(firstword $(subst /src/, ,$(CURRENTDIR)))
    44  endif
    45  
    46  # --- MAKE TARGETS ---
    47  
    48  # Display general help about this command
    49  help:
    50  	@echo ""
    51  	@echo "$(PROJECT) Makefile."
    52  	@echo "GOPATH=$(GOPATH)"
    53  	@echo "The following commands are available:"
    54  	@echo ""
    55  	@echo "    make qa          : Run all the tests"
    56  	@echo "    make test        : Run the unit tests"
    57  	@echo ""
    58  	@echo "    make format      : Format the source code"
    59  	@echo "    make fmtcheck    : Check if the source code has been formatted"
    60  	@echo "    make vet         : Check for suspicious constructs"
    61  	@echo "    make lint        : Check for style errors"
    62  	@echo "    make coverage    : Generate the coverage report"
    63  	@echo "    make cyclo       : Generate the cyclomatic complexity report"
    64  	@echo "    make ineffassign : Detect ineffectual assignments"
    65  	@echo "    make misspell    : Detect commonly misspelled words in source files"
    66  	@echo "    make structcheck : Find unused struct fields"
    67  	@echo "    make varcheck    : Find unused global variables and constants"
    68  	@echo "    make errcheck    : Check that error return values are used"
    69  	@echo "    make gosimple    : Suggest code simplifications"
    70  	@echo "    make astscan     : GO AST scanner"
    71  	@echo ""
    72  	@echo "    make docs        : Generate source code documentation"
    73  	@echo ""
    74  	@echo "    make deps        : Get the dependencies"
    75  	@echo "    make clean       : Remove any build artifact"
    76  	@echo "    make nuke        : Deletes any intermediate file"
    77  	@echo ""
    78  
    79  # Alias for help target
    80  all: help
    81  
    82  # Run the unit tests
    83  test:
    84  	@mkdir -p target/test
    85  	@mkdir -p target/report
    86  	GOPATH=$(GOPATH) \
    87  	go test \
    88  	-covermode=atomic \
    89  	-bench=. \
    90  	-race \
    91  	-cpuprofile=target/report/cpu.out \
    92  	-memprofile=target/report/mem.out \
    93  	-mutexprofile=target/report/mutex.out \
    94  	-coverprofile=target/report/coverage.out \
    95  	-v ./... | \
    96  	tee >(PATH=$(GOPATH)/bin:$(PATH) go-junit-report > target/test/report.xml); \
    97  	test $${PIPESTATUS[0]} -eq 0
    98  
    99  # Format the source code
   100  format:
   101  	@find . -type f -name "*.go" -exec gofmt -s -w {} \;
   102  
   103  # Check if the source code has been formatted
   104  fmtcheck:
   105  	@mkdir -p target
   106  	@find . -type f -name "*.go" -exec gofmt -s -d {} \; | tee target/format.diff
   107  	@test ! -s target/format.diff || { echo "ERROR: the source code has not been formatted - please use 'make format' or 'gofmt'"; exit 1; }
   108  
   109  # Check for syntax errors
   110  vet:
   111  	GOPATH=$(GOPATH) go vet .
   112  
   113  # Check for style errors
   114  lint:
   115  	GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) golint .
   116  
   117  # Generate the coverage report
   118  coverage:
   119  	@mkdir -p target/report
   120  	GOPATH=$(GOPATH) \
   121  	go tool cover -html=target/report/coverage.out -o target/report/coverage.html
   122  
   123  # Report cyclomatic complexity
   124  cyclo:
   125  	@mkdir -p target/report
   126  	GOPATH=$(GOPATH) gocyclo -avg ./ | tee target/report/cyclo.txt ; test $${PIPESTATUS[0]} -eq 0
   127  
   128  # Detect ineffectual assignments
   129  ineffassign:
   130  	@mkdir -p target/report
   131  	GOPATH=$(GOPATH) ineffassign ./ | tee target/report/ineffassign.txt ; test $${PIPESTATUS[0]} -eq 0
   132  
   133  # Detect commonly misspelled words in source files
   134  misspell:
   135  	@mkdir -p target/report
   136  	GOPATH=$(GOPATH) misspell -error ./  | tee target/report/misspell.txt ; test $${PIPESTATUS[0]} -eq 0
   137  
   138  # Find unused struct fields
   139  structcheck:
   140  	@mkdir -p target/report
   141  	GOPATH=$(GOPATH) structcheck -a ./  | tee target/report/structcheck.txt
   142  
   143  # Find unused global variables and constants
   144  varcheck:
   145  	@mkdir -p target/report
   146  	GOPATH=$(GOPATH) varcheck -e ./  | tee target/report/varcheck.txt
   147  
   148  # Check that error return values are used
   149  errcheck:
   150  	@mkdir -p target/report
   151  	GOPATH=$(GOPATH) errcheck ./  | tee target/report/errcheck.txt
   152  
   153  # Suggest code simplifications
   154  gosimple:
   155  	@mkdir -p target/report
   156  	GOPATH=$(GOPATH) gosimple ./  | tee target/report/gosimple.txt
   157  
   158  # AST scanner
   159  astscan:
   160  	@mkdir -p target/report
   161  	GOPATH=$(GOPATH) gas .//*.go | tee target/report/astscan.txt ; test $${PIPESTATUS[0]} -eq 0
   162  
   163  # Generate source docs
   164  docs:
   165  	@mkdir -p target/docs
   166  	nohup sh -c 'GOPATH=$(GOPATH) godoc -http=127.0.0.1:6060' > target/godoc_server.log 2>&1 &
   167  	wget --directory-prefix=target/docs/ --execute robots=off --retry-connrefused --recursive --no-parent --adjust-extension --page-requisites --convert-links http://127.0.0.1:6060/pkg/github.com/${VENDOR}/${PROJECT}/ ; kill -9 `lsof -ti :6060`
   168  	@echo '<html><head><meta http-equiv="refresh" content="0;./127.0.0.1:6060/pkg/'${CVSPATH}'/'${PROJECT}'/index.html"/></head><a href="./127.0.0.1:6060/pkg/'${CVSPATH}'/'${PROJECT}'/index.html">'${PKGNAME}' Documentation ...</a></html>' > target/docs/index.html
   169  
   170  # Alias to run all quality-assurance checks
   171  qa: fmtcheck test vet lint coverage cyclo ineffassign misspell structcheck varcheck errcheck gosimple astscan
   172  
   173  # --- INSTALL ---
   174  
   175  # Get the dependencies
   176  deps:
   177  	GOPATH=$(GOPATH) go get ./...
   178  	GOPATH=$(GOPATH) go get github.com/golang/lint/golint
   179  	GOPATH=$(GOPATH) go get github.com/jstemmer/go-junit-report
   180  	GOPATH=$(GOPATH) go get github.com/axw/gocov/gocov
   181  	GOPATH=$(GOPATH) go get github.com/fzipp/gocyclo
   182  	GOPATH=$(GOPATH) go get github.com/gordonklaus/ineffassign
   183  	GOPATH=$(GOPATH) go get github.com/client9/misspell/cmd/misspell
   184  	GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/structcheck
   185  	GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/varcheck
   186  	GOPATH=$(GOPATH) go get github.com/kisielk/errcheck
   187  	GOPATH=$(GOPATH) go get honnef.co/go/tools/cmd/gosimple
   188  	GOPATH=$(GOPATH) go get github.com/GoASTScanner/gas
   189  
   190  # Remove any build artifact
   191  clean:
   192  	GOPATH=$(GOPATH) go clean ./...
   193  
   194  # Deletes any intermediate file
   195  nuke:
   196  	rm -rf ./target
   197  	GOPATH=$(GOPATH) go clean -i ./...