Skip to content

Commit

Permalink
QoL feature to make building the example code binaries easier (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans authored Feb 12, 2025
1 parent 1d3d19b commit 0970c85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# Test binary, build with `go test -c`
*.test

#Example executables
examples/bin

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Swap
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
EXAMPLES_DIR:=./examples
GO_EXAMPLES_GO_MAINS:=$(wildcard $(EXAMPLES_DIR)/*/main.go)
EXAMPLES:=$(basename $(notdir $(patsubst %/,%,$(dir $(GO_EXAMPLES_GO_MAINS)))))
EXAMPLES_BIN_DIR:=$(EXAMPLES_DIR)/bin

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | cut -d":" -f2,3 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

Expand All @@ -18,4 +23,19 @@ all-checks: lint ## run all formatters
go mod tidy
go vet ./...

.PHONY: build-examples
build-examples: $(EXAMPLES)
@echo "Done!"

.PHONY:$(EXAMPLES)
.SECONDEXPANSION:
$(EXAMPLES):
@mkdir -p $(EXAMPLES_BIN_DIR)
@echo "Building example: $@"
@go build -o ./examples/bin/$@ ./examples/$@/main.go

.PHONY: clean
clean:
rm -rf $(EXAMPLES_BIN_DIR)

-include lint.mk

0 comments on commit 0970c85

Please sign in to comment.