Skip to content

Commit 0234615

Browse files
committed
Makefile refactor to use the Makes makefile system
See: https://github.com/makeplus/makes With this setup, one not need to have Go or Clojure installed. The Makefile takes care of everything. You can easily override Go and Clojure versions with `GO-VERSION` and `CLOJURE-VERSION` make variables: make test GO-VERSION=1.23.4 Makefile autoinstalls the `makes` repo, Go and Clojure deps under `.cache/`. Adds support for: * make shell - Start subshell with local go in PATH * make build - Build glj * make clean - Remove build artifacts * make distclean - Clean and remove .cache dir Inside shell after `make build`, `glj` will be in PATH. We lock the makeplus/makes repo to commit ca8c2c25e66cf6bfcf8c993502de5b98da5beaf5 to be make sure everyone gets the same results forever. Updates Makefile variables to use `-` instead of `_`. Variables with `_` can come from the environment. With `-` they are only recognized by make. You can override in the shell with `make something FOO-BAR=123`. `.PHONY` is only needed when phony targets have matching file system names. `test` is the only one here.
1 parent 043d917 commit 0234615

File tree

2 files changed

+86
-41
lines changed

2 files changed

+86
-41
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
bin
22
doc/repl/glj.wasm
3+
/.cache/
4+
/.clj-kondo/
5+
/.lsp/
6+
/.vscode/
7+
/*.clj

Makefile

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,114 @@
1+
M := $(or $(MAKES_REPO_DIR),.cache/makes)
2+
C := ca8c2c25e66cf6bfcf8c993502de5b98da5beaf5
3+
$(shell [ -d $M ] || git clone -q https://github.com/makeplus/makes $M)
4+
$(shell [ -d $M ] || ( \
5+
git clone -depth=1 -q https://github.com/makeplus/makes $M && \
6+
git -C $M reset -q --hard $C))
7+
include $M/init.mk
8+
MAKES-NO-RULES := true
9+
GO-VERSION ?= 1.19.3
10+
include $M/go.mk
11+
CLOJURE-VERSION := 1.12.1.1550
12+
include $M/clojure.mk
13+
include $M/clean.mk
14+
include $M/shell.mk
15+
16+
MAKES-CLEAN := bin/
17+
MAKES-DISTCLEAN := .cache/ .clj-kondo/ .lsp/ .vscode/
18+
19+
CLOJURE-STDLIB-VERSION := clojure-1.12.1
20+
STDLIB-ORIGINALS-DIR := scripts/rewrite-core/originals
21+
STDLIB-ORIGINALS := $(shell find $(STDLIB-ORIGINALS-DIR) -name '*.clj')
22+
STDLIB := $(STDLIB-ORIGINALS:scripts/rewrite-core/originals/%=%)
23+
STDLIB-ORIGINALS := $(addprefix scripts/rewrite-core/originals/,$(STDLIB))
24+
STDLIB-TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))
25+
26+
TEST-FILES := $(shell find ./test -name '*.glj' | sort)
27+
TEST-TARGETS := $(addsuffix .test,$(TEST-FILES))
28+
29+
GOPLATFORMS := \
30+
darwin_arm64 \
31+
darwin_amd64 \
32+
linux_arm64 \
33+
linux_amd64 \
34+
windows_amd64 \
35+
windows_arm \
36+
js_wasm \
37+
38+
# Set PATH so that glj is in the PATH after 'make shell'
39+
override PATH := $(subst $(space),:,$(GOPLATFORMS:%=bin/%)):$(PATH)
140

2-
CLOJURE_STDLIB_VERSION := clojure-1.12.1
3-
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
4-
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
5-
STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
6-
STDLIB_ORIGINALS := $(addprefix scripts/rewrite-core/originals/,$(STDLIB))
7-
STDLIB_TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))
8-
9-
TEST_FILES := $(shell find ./test -name '*.glj' | sort)
10-
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))
11-
12-
GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
1341
GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go)
1442
# wasm should have .wasm suffix; others should not
1543
BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
1644

17-
# eventually, support multiple minor versions
18-
GO_VERSION := 1.19.3
19-
GO_CMD := go$(GO_VERSION)
45+
GLJ-DEPS := \
46+
$(wildcard ./cmd/glj/*.go) \
47+
$(wildcard ./pkg/**/*.go) \
48+
$(wildcard ./internal/**/*.go) \
49+
50+
all: $(STDLIB-TARGETS) generate $(GLJIMPORTS) $(BINS)
2051

21-
.PHONY: all
22-
all: gocmd $(STDLIB_TARGETS) generate $(GLJIMPORTS) $(BINS)
52+
OA-linux-arm64 := linux_arm64
53+
OA-linux-int64 := linux_amd64
54+
OA-macos-arm64 := darwin_arm64
55+
OA-macos-int64 := darwin_amd64
56+
OA := $(OA-$(OS-ARCH))
2357

24-
.PHONY: gocmd
25-
gocmd:
26-
@$(GO_CMD) version 2>&1 > /dev/null || \
27-
(go install "golang.org/dl/$(GO_CMD)@latest" && \
28-
$(GO_CMD) download > /dev/null && $(GO_CMD) version > /dev/null)
58+
GLJ := bin/$(OA)/glj
2959

30-
.PHONY: generate
31-
generate:
32-
@go generate ./...
60+
ifdef OA
61+
build: $(GLJ)
62+
endif
3363

34-
pkg/gen/gljimports/gljimports_%.go: ./scripts/gen-gljimports.sh ./cmd/gen-import-interop/main.go ./internal/genpkg/genpkg.go \
35-
$(wildcard ./pkg/lang/*.go) $(wildcard ./pkg/runtime/*.go)
64+
generate: $(GO)
65+
go generate ./...
66+
67+
pkg/gen/gljimports/gljimports_%.go: $(GO) \
68+
./scripts/gen-gljimports.sh \
69+
./cmd/gen-import-interop/main.go \
70+
./internal/genpkg/genpkg.go \
71+
$(wildcard ./pkg/lang/*.go) \
72+
$(wildcard ./pkg/runtime/*.go)
3673
@echo "Generating $@"
37-
@./scripts/gen-gljimports.sh $@ $* $(GO_CMD)
74+
@./scripts/gen-gljimports.sh $@ $* go
3875

39-
pkg/stdlib/glojure/%.glj: scripts/rewrite-core/originals/%.clj scripts/rewrite-core/run.sh scripts/rewrite-core/rewrite.clj
76+
pkg/stdlib/glojure/%.glj: $(CLOJURE) \
77+
scripts/rewrite-core/originals/%.clj \
78+
scripts/rewrite-core/run.sh \
79+
scripts/rewrite-core/rewrite.clj
4080
@echo "Rewriting $< to $@"
4181
@mkdir -p $(dir $@)
4282
@scripts/rewrite-core/run.sh $< > $@
4383

44-
bin/%/glj: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
84+
bin/%/glj: $(GLJ-DEPS)
4585
@echo "Building $@"
4686
@mkdir -p $(dir $@)
4787
@scripts/build-glj.sh $@ $*
4888

49-
bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
89+
bin/%/glj.wasm: $(GLJ-DEPS)
5090
@echo "Building $@"
5191
@mkdir -p $(dir $@)
5292
@scripts/build-glj.sh $@ $*
5393

54-
.PHONY: vet
55-
vet:
56-
@go vet ./...
94+
vet: $(GO)
95+
go vet ./...
5796

58-
.PHONY: $(TEST_TARGETS)
59-
$(TEST_TARGETS): gocmd
60-
@$(GO_CMD) run ./cmd/glj/main.go $(basename $@)
97+
$(TEST-TARGETS): $(GO)
98+
go run ./cmd/glj/main.go $(basename $@)
6199

62100
.PHONY: test
63-
test: vet $(TEST_TARGETS)
101+
test: vet $(TEST-TARGETS)
64102

65-
.PHONY: format
66-
format:
103+
format: $(GO)
67104
@if go fmt ./... | grep -q ''; then \
68105
echo "Files were formatted. Please commit the changes."; \
69106
exit 1; \
70107
fi
71108

72-
.PHONY: update-clojure-sources
73109
update-clojure-sources:
74-
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE_STDLIB_VERSION)
110+
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE-STDLIB-VERSION)
111+
112+
test-bug: $(GLJ)
113+
-glj <(echo '(throw (Exception. "foo"))')
114+
-glj <(echo '(throw (new Exception "foo"))')

0 commit comments

Comments
 (0)