Skip to content

Commit b1c1c81

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 a2bebb9 commit b1c1c81

2 files changed

Lines changed: 84 additions & 66 deletions

File tree

.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: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,116 @@
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+
GOPLATFORMS := \
27+
darwin_arm64 \
28+
darwin_amd64 \
29+
linux_arm64 \
30+
linux_amd64 \
31+
windows_amd64 \
32+
windows_arm \
33+
js_wasm \
34+
35+
# Set PATH so that glj is in the PATH after 'make shell'
36+
override PATH := $(subst $(space),:,$(GOPLATFORMS:%=bin/%)):$(PATH)
37+
38+
GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go)
39+
# wasm should have .wasm suffix; others should not
40+
BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
41+
42+
GLJ-DEPS := \
43+
$(GO) \
44+
$(wildcard ./cmd/glj/*.go) \
45+
$(wildcard ./pkg/**/*.go) \
46+
$(wildcard ./internal/**/*.go) \
47+
48+
all: $(STDLIB-TARGETS) generate $(GLJIMPORTS) $(BINS)
149

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-
OS-TYPE := $(shell bash -c 'echo $$OSTYPE')
10-
OS-NAME := \
11-
$(if $(findstring darwin,$(OS-TYPE))\
12-
,macos,$(if $(findstring linux,$(OS-TYPE)),linux,))
13-
ARCH-TYPE := $(shell bash -c 'echo $$MACHTYPE')
14-
ARCH-NAME := \
15-
$(if $(or $(findstring arm64,$(ARCH-TYPE)),\
16-
$(findstring aarch64,$(ARCH-TYPE)))\
17-
,arm64,$(if $(findstring x86_64,$(ARCH-TYPE)),int64,))
18-
19-
ifdef OS-NAME
20-
ifdef ARCH-NAME
21-
OS-ARCH := $(OS-NAME)-$(ARCH-NAME)
2250
OA-linux-arm64 := linux_arm64
2351
OA-linux-int64 := linux_amd64
2452
OA-macos-arm64 := darwin_arm64
2553
OA-macos-int64 := darwin_amd64
2654
OA := $(OA-$(OS-ARCH))
27-
GLJ := bin/$(OA)/glj
28-
endif
29-
endif
3055

31-
TEST_FILES := $(shell find ./test -name '*.glj' | sort)
32-
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))
33-
34-
GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
35-
GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go)
36-
# wasm should have .wasm suffix; others should not
37-
BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
38-
39-
# eventually, support multiple minor versions
40-
GO_VERSION := 1.19.3
41-
GO_CMD := go$(GO_VERSION)
42-
43-
.PHONY: all
44-
all: gocmd $(STDLIB_TARGETS) generate $(GLJIMPORTS) $(BINS)
56+
GLJ := bin/$(OA)/glj
4557

46-
.PHONY: gocmd
47-
gocmd:
48-
@$(GO_CMD) version 2>&1 > /dev/null || \
49-
(go install "golang.org/dl/$(GO_CMD)@latest" && \
50-
$(GO_CMD) download > /dev/null && $(GO_CMD) version > /dev/null)
58+
TEST-FILES := $(shell find ./test -name '*.glj' | sort)
59+
TEST-TARGETS := $(addsuffix .test,$(TEST-FILES))
5160

52-
.PHONY: generate
53-
generate:
54-
@go generate ./...
5561

56-
.PHONY: build
62+
ifdef OA
5763
build: $(GLJ)
64+
endif
5865

59-
.PHONY: clean
60-
clean:
61-
$(RM) -r bin/
66+
generate: $(GO)
67+
go generate ./...
6268

63-
pkg/gen/gljimports/gljimports_%.go: ./scripts/gen-gljimports.sh ./cmd/gen-import-interop/main.go ./internal/genpkg/genpkg.go \
64-
$(wildcard ./pkg/lang/*.go) $(wildcard ./pkg/runtime/*.go)
69+
pkg/gen/gljimports/gljimports_%.go: $(GO) \
70+
./scripts/gen-gljimports.sh \
71+
./cmd/gen-import-interop/main.go \
72+
./internal/genpkg/genpkg.go \
73+
$(wildcard ./pkg/lang/*.go) \
74+
$(wildcard ./pkg/runtime/*.go)
6575
@echo "Generating $@"
66-
@./scripts/gen-gljimports.sh $@ $* $(GO_CMD)
76+
@./scripts/gen-gljimports.sh $@ $* go
6777

68-
pkg/stdlib/glojure/%.glj: scripts/rewrite-core/originals/%.clj scripts/rewrite-core/run.sh scripts/rewrite-core/rewrite.clj
78+
pkg/stdlib/glojure/%.glj: $(CLOJURE) \
79+
scripts/rewrite-core/originals/%.clj \
80+
scripts/rewrite-core/run.sh \
81+
scripts/rewrite-core/rewrite.clj
6982
@echo "Rewriting $< to $@"
7083
@mkdir -p $(dir $@)
7184
@scripts/rewrite-core/run.sh $< > $@
7285

73-
bin/%/glj: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
86+
bin/%/glj: $(GLJ-DEPS)
7487
@echo "Building $@"
7588
@mkdir -p $(dir $@)
7689
@scripts/build-glj.sh $@ $*
7790

78-
bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
91+
bin/%/glj.wasm: $(GLJ-DEPS)
7992
@echo "Building $@"
8093
@mkdir -p $(dir $@)
8194
@scripts/build-glj.sh $@ $*
8295

83-
.PHONY: vet
84-
vet:
85-
@go vet ./...
96+
vet: $(GO)
97+
go vet ./...
8698

87-
.PHONY: $(TEST_TARGETS)
88-
$(TEST_TARGETS): gocmd $(GLJ)
89-
@$(GO_CMD) run ./cmd/glj/main.go $(basename $@)
99+
$(TEST-TARGETS): $(GO) $(GLJ)
100+
go run ./cmd/glj/main.go $(basename $@)
90101

91102
.PHONY: test
92-
test: vet $(TEST_TARGETS)
103+
test: vet $(TEST-TARGETS)
93104

94-
.PHONY: format
95-
format:
105+
format: $(GO)
96106
@if go fmt ./... | grep -q ''; then \
97107
echo "Files were formatted. Please commit the changes."; \
98108
exit 1; \
99109
fi
100110

101-
.PHONY: update-clojure-sources
102111
update-clojure-sources:
103-
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE_STDLIB_VERSION)
112+
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE-STDLIB-VERSION)
113+
114+
test-bug: $(GLJ)
115+
-glj <(echo '(throw (Exception. "foo"))')
116+
-glj <(echo '(throw (new Exception "foo"))')

0 commit comments

Comments
 (0)