Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking how makefile build help to remove gawk dependency #43

Merged
merged 1 commit into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,43 @@ release:
@goreleaser release --skip-publish --rm-dist

.PHONY: help
## Display this help screen - requires gawk
help:
@gawk 'match($$0, /^## (.*)/, a) \
{ getline x; x = gensub(/(.+:) .+/, "\\1", "g", x) ; \
printf "\033[36m%-30s\033[0m %s\n", x, a[1]; }' $(MAKEFILE_LIST) | sort

.PHONY: build
## Builds binary from source
build:
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "$(LD_FLAGS)" -o dist/dirstalk cmd/dirstalk/main.go

.PHONY: build
HELP_WIDTH=" "
## Display makefile help
help:
@printf "Usage\n";
@awk '{ \
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
helpCommand = substr($$0, index($$0, ":") + 2); \
if (helpMessage) { \
printf " \033[32m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
helpCommand = substr($$0, 0, index($$0, ":")); \
if (helpMessage) { \
printf " \033[32m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^##/) { \
if (helpMessage) { \
helpMessage = helpMessage"\n"${HELP_WIDTH}substr($$0, 3); \
} else { \
helpMessage = substr($$0, 3); \
} \
} else { \
if (helpMessage) { \
print "\n"${HELP_WIDTH}helpMessage"\n" \
} \
helpMessage = ""; \
} \
}' \
$(MAKEFILE_LIST)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ make build # to build an executable for your h

[dep](https://github.com/golang/dep) is the tool of choice for dependency management.

If you have [gawk](https://www.gnu.org/software/gawk/) available in your PATH you can also just launch
```bash
make help
```
to obtain a description of every command available in the Makefile.
will print a description of every command available in the Makefile.

Wanna add a functionality? fix a bug? fork and create a PR.

Expand Down