|
| 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) |
1 | 40 |
|
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 |
13 | 41 | GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go) |
14 | 42 | # wasm should have .wasm suffix; others should not |
15 | 43 | BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,)) |
16 | 44 |
|
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) |
20 | 51 |
|
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)) |
23 | 57 |
|
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 |
29 | 59 |
|
30 | | -.PHONY: generate |
31 | | -generate: |
32 | | - @go generate ./... |
| 60 | +ifdef OA |
| 61 | +build: $(GLJ) |
| 62 | +endif |
33 | 63 |
|
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) |
36 | 73 | @echo "Generating $@" |
37 | | - @./scripts/gen-gljimports.sh $@ $* $(GO_CMD) |
| 74 | + @./scripts/gen-gljimports.sh $@ $* go |
38 | 75 |
|
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 |
40 | 80 | @echo "Rewriting $< to $@" |
41 | 81 | @mkdir -p $(dir $@) |
42 | 82 | @scripts/rewrite-core/run.sh $< > $@ |
43 | 83 |
|
44 | | -bin/%/glj: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go) |
| 84 | +bin/%/glj: $(GLJ-DEPS) |
45 | 85 | @echo "Building $@" |
46 | 86 | @mkdir -p $(dir $@) |
47 | 87 | @scripts/build-glj.sh $@ $* |
48 | 88 |
|
49 | | -bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go) |
| 89 | +bin/%/glj.wasm: $(GLJ-DEPS) |
50 | 90 | @echo "Building $@" |
51 | 91 | @mkdir -p $(dir $@) |
52 | 92 | @scripts/build-glj.sh $@ $* |
53 | 93 |
|
54 | | -.PHONY: vet |
55 | | -vet: |
56 | | - @go vet ./... |
| 94 | +vet: $(GO) |
| 95 | + go vet ./... |
57 | 96 |
|
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 $@) |
61 | 99 |
|
62 | 100 | .PHONY: test |
63 | | -test: vet $(TEST_TARGETS) |
| 101 | +test: vet $(TEST-TARGETS) |
64 | 102 |
|
65 | | -.PHONY: format |
66 | | -format: |
| 103 | +format: $(GO) |
67 | 104 | @if go fmt ./... | grep -q ''; then \ |
68 | 105 | echo "Files were formatted. Please commit the changes."; \ |
69 | 106 | exit 1; \ |
70 | 107 | fi |
71 | 108 |
|
72 | | -.PHONY: update-clojure-sources |
73 | 109 | 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