repos / gbc

GBC - Go B Compiler
git clone https://github.com/xplshn/gbc.git

xplshn  ·  2025-08-13

Makefile

Makefile
 1OUT = gbc
 2GTEST = gtest
 3
 4GO = go
 5ifneq ($(shell command -v gore 2>/dev/null),)
 6GO = gore
 7endif
 8
 9# `gore` is my wrapper for `go` that adds beautiful errors like this one:
10#     # $ gore build
11#     # gbc/pkg/codegen
12#       71 | // NewContext creates a new code generation context.
13#       72 | func NewContext(targetArch string, cfg *config.Config) *Context {
14#       73 |     invalidSyntaxToShowcaseGore
15#       -- |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~  undefined: invalidSyntaxToShowcaseGore
16#       74 |     return &Context{
17#       75 |         currentScope: newScope(nil),
18#
19#       83 |
20#       84 | func newScope(parent *scope) *scope {
21#       85 |     hellooooo
22#       -- |     ^~~~~~~~~  undefined: hellooooo
23#       86 |     return &scope{Parent: parent}
24#       87 | }
25#
26# I might publish `gore` at some point...
27# NOTE: `gore` uses syntax highlighting and pretty colors, this showcase doesn't do it justice
28#
29
30all: $(OUT)
31
32$(OUT):
33	@echo "Building gbc..."
34	@$(GO) build -C ./cmd/$(OUT) -o ../../$(OUT)
35
36$(GTEST):
37	@echo "Building test runner..."
38	@$(GO) build -C ./cmd/gtest #-o ../../$(GTEST)
39
40clean:
41	@echo "Cleaning up..."
42	@rm -f $(OUT) $(GTEST) ./a.out .test_results.json
43
44ARCH := $(shell uname -m)
45OS := $(shell uname -s)
46LIBB := ./lib/b/$(ARCH)-$(OS).b
47
48badFiles := donut.b
49
50define filter_files
51files=""; \
52for f in $(1); do \
53  skip=0; \
54  for bad in $(badFiles); do \
55    if [ "$$f" = "$(2)/$$bad" ]; then skip=1; break; fi; \
56  done; \
57  if [ $$skip -eq 0 ]; then files="$$files $$f"; fi; \
58done; \
59echo "$$files"
60endef
61
62test: all $(GTEST)
63	@echo "Running tests..."
64	@files=$$( $(call filter_files,tests/*.b*,tests) ); \
65	./cmd/$(GTEST)/$(GTEST) --test-files="$$files" --target-args="$(LIBB)" -v
66
67examples: all $(GTEST)
68	@echo "Running examples..."
69	@files=$$( $(call filter_files,examples/*.b*,examples) ); \
70	./cmd/$(GTEST)/$(GTEST) --test-files="$$files" --target-args="$(LIBB)" -v --ignore-lines="xs_items"