-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (150 loc) · 4.36 KB
/
Makefile
File metadata and controls
184 lines (150 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Usage:
# make clean all test GO-VERSION=1.25.1
SHELL := bash
GO-VERSION ?= 1.24.0
CLOJURE-VERSION ?= 1.12.1
CLOJURE-STDLIB-VERSION := clojure-$(CLOJURE-VERSION)
STDLIB-ORIGINALS-DIR := scripts/rewrite-core/originals
STDLIB-ORIGINALS := $(wildcard $(STDLIB-ORIGINALS-DIR)/*.clj)
STDLIB-NAMES := $(STDLIB-ORIGINALS:scripts/rewrite-core/originals/%=%)
STDLIB-ORIGINALS := $(STDLIB-NAMES:%=scripts/rewrite-core/originals/,%)
STDLIB-TARGETS := $(addprefix pkg/stdlib/clojure/,$(STDLIB-NAMES:.clj=.glj))
AOT-NAMESPACES := \
clojure.core \
clojure.core.async \
clojure.string \
clojure.template \
clojure.test \
clojure.uuid \
clojure.walk \
glojure.go.io \
glojure.go.types \
$(EXTRA-AOT-NAMESPACES)
OS-TYPE := $(shell bash -c 'echo $$OSTYPE')
OS-NAME := \
$(if $(findstring darwin,$(OS-TYPE))\
,macos,$(if $(findstring linux,$(OS-TYPE)),linux,))
ARCH-TYPE := $(shell bash -c 'echo $$MACHTYPE')
ARCH-NAME := \
$(if $(or $(findstring arm64,$(ARCH-TYPE)),\
$(findstring aarch64,$(ARCH-TYPE)))\
,arm64,$(if $(findstring x86_64,$(ARCH-TYPE)),int64,))
ifdef OS-NAME
ifdef ARCH-NAME
OS-ARCH := $(OS-NAME)-$(ARCH-NAME)
OA-linux-arm64 := linux_arm64
OA-linux-int64 := linux_amd64
OA-macos-arm64 := darwin_arm64
OA-macos-int64 := darwin_amd64
GLJ-CMD := bin/$(OA-$(OS-ARCH))/glj
endif
endif
TEST-GLJ-DIR := test/glojure
TEST-GLJ-FILES := $(shell find $(TEST-GLJ-DIR) -name '*.glj' | sort)
TEST-GLJ-TARGETS := $(addsuffix .test,$(TEST-GLJ-FILES))
TEST-SUITE-DIR := test/clojure-test-suite
TEST-SUITE-FILE := test-glojure.glj
GO-PLATFORMS := \
darwin_arm64 \
darwin_amd64 \
linux_arm64 \
linux_amd64 \
windows_arm \
windows_amd64 \
js_wasm \
wasip1_wasm \
$(EXTRA-GO-PLATFORMS)
GLJ-IMPORTS=$(foreach platform,$(GO-PLATFORMS) \
,pkg/gen/gljimports/gljimports_$(platform).go)
# wasm should have .wasm suffix; others should not
GLJ-BINS=$(foreach platform,$(GO-PLATFORMS) \
,bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
GO-CMD := go$(GO-VERSION)
ALL-TARGETS := \
$(if $(force),update-clojure-sources) \
stdlib-targets \
generate \
aot \
glj-imports \
glj-bins \
#-------------------------------------------------------------------------------
default: all
# Dummy target for commands like:
# make all force=1
# make stdlib-targets force=1
force:
all: $(ALL-TARGETS)
gocmd:
@$(GO-CMD) version &> /dev/null || { \
(go install "golang.org/dl/$(GO-CMD)@latest" && \
$(GO-CMD) download > /dev/null && \
$(GO-CMD) version > /dev/null); }
stdlib-targets: $(STDLIB-TARGETS)
generate:
go generate ./...
aot: gocmd $(STDLIB-TARGETS)
GLOJURE_USE_AOT=false \
GLOJURE_STDLIB_PATH=./pkg/stdlib \
$(GO-CMD) run -tags glj_no_aot_stdlib ./cmd/glj \
<<<"(map compile '[$(AOT-NAMESPACES)])"
glj-imports: $(GLJ-IMPORTS)
glj-bins: $(GLJ-BINS)
build: $(GLJ-CMD)
clean:
$(RM) report.html
$(RM) -r bin/ scripts/rewrite-core/.cpcache/
pkg/gen/gljimports/gljimports_%.go: \
./scripts/gen-gljimports.sh \
./cmd/gen-import-interop/main.go \
./internal/genpkg/genpkg.go \
$(wildcard ./pkg/lang/*.go) \
$(wildcard ./pkg/runtime/*.go) \
$(if $(force),force)
@echo "Generating $@"
./scripts/gen-gljimports.sh $@ $* $(GO-CMD)
pkg/stdlib/clojure/%.glj: \
scripts/rewrite-core/originals/%.clj \
scripts/rewrite-core/run.sh \
scripts/rewrite-core/rewrite.clj \
$(if $(force),force)
@echo "Rewriting $< to $@"
@mkdir -p $(dir $@)
scripts/rewrite-core/run.sh $< > $@
bin/%/glj: generate \
$(wildcard ./cmd/glj/*.go) \
$(wildcard ./pkg/**/*.go) \
$(wildcard ./internal/**/*.go) \
$(if $(force),force)
@echo "Building $@"
@mkdir -p $(dir $@)
scripts/build-glj.sh $@ $*
bin/%/glj.wasm: \
$(wildcard ./cmd/glj/*.go) \
$(wildcard ./pkg/**/*.go) \
$(wildcard ./internal/**/*.go) \
$(if $(force),force)
@echo "Building $@"
@mkdir -p $(dir $@)
scripts/build-glj.sh $@ $*
vet:
go vet ./...
.PHONY: test
# vet is disabled until we fix errors in generated code
test: test-glj test-suite # vet
test-glj: $(TEST-GLJ-TARGETS)
test-suite: $(GLJ-CMD)
cd $(TEST-SUITE-DIR) && \
$(abspath $<) $(TEST-SUITE-FILE) \
--expect-failures 38 \
--expect-errors 151 \
2>/dev/null
$(TEST-GLJ-TARGETS): $(GLJ-CMD)
$< $(basename $@)
format:
@if go fmt ./... | grep -q ''; then \
echo "Files were formatted. Please commit the changes."; \
exit 1; \
fi
update-clojure-sources:
scripts/rewrite-core/update-clojure-sources.sh \
$(CLOJURE-STDLIB-VERSION)