Skip to content

Commit 9273c7c

Browse files
committed
Makefile refactor to use Makes resuable parts
Lock to commit bc32749a8dcc250e375b3a6d3572c3260a972efb to be safe With this setup, one not need to have a go installed. Adds support for:\ * make shell * make build Inside shell after `make build`, `glj` will be in PATH.
1 parent 2daaa05 commit 9273c7c

File tree

1 file changed

+66
-26
lines changed

1 file changed

+66
-26
lines changed

Makefile

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
GO-VERSION ?= 1.22.0
11+
include $M/go.mk
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/
118

219
CLOJURE_STDLIB_VERSION := clojure-1.12.1
320
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
@@ -9,66 +26,89 @@ STDLIB_TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))
926
TEST_FILES := $(shell find ./test -name '*.glj' | sort)
1027
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))
1128

12-
GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
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)
40+
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:
60+
ifdef OA
61+
build: $(GLJ)
62+
endif
63+
64+
generate: $(GO)
3265
@go generate ./...
3366

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)
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: \
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:
94+
vet: $(GO)
5695
@go vet ./...
5796

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

62100
.PHONY: test
63101
test: vet $(TEST_TARGETS)
64102

65-
.PHONY: format
66103
format:
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:
74110
@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)