code.cestus.io/tools/fabricator@v0.4.3/Makefile (about)

     1  # Code generated by fabricator-generate-project-go
     2  #
     3  # Modifications in code regions will be lost during regeneration!
     4  #region CODE_REGION(Make)
     5  # Make is verbose in Linux. Make it silent.
     6  MAKEFLAGS += --silent
     7  include build.mk 
     8  # -----------------------------------------------------------------------------
     9  # DEFINES
    10  # -----------------------------------------------------------------------------
    11  TOOLS_MOD_DIR := ./tools
    12  # All directories with go.mod files  Used for building, testing and linting.
    13  ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)) 
    14  
    15  SHELL                   := sh
    16  SCRIPT_DIR              := hack
    17  IS_CI                   ?= 0
    18  BINARY_windows_ENDING   := .exe
    19  
    20  # Colors for shell
    21  NO_COLOR=\033[0m
    22  CYAN_COLOR=\033[0;36m
    23  
    24  # -----------------------------------------------------------------------------
    25  # CHECKS
    26  # -----------------------------------------------------------------------------
    27  HAS_GO                  := $(shell command -v go;)
    28  
    29  # -----------------------------------------------------------------------------
    30  # MACROS
    31  # -----------------------------------------------------------------------------
    32  
    33  # Check for Windows or Linux/Unix
    34  ifeq ($(OS),Windows_NT)
    35      msg = @powershell -Command "Write-Host \"$(1)\" -ForegroundColor Cyan"
    36  else
    37      msg = @printf '$(CYAN_COLOR)$(1)$(NO_COLOR)\n'
    38  endif
    39  
    40  # -----------------------------------------------------------------------------
    41  # TARGETS - GOLANG
    42  # -----------------------------------------------------------------------------
    43  # set default os and architecture to have common naming for build and build_all targets
    44  ifneq ($(HAS_GO),)
    45  	ifndef $(GOOS)
    46  		GOOS=$(shell go env GOOS)
    47  		export GOOS
    48  	endif
    49  	ifndef $(GOARCH)
    50  		GOARCH=$(shell go env GOARCH)
    51  		export GOARCH
    52  	endif
    53  endif
    54  
    55  LDFLAGS += $(ADDITIONALLDFLAGS)
    56  LDFLAGS += -X code.cestus.io/libs/buildinfo.version=${goModuleBuildVersion}
    57  LDFLAGS += -X code.cestus.io/libs/buildinfo.buildDate=$(VERSION_DATE)
    58  export LDFLAGS
    59  
    60  # building platform string
    61  b_platform = --> Building $(APP)-$(GOOS)-$(GOARCH)\n
    62  # building platform command
    63  ifeq ($(OS),Windows_NT)
    64      b_command = export GOOS=$(GOOS); export GOARCH=$(GOARCH); export CGO_ENABLED=0; go build -ldflags "$(LDFLAGS) -X code.cestus.io/libs/buildinfo.name=$(APP)" -o $(BINDIR)/$(APP)-$(GOOS)-$(GOARCH)$(BINARY_$(GOOS)_ENDING) ./cmd/$(APP)/ ;
    65  else
    66      b_command = export GOOS=$(GOOS); export GOARCH=$(GOARCH); export CGO_ENABLED=1; go build -ldflags "$(LDFLAGS) -X code.cestus.io/libs/buildinfo.name=$(APP)" -o $(BINDIR)/$(APP)-$(GOOS)-$(GOARCH)$(BINARY_$(GOOS)_ENDING) ./cmd/$(APP)/ ;
    67  endif
    68  # build everything command
    69  ifeq ($(OS),Windows_NT)
    70      be_command = export GOOS=$(GOOS); export GOARCH=$(GOARCH); export CGO_ENABLED=0; go build ./... ;
    71  else
    72      be_command = export GOOS=$(GOOS); export GOARCH=$(GOARCH); export CGO_ENABLED=1; go build ./... ;
    73  endif
    74  # for each iterations use build message
    75  fb_platforms =$(foreach GOOS, $(PLATFORMS),$(foreach GOARCH, $(ARCHITECTURES),$(foreach APP, $(APPLICATIONS),$(b_platform))))
    76  # for each iterations use build message
    77  fbe_platforms =$(foreach GOOS, $(PLATFORMS),$(foreach GOARCH, $(ARCHITECTURES),$(b_platform)))
    78  # foreach iterations to do multi platform build
    79  fb_command = $(foreach GOOS, $(PLATFORMS),\
    80  	$(foreach GOARCH, $(ARCHITECTURES),$(foreach APP, $(APPLICATIONS),$(b_command))))
    81  # foreach iterations to do multi platform build
    82  fbe_command = $(foreach GOOS, $(PLATFORMS),\
    83  	$(foreach GOARCH, $(ARCHITECTURES),$(be_command)))
    84  
    85  .PHONY: all
    86  ## Builds for all platforms and architectures (including generation and setup and tests)
    87  all: generate build_all test
    88  	
    89  # No documentation; Installs tools
    90  setup:
    91  	
    92  .PHONY: clean
    93  ## Cleans generation folders
    94  clean:
    95  
    96  .PHONY: generate
    97  ## Generate files
    98  generate:
    99  	set -e; for dir in $(ALL_GO_MOD_DIRS); do \
   100  		echo "go generate $${dir}/..."; \
   101  		(cd "$${dir}" && \
   102  			go generate ./...); \
   103  	done
   104  
   105  .PHONY: compile
   106  ## Compile for current platform and architecture
   107  compile: 
   108  	$(call msg, $(b_platform))
   109  	@$(b_command)
   110  
   111  .PHONY: compile_all
   112  ## Compile for all platforms, architectures and apps
   113  ## Thows error if a invalid GOOS/GOARCH combo gets generated
   114  compile_all: 
   115  	$(call msg, $(fb_platforms))
   116  	@$(fb_command)
   117  
   118  .PHONY: build
   119  ## Build (including generation and setup) for the current platform
   120  build: setup generate compile
   121  
   122  .PHONY: install_tools
   123  install_tools:
   124  	 if [ -d "tools" ]; then $(MAKE) -C tools all ;fi
   125  
   126  .PHONY: build_all
   127  ## Builds for all platforms and architectures (including generation and setup)
   128  build_all: install_tools build_all_ci
   129  
   130  .PHONY: build_all_ci
   131  ## Builds for all platforms and architectures (including generation and setup)
   132  build_all_ci: setup $(ADDITIONAL_CI_STEPS) compile_all compile_absolute_everything changelog
   133  
   134  .PHONY: compile_absolute_everything
   135  ## Builds all files even those not part of the desired outputs
   136  compile_absolute_everything:
   137  	$(call msg, --> Building all files even those not part of the desired apps)
   138  	$(call msg, $(fbe_platforms))
   139  	set -e; for dir in $(ALL_GO_MOD_DIRS); do \
   140  		echo "go build $${dir}/..."; \
   141  		(cd "$${dir}" && \
   142  			$(fbe_command));\
   143  	done
   144  
   145  .PHONY: test
   146  ## Runs the tests
   147  test: install_tools
   148  ifeq ($(OS),Windows_NT)
   149  		set -e; for dir in $(ALL_GO_MOD_DIRS); do \
   150  		echo "ginkgo $${dir}/..."; \
   151  		(cd "$${dir}" && \
   152  		export CGO_ENABLED=0; ginkgo --output-dir=. ./...); \
   153  		done; 
   154  else
   155  		set -e; for dir in $(ALL_GO_MOD_DIRS); do \
   156  		echo "ginkgo $${dir}/..."; \
   157  		(cd "$${dir}" && \
   158  		export CGO_ENABLED=1; ginkgo -race --output-dir=. ./...); \
   159  		done;
   160  endif
   161  
   162  .PHONY: changelog
   163  changelog:
   164  	$(call msg, --> Generating changelog)
   165  	git-chglog --next-tag $(goModuleBuildVersion) 1> /dev/null && ([ $$? -eq 0 ] && git-chglog --next-tag $(goModuleBuildVersion) -o CHANGELOG.md) || echo "changelog failure!"
   166  
   167  .PHONY: vuln
   168  vuln: install_tools $(ADDITIONAL_CI_STEPS)
   169  	set -e; for dir in $(ALL_GO_MOD_DIRS); do \
   170  		echo "govulncheck  $${dir}/..."; \
   171  		(cd "$${dir}" && \
   172  			govulncheck  ./...); \
   173  	done
   174  # Plonk the following at the end of your Makefile
   175  .DEFAULT_GOAL := show-help
   176  
   177  # Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
   178  # sed script explained:
   179  # /^##/:
   180  # 	* save line in hold space
   181  # 	* purge line
   182  # 	* Loop:
   183  # 		* append newline + line to hold space
   184  # 		* go to next line
   185  # 		* if line starts with doc comment, strip comment character off and loop
   186  # 	* remove target prerequisites
   187  # 	* append hold space (+ newline) to line
   188  # 	* replace newline plus comments by `---`
   189  # 	* print line
   190  # Separate expressions are necessary because labels cannot be delimited by
   191  # semicolon; see <http://stackoverflow.com/a/11799865/1968>
   192  .PHONY: show-help
   193  show-help:
   194  	@echo "$$(tput bold)Available rules:$$(tput sgr0)"
   195  	@echo
   196  	@sed -n -e "/^## / { \
   197  		h; \
   198  		s/.*//; \
   199  		:doc" \
   200  		-e "H; \
   201  		n; \
   202  		s/^## //; \
   203  		t doc" \
   204  		-e "s/:.*//; \
   205  		G; \
   206  		s/\\n## /---/; \
   207  		s/\\n/ /g; \
   208  		p; \
   209  	}" ${MAKEFILE_LIST} \
   210  	| LC_ALL='C' sort --ignore-case \
   211  	| awk -F '---' \
   212  		-v ncol=$$(tput cols) \
   213  		-v indent=19 \
   214  		-v col_on="$$(tput setaf 6)" \
   215  		-v col_off="$$(tput sgr0)" \
   216  	'{ \
   217  		printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
   218  		n = split($$2, words, " "); \
   219  		line_length = ncol - indent; \
   220  		for (i = 1; i <= n; i++) { \
   221  			line_length -= length(words[i]) + 1; \
   222  			if (line_length <= 0) { \
   223  				line_length = ncol - indent - length(words[i]) - 1; \
   224  				printf "\n%*s ", -indent, " "; \
   225  			} \
   226  			printf "%s ", words[i]; \
   227  		} \
   228  		printf "\n"; \
   229  	}'
   230  # endregion