Skip to content

Commit ba11570

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 eb274a0 commit ba11570

1 file changed

Lines changed: 59 additions & 24 deletions

File tree

Makefile

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
M := $(or $(MAKES_REPO_DIR),.cache/makes)
2+
C := bc32749a8dcc250e375b3a6d3572c3260a972efb
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/clean.mk
13+
include $M/shell.mk
14+
15+
MAKES-CLEAN := bin/
16+
MAKES-DISTCLEAN := .cache/ .clj-kondo/ .lsp/ .vscode/
117

218
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
319
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
@@ -8,55 +24,74 @@ STDLIB_TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))
824
TEST_FILES := $(shell find ./test -name '*.glj')
925
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))
1026

11-
GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
27+
GOPLATFORMS := \
28+
darwin_arm64 \
29+
darwin_amd64 \
30+
linux_arm64 \
31+
linux_amd64 \
32+
windows_amd64 \
33+
windows_arm \
34+
js_wasm \
35+
36+
# Set PATH so that glj is in the PATH after 'make shell'
37+
override PATH := $(subst $(space),:,$(GOPLATFORMS:%=bin/%)):$(PATH)
38+
1239
GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go)
1340
# wasm should have .wasm suffix; others should not
1441
BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
1542

16-
# eventually, support multiple minor versions
17-
GO_VERSION := 1.19.3
18-
GO_CMD := go$(GO_VERSION)
43+
GLJ-DEPS := \
44+
$(wildcard ./cmd/glj/*.go) \
45+
$(wildcard ./pkg/**/*.go) \
46+
$(wildcard ./internal/**/*.go) \
47+
48+
all: $(STDLIB_TARGETS) generate $(GLJIMPORTS) $(BINS)
1949

20-
.PHONY: all
21-
all: gocmd $(STDLIB_TARGETS) generate $(GLJIMPORTS) $(BINS)
50+
OA-linux-arm64 := linux_arm64
51+
OA-linux-int64 := linux_amd64
52+
OA-macos-arm64 := darwin_arm64
53+
OA-macos-int64 := darwin_amd64
54+
OA := $(OA-$(OS-ARCH))
2255

23-
.PHONY: gocmd
24-
gocmd:
25-
@$(GO_CMD) version 2>&1 > /dev/null || \
26-
(go install "golang.org/dl/$(GO_CMD)@latest" && \
27-
$(GO_CMD) download > /dev/null && $(GO_CMD) version > /dev/null)
56+
ifdef OA
57+
build: bin/$(OA)/glj
58+
endif
2859

29-
.PHONY: generate
30-
generate:
60+
generate: $(GO)
3161
@go generate ./...
3262

33-
pkg/gen/gljimports/gljimports_%.go: ./scripts/gen-gljimports.sh ./cmd/gen-import-interop/main.go ./internal/genpkg/genpkg.go \
34-
$(wildcard ./pkg/lang/*.go) $(wildcard ./pkg/runtime/*.go)
63+
pkg/gen/gljimports/gljimports_%.go: $(GO) \
64+
./scripts/gen-gljimports.sh \
65+
./cmd/gen-import-interop/main.go \
66+
./internal/genpkg/genpkg.go \
67+
$(wildcard ./pkg/lang/*.go) \
68+
$(wildcard ./pkg/runtime/*.go)
3569
@echo "Generating $@"
36-
@./scripts/gen-gljimports.sh $@ $* $(GO_CMD)
70+
@./scripts/gen-gljimports.sh $@ $* go
3771

38-
pkg/stdlib/glojure/%.glj: scripts/rewrite-core/originals/%.clj scripts/rewrite-core/run.sh scripts/rewrite-core/rewrite.clj
72+
pkg/stdlib/glojure/%.glj: \
73+
scripts/rewrite-core/originals/%.clj \
74+
scripts/rewrite-core/run.sh \
75+
scripts/rewrite-core/rewrite.clj
3976
@echo "Rewriting $< to $@"
4077
@mkdir -p $(dir $@)
4178
@scripts/rewrite-core/run.sh $< > $@
4279

43-
bin/%/glj: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
80+
bin/%/glj: $(GLJ-DEPS)
4481
@echo "Building $@"
4582
@mkdir -p $(dir $@)
4683
@scripts/build-glj.sh $@ $*
4784

48-
bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
85+
bin/%/glj.wasm: $(GLJ-DEPS)
4986
@echo "Building $@"
5087
@mkdir -p $(dir $@)
5188
@scripts/build-glj.sh $@ $*
5289

53-
.PHONY: vet
54-
vet:
90+
vet: $(GO)
5591
@go vet ./...
5692

57-
.PHONY: $(TEST_TARGETS)
58-
$(TEST_TARGETS): gocmd
59-
@$(GO_CMD) run ./cmd/glj/main.go $(basename $@)
93+
$(TEST_TARGETS):
94+
go run ./cmd/glj/main.go $(basename $@)
6095

6196
.PHONY: test
6297
test: vet $(TEST_TARGETS)

0 commit comments

Comments
 (0)