diff --git a/.gitignore b/.gitignore index cc6c755..ea40f4d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,13 @@ # Go workspace file go.work + +# macOS artifacts +.DS_STORE + +# Visual Studio code +.vscode .history -target/ \ No newline at end of file + +# Makefile +target/ diff --git a/Makefile b/Makefile index 747a477..9a315b8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile for go-cmdhelping. -# Detect the operating system and architecture +# Detect the operating system and architecture. include Makefile.osdetect @@ -23,13 +23,13 @@ BUILD_TAG := $(shell git describe --always --tags --abbrev=0 | sed 's/v//') BUILD_ITERATION := $(shell git log $(BUILD_TAG)..HEAD --oneline | wc -l | sed 's/^ *//') GIT_REMOTE_URL := $(shell git config --get remote.origin.url) GO_PACKAGE_NAME := $(shell echo $(GIT_REMOTE_URL) | sed -e 's|^git@github.com:|github.com/|' -e 's|\.git$$||' -e 's|Senzing|senzing|') -GO_OSARCH = $(subst /, ,$@) -GO_OS = $(word 1, $(GO_OSARCH)) -GO_ARCH = $(word 2, $(GO_OSARCH)) # Recursive assignment ('=') CC = gcc +GO_OSARCH = $(subst /, ,$@) +GO_OS = $(word 1, $(GO_OSARCH)) +GO_ARCH = $(word 2, $(GO_OSARCH)) # Conditional assignment. ('?=') # Can be overridden with "export" @@ -41,9 +41,6 @@ LD_LIBRARY_PATH ?= /opt/senzing/g2/lib .EXPORT_ALL_VARIABLES: --include Makefile.$(OSTYPE) --include Makefile.$(OSTYPE)_$(OSARCH) - # ----------------------------------------------------------------------------- # The first "make" target runs as default. # ----------------------------------------------------------------------------- @@ -52,8 +49,14 @@ LD_LIBRARY_PATH ?= /opt/senzing/g2/lib default: help # ----------------------------------------------------------------------------- -# Build -# - The "build" target is implemented in Makefile.OS.ARCH files. +# Operating System / Architecture targets +# ----------------------------------------------------------------------------- + +-include Makefile.$(OSTYPE) +-include Makefile.$(OSTYPE)_$(OSARCH) + +# ----------------------------------------------------------------------------- +# Dependency management # ----------------------------------------------------------------------------- .PHONY: dependencies @@ -62,6 +65,11 @@ dependencies: @go get -t -u ./... @go mod tidy +# ----------------------------------------------------------------------------- +# Build +# - The "build" target is implemented in Makefile.OS.ARCH files. +# - docker-build: https://docs.docker.com/engine/reference/commandline/build/ +# ----------------------------------------------------------------------------- PLATFORMS := darwin/amd64 linux/amd64 windows/amd64 $(PLATFORMS): @@ -83,45 +91,11 @@ test: @go test -v -p 1 ./... # @go test -v ./engineconfiguration -# ----------------------------------------------------------------------------- -# docker-build -# - https://docs.docker.com/engine/reference/commandline/build/ -# ----------------------------------------------------------------------------- - -.PHONY: docker-build -docker-build: - @docker build \ - --build-arg BUILD_ITERATION=$(BUILD_ITERATION) \ - --build-arg BUILD_VERSION=$(BUILD_VERSION) \ - --build-arg GO_PACKAGE_NAME=$(GO_PACKAGE_NAME) \ - --build-arg PROGRAM_NAME=$(PROGRAM_NAME) \ - --file Dockerfile \ - --tag $(DOCKER_IMAGE_NAME) \ - --tag $(DOCKER_IMAGE_NAME):$(BUILD_VERSION) \ - . - - -.PHONY: docker-build-package -docker-build-package: - @docker build \ - --build-arg BUILD_ITERATION=$(BUILD_ITERATION) \ - --build-arg BUILD_VERSION=$(BUILD_VERSION) \ - --build-arg GO_PACKAGE_NAME=$(GO_PACKAGE_NAME) \ - --build-arg PROGRAM_NAME=$(PROGRAM_NAME) \ - --no-cache \ - --file package.Dockerfile \ - --tag $(DOCKER_BUILD_IMAGE_NAME) \ - . # ----------------------------------------------------------------------------- # Run # ----------------------------------------------------------------------------- -.PHONY: run -run: - @go run main.go - - .PHONY: docker-run docker-run: @docker run \ @@ -130,16 +104,15 @@ docker-run: --name $(DOCKER_CONTAINER_NAME) \ $(DOCKER_IMAGE_NAME) + +.PHONY: run +run: + @go run main.go + # ----------------------------------------------------------------------------- # Utility targets # ----------------------------------------------------------------------------- -.PHONY: update-pkg-cache -update-pkg-cache: - @GOPROXY=https://proxy.golang.org GO111MODULE=on \ - go get $(GO_PACKAGE_NAME)@$(BUILD_TAG) - - .PHONY: clean clean: @go clean -cache @@ -150,26 +123,26 @@ clean: @rm -f $(GOPATH)/bin/$(PROGRAM_NAME) || true +.PHONY: help +help: + @echo "Build $(PROGRAM_NAME) version $(BUILD_VERSION)-$(BUILD_ITERATION)". + @echo "Makefile targets:" + @$(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs + + .PHONY: print-make-variables print-make-variables: @$(foreach V,$(sort $(.VARIABLES)), \ $(if $(filter-out environment% default automatic, \ $(origin $V)),$(warning $V=$($V) ($(value $V))))) -# ----------------------------------------------------------------------------- -# Help -# ----------------------------------------------------------------------------- -.PHONY: help -help: - @echo "Build $(PROGRAM_NAME) version $(BUILD_VERSION)-$(BUILD_ITERATION)". - @echo "Makefile targets:" - @$(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs +.PHONY: setup +setup: + @echo "No setup required." -# ----------------------------------------------------------------------------- -# Optionally include platform-specific settings and targets. -# - Note: This is last because the "last one wins" when over-writing targets. -# ----------------------------------------------------------------------------- -# -include Makefile.$(OSTYPE) -# -include Makefile.$(OSTYPE)_$(OSARCH) \ No newline at end of file +.PHONY: update-pkg-cache +update-pkg-cache: + @GOPROXY=https://proxy.golang.org GO111MODULE=on \ + go get $(GO_PACKAGE_NAME)@$(BUILD_TAG) diff --git a/Makefile.darwin b/Makefile.darwin index b6f366a..d03e58a 100644 --- a/Makefile.darwin +++ b/Makefile.darwin @@ -21,4 +21,4 @@ build: darwin/amd64 .PHONY: only-darwin only-darwin: - @echo "Only darwin has this Makefile target." \ No newline at end of file + @echo "Only darwin has this Makefile target." diff --git a/Makefile.linux b/Makefile.linux index 1a0df4a..741c682 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -21,4 +21,4 @@ build: linux/amd64 .PHONY: only-linux only-linux: - @echo "Only linux has this Makefile target." \ No newline at end of file + @echo "Only linux has this Makefile target." diff --git a/Makefile.windows b/Makefile.windows index 44f29ff..3a3dbcb 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -22,4 +22,4 @@ build: windows/amd64 .PHONY: only-windows only-windows: - @echo "Only windows has this Makefile target." \ No newline at end of file + @echo "Only windows has this Makefile target." diff --git a/go.mod b/go.mod index 82d444d..466f79f 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.4.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index dfd02cc..09754ec 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= -github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=