BUILDDIR := build DIRS := $(shell ls -d */) .PHONY: build build: mkdir -p $(BUILDDIR); \ for dir in $(DIRS); do \ if [ ! -f "$$dir/main.go" ]; then \ continue; \ fi; \ pkg=$${dir%/}; \ go build -o $(BUILDDIR)/$$pkg ./$$dir/main.go; \ done .PHONY: test test: for bin in $(BUILDDIR)/*; do \ echo "\n"; \ $$bin; \ done; \ echo "\nAll Go examples executed.\n" .PHONY: clean clean: rm -rf $(BUILDDIR)/* .PHONY: all all: build test clean