gobot.io/x/gobot/v2@v2.1.0/Makefile (about)

     1  # include also examples in other than ./examples folder
     2  ALL_EXAMPLES := $(shell grep -l -r --include "*.go" 'build example' ./)
     3  # prevent examples with gocv (opencv) dependencies
     4  EXAMPLES_NO_GOCV := $(shell grep -L 'gocv' $(ALL_EXAMPLES))
     5  # prevent examples with joystick (sdl2) dependencies
     6  EXAMPLES_NO_JOYSTICK := $(shell grep -L 'joystick' $(ALL_EXAMPLES))
     7  # prevent examples with joystick (sdl2) and gocv (opencv) dependencies
     8  EXAMPLES_NO_GOCV_JOYSTICK := $(shell grep -L 'joystick' $$(grep -L 'gocv' $(EXAMPLES_NO_GOCV)))
     9  # used examples
    10  EXAMPLES := $(EXAMPLES_NO_GOCV_JOYSTICK)
    11  
    12  .PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES)
    13  
    14  # opencv platform currently skipped to prevent install of preconditions
    15  including_except := $(shell go list ./... | grep -v platforms/opencv)
    16  
    17  # Run tests on nearly all directories without test cache
    18  test:
    19  	go test -count=1 -v $(including_except)
    20  
    21  # Run tests with race detection
    22  test_race:
    23  	go test -race $(including_except)
    24  
    25  # Test, generate and show coverage in browser
    26  test_cover:
    27  	go test -v $(including_except) -coverprofile=coverage.txt ; \
    28  	go tool cover -html=coverage.txt ; \
    29  
    30  robeaux:
    31  ifeq (,$(shell which go-bindata))
    32  	$(error robeaux not built! https://github.com/jteeuwen/go-bindata is required to build robeaux assets )
    33  endif
    34  	cd api ; \
    35  	npm install robeaux ; \
    36  	cp -r node_modules/robeaux robeaux-tmp ; \
    37  	cd robeaux-tmp ; \
    38  	rm Makefile package.json README.markdown ; \
    39  	touch css/fonts.css ; \
    40  	echo "Updating robeaux..." ; \
    41  	go-bindata -pkg="robeaux" -o robeaux.go -ignore=\\.git ./... ; \
    42  	mv robeaux.go ../robeaux ; \
    43  	cd .. ; \
    44  	rm -rf robeaux-tmp/ ; \
    45  	rm -rf node_modules/ ; \
    46  	go fmt ./robeaux/robeaux.go ; \
    47  
    48  # Check for installed and module version match. Will exit with code 50 if not match.
    49  # There is nothing bad in general, if you program with a higher version.
    50  # At least the recipe "fmt_fix" will not work in that case.
    51  version_check:
    52  	@gv=$$(echo $$(go version) | sed "s/^.* go\([0-9].[0-9]*\).*/\1/") ; \
    53  	mv=$$(grep -m 1 'go 1.' ./go.mod | sed "s/^go \([0-9].[0-9]*\).*/\1/") ; \
    54  	echo "go: $${gv}.*, go.mod: $${mv}" ; \
    55  	if [ "$${gv}" != "$${mv}" ]; then exit 50; fi ; \
    56  
    57  # Check for bad code style and other issues
    58  fmt_check:
    59  	gofmt -l ./	
    60  	golangci-lint run -v
    61  
    62  # Fix bad code style (will only be executed, on version match)
    63  fmt_fix: version_check
    64  	go fmt ./...
    65  
    66  examples: $(EXAMPLES)
    67  
    68  examples_check: 
    69  	$(MAKE) CHECK=ON examples
    70  
    71  $(EXAMPLES):
    72  ifeq ($(CHECK),ON)
    73  	go vet ./$@
    74  else
    75  	go build -o /tmp/gobot_examples/$@ ./$@
    76  endif