|
| 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) |
1 | 49 |
|
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) |
22 | 50 | OA-linux-arm64 := linux_arm64 |
23 | 51 | OA-linux-int64 := linux_amd64 |
24 | 52 | OA-macos-arm64 := darwin_arm64 |
25 | 53 | OA-macos-int64 := darwin_amd64 |
26 | 54 | OA := $(OA-$(OS-ARCH)) |
27 | | -GLJ := bin/$(OA)/glj |
28 | | -endif |
29 | | -endif |
30 | 55 |
|
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 |
45 | 57 |
|
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)) |
51 | 60 |
|
52 | | -.PHONY: generate |
53 | | -generate: |
54 | | - @go generate ./... |
55 | 61 |
|
56 | | -.PHONY: build |
| 62 | +ifdef OA |
57 | 63 | build: $(GLJ) |
| 64 | +endif |
58 | 65 |
|
59 | | -.PHONY: clean |
60 | | -clean: |
61 | | - $(RM) -r bin/ |
| 66 | +generate: $(GO) |
| 67 | + go generate ./... |
62 | 68 |
|
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) |
65 | 75 | @echo "Generating $@" |
66 | | - @./scripts/gen-gljimports.sh $@ $* $(GO_CMD) |
| 76 | + @./scripts/gen-gljimports.sh $@ $* go |
67 | 77 |
|
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 |
69 | 82 | @echo "Rewriting $< to $@" |
70 | 83 | @mkdir -p $(dir $@) |
71 | 84 | @scripts/rewrite-core/run.sh $< > $@ |
72 | 85 |
|
73 | | -bin/%/glj: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go) |
| 86 | +bin/%/glj: $(GLJ-DEPS) |
74 | 87 | @echo "Building $@" |
75 | 88 | @mkdir -p $(dir $@) |
76 | 89 | @scripts/build-glj.sh $@ $* |
77 | 90 |
|
78 | | -bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go) |
| 91 | +bin/%/glj.wasm: $(GLJ-DEPS) |
79 | 92 | @echo "Building $@" |
80 | 93 | @mkdir -p $(dir $@) |
81 | 94 | @scripts/build-glj.sh $@ $* |
82 | 95 |
|
83 | | -.PHONY: vet |
84 | | -vet: |
85 | | - @go vet ./... |
| 96 | +vet: $(GO) |
| 97 | + go vet ./... |
86 | 98 |
|
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 $@) |
90 | 101 |
|
91 | 102 | .PHONY: test |
92 | | -test: vet $(TEST_TARGETS) |
| 103 | +test: vet $(TEST-TARGETS) |
93 | 104 |
|
94 | | -.PHONY: format |
95 | | -format: |
| 105 | +format: $(GO) |
96 | 106 | @if go fmt ./... | grep -q ''; then \ |
97 | 107 | echo "Files were formatted. Please commit the changes."; \ |
98 | 108 | exit 1; \ |
99 | 109 | fi |
100 | 110 |
|
101 | | -.PHONY: update-clojure-sources |
102 | 111 | 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