github.com/per1234/editorconfig-checker/v2@v2.8.5/Makefile (about)

     1  ifeq ($(OS),Windows_NT)
     2  	STDERR=con
     3  else
     4  	STDERR=/dev/stderr
     5  endif
     6  
     7  ifeq ($(wildcard "C:/Program Files/Git/usr/bin/*"),)
     8  export PATH:="C:/Program Files/Git/usr/bin:$(PATH)"
     9  endif
    10  
    11  EXE=bin/ec$(EXEEXT)
    12  SRC_DIR := $(shell dirname "$(realpath "$(firstword $(MAKEFILE_LIST))")")
    13  SOURCES = $(shell find "$(SRC_DIR)" -type f -name "*.go")
    14  GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
    15  GIT_BRANCH_UP_TO_DATE = $(shell git remote show origin | tail -n1 | sed "s/.*(\(.*\))/\1/")
    16  CURRENT_VERSION = $(shell cat VERSION | tr -d "\n")
    17  
    18  prefix = /usr/local
    19  bindir = /bin
    20  mandir = /share/man
    21  
    22  all: build ## Build bin/ec
    23  
    24  clean: ## Clean bin/ directory
    25  	rm -f ./bin/*
    26  
    27  define _build
    28  go build -ldflags "-X main.version=$(CURRENT_VERSION)" -o $1 ./cmd/editorconfig-checker/main.go
    29  endef
    30  
    31  $(EXE): $(SOURCES) VERSION
    32  	$(call _build,$(EXE))
    33  
    34  build: $(EXE) ## Build bin/ec
    35  
    36  install: build ## Build and install executable in PATH
    37  	install -D $(EXE) $(DESTDIR)$(prefix)$(bindir)/editorconfig-checker
    38  	install -D docs/editorconfig-checker.1 $(DESTDIR)$(prefix)$(mandir)/man1/editorconfig-checker.1
    39  
    40  uninstall: ## Remove executable from PATH
    41  	rm -f $(DESTDIR)$(prefix)$(bindir)/editorconfig-checker
    42  	rm -f $(DESTDIR)$(prefix)$(mandir)/man1/editorconfig-checker.1
    43  
    44  test: ## Run test suite
    45  	@go test -race -coverprofile=coverage.txt -covermode=atomic ./...
    46  	@go vet ./...
    47  	@test -z $(shell gofmt -s -l . | tee $(STDERR)) || (echo "[ERROR] Fix formatting issues with 'gofmt'" && exit 1)
    48  
    49  bench: ## Run benchmark
    50  	go test -bench=. ./**/*/
    51  
    52  run: build ## Build and run bin/ec
    53  	@./bin/ec --exclude "\\.git" --exclude "\\.exe$$"
    54  
    55  run-verbose: build ## Build and run bin/ec --verbose
    56  	@./bin/ec --verbose --exclude "\\.git" --exclude "\\.exe$$"
    57  
    58  release: _is_main_branch _git_branch_is_up_to_date _do_release ## Create release
    59  	@echo Release done. Go to Github and create a release.
    60  
    61  _is_main_branch:
    62  ifneq ($(GIT_BRANCH),main)
    63  	@echo You are not on the main branch.
    64  	@echo Please check out the main and try to release again
    65  	@false
    66  endif
    67  
    68  _git_branch_is_up_to_date:
    69  ifneq ($(GIT_BRANCH_UP_TO_DATE),up to date)
    70  	@echo Your main branch is not up to date.
    71  	@echo Please push your changes or pull changes from the remote.
    72  	@false
    73  endif
    74  
    75  current_version: ## Display current version
    76  	@echo the current version is: $(CURRENT_VERSION)
    77  
    78  _do_release: _checkout clean _tag_version build run _build-all-binaries _compress-all-binaries
    79  	git checkout main
    80  	git merge --no-ff release
    81  	git push origin main && git push origin main --tags
    82  
    83  _checkout:
    84  	git branch -D release; git checkout -b release
    85  
    86  _tag_version: current_version
    87  	@read -p "Enter version to release: " version && \
    88  	echo $${version} > VERSION && \
    89  	sed -i "s/VERSION=".*"/VERSION=\"$${version}\"/" ./README.md && \
    90  	sed -i "s/\"Version\": \".*\",/\"Version\": \"$${version}\",/" .ecrc && \
    91  	sed -i "s/\"Version\": \".*\",/\"Version\": \"$${version}\",/" testfiles/generated-config.json && \
    92  	sed -i "s/${CURRENT_VERSION}/$${version}/" ./pkg/config/config_test.go && \
    93  	git add . && git commit -m "chore(release): $${version}" && git tag "$${version}"
    94  
    95  define _build_target
    96  CGO_ENABLED=0 GOOS=$(subst /,,$(dir $1)) GOARCH=$(notdir $1) $(call _build,bin/ec-$(subst /,,$(dir $1))-$(notdir $1)$2)
    97  endef
    98  
    99  _build-all-binaries:
   100  	@# To generate list of supported targets, run:
   101  	@#  go tool dist list
   102  	$(call _build_target,aix/ppc64)
   103  	@# gcc.exe: error: unrecognized command-line option '-rdynamic'
   104  	@# $(call _build_target,android/386)
   105  	@# gcc.exe: error: unrecognized command-line option '-rdynamic'
   106  	@# $(call _build_target,android/amd64)
   107  	@# gcc.exe: error: unrecognized command-line option '-marm'; did you mean '-mabm'?
   108  	@# gcc.exe: error: unrecognized command-line option '-rdynamic'
   109  	@# $(call _build_target,android/arm)
   110  	$(call _build_target,android/arm64)
   111  	$(call _build_target,darwin/amd64)
   112  	$(call _build_target,darwin/arm64)
   113  	$(call _build_target,dragonfly/amd64)
   114  	$(call _build_target,freebsd/386)
   115  	$(call _build_target,freebsd/amd64)
   116  	$(call _build_target,freebsd/arm)
   117  	$(call _build_target,freebsd/arm64)
   118  	$(call _build_target,illumos/amd64)
   119  	@# gcc.exe: error: unrecognized command-line option '-framework'
   120  	@# $(call _build_target,ios/amd64)
   121  	@# gcc.exe: error: unrecognized command-line option '-framework'
   122  	@# $(call _build_target,ios/arm64)
   123  	$(call _build_target,js/wasm)
   124  	$(call _build_target,linux/386)
   125  	$(call _build_target,linux/amd64)
   126  	$(call _build_target,linux/arm)
   127  	$(call _build_target,linux/arm64)
   128  	$(call _build_target,linux/mips)
   129  	$(call _build_target,linux/mips64)
   130  	$(call _build_target,linux/mips64le)
   131  	$(call _build_target,linux/mipsle)
   132  	$(call _build_target,linux/ppc64)
   133  	$(call _build_target,linux/ppc64le)
   134  	$(call _build_target,linux/riscv64)
   135  	$(call _build_target,linux/s390x)
   136  	$(call _build_target,netbsd/386)
   137  	$(call _build_target,netbsd/amd64)
   138  	$(call _build_target,netbsd/arm)
   139  	$(call _build_target,netbsd/arm64)
   140  	$(call _build_target,openbsd/386)
   141  	$(call _build_target,openbsd/amd64)
   142  	$(call _build_target,openbsd/arm)
   143  	$(call _build_target,openbsd/arm64)
   144  	$(call _build_target,openbsd/mips64)
   145  	$(call _build_target,plan9/386)
   146  	$(call _build_target,plan9/amd64)
   147  	$(call _build_target,plan9/arm)
   148  	$(call _build_target,solaris/amd64)
   149  	$(call _build_target,windows/386,.exe)
   150  	$(call _build_target,windows/amd64,.exe)
   151  	$(call _build_target,windows/arm,.exe)
   152  	$(call _build_target,windows/arm64,.exe)
   153  
   154  _compress-all-binaries:
   155  	for f in bin/*; do      \
   156  		tar czf $$f.tar.gz $$f;    \
   157  		rm -f $$f;    \
   158  	done
   159  
   160  _release_dockerfile: _build_dockerfile _push_dockerfile
   161  
   162  _build_dockerfile:
   163  	docker build -t mstruebing/editorconfig-checker:$(shell grep 'const version' cmd/editorconfig-checker/main.go | sed 's/.*"\(.*\)"/\1/') .
   164  
   165  _push_dockerfile:
   166  	docker push mstruebing/editorconfig-checker:$(shell grep 'const version' cmd/editorconfig-checker/main.go | sed 's/.*"\(.*\)"/\1/')
   167  
   168  nix-build: ## Build for nix
   169  	nix-build -E 'with import <nixpkgs> { }; callPackage ./default.nix {}'
   170  
   171  nix-install: ## Install on nix
   172  	nix-env -i -f install.nix
   173  
   174  nix-update-dependencies: ## Update nix dependencies
   175  	nix-shell -p vgo2nix --run vgo2nix
   176  
   177  PHONY += help
   178  help: ## Display available commands
   179  	@awk -F ':.*##[ \t]*' '/^[^#: \t]+:.*##/ {printf "\033[36m%-23s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
   180  
   181  PHONY += dumpvars
   182  dumpvars: ## Dump variables
   183  	@echo CURRENT_VERSION=$(CURRENT_VERSION)
   184  	@echo EXE=$(EXE)
   185  	@echo EXEEXT=$(EXEEXT)
   186  	@echo GIT_BRANCH=$(GIT_BRANCH)
   187  	@echo GIT_BRANCH_UP_TO_DATE=$(GIT_BRANCH_UP_TO_DATE)
   188  	@echo STDERR=$(STDERR)
   189  	@echo SRC_DIR=$(SRC_DIR)
   190  	@echo SOURCES=$(SOURCES)
   191  
   192  .PHONY: $(PHONY) clean build install uninstall test bench run run-verbose release _is_main_branch _git_branch_is_up_to_date current_version _do_release _tag_version _build-all-binaries _compress-all-binaries _release_dockerfile _build_dockerfile _push_dockerfile nix-build nix-install nix-update-dependencies