Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (73 loc) · 2.43 KB
/
Copy pathMakefile
File metadata and controls
90 lines (73 loc) · 2.43 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
SHELL := /bin/sh
CC ?= cc
BUILD_DIR ?= build
HUMC_BIN := $(BUILD_DIR)/humc
SANITIZE_DIR ?= build-sanitize
SANITIZE_BIN := $(SANITIZE_DIR)/humc
PREFIX ?= $(HOME)/.local
CPPFLAGS ?=
CFLAGS ?= -std=c11 -O2 -Wall -Wextra -Wpedantic
LDFLAGS ?=
LDLIBS ?=
SOURCES := bin/humc.c src/compiler.c
HEADERS := src/compiler.h
SMOKE_TEST := $(firstword $(wildcard test/test.sh test/test.sh))
.PHONY: all help test tests run install uninstall clean clean-all sanitize sanitize-test
all: $(HUMC_BIN)
help:
@printf '%s\n' \
'HumC Make targets:' \
' make Build build/humc' \
' make test Run tests' \
' make run FILE=... Translate, compile, and run a .humc file' \
' make sanitize Build with AddressSanitizer and UBSan' \
' make sanitize-test Run tests with sanitizers' \
' make install Install to PREFIX (default: ~/.local)' \
' make uninstall Remove installed humc' \
' make clean Remove generated compiler binaries' \
' make clean-all Remove build directories'
$(HUMC_BIN): $(SOURCES) $(HEADERS)
@mkdir -p "$(dir $@)"
$(CC) $(CPPFLAGS) $(CFLAGS) $(SOURCES) -o "$@" $(LDFLAGS) $(LDLIBS)
test: tests
tests: $(HUMC_BIN)
@if [ -n "$(SMOKE_TEST)" ]; then \
CC="$(CC)" \
HUMC_BIN="$(abspath $(HUMC_BIN))" \
HUMC_SOURCE_DIR="$(CURDIR)" \
sh "$(CURDIR)/$(SMOKE_TEST)"; \
else \
echo 'No smoke-test script found (expected test/test.sh or tests-smoke.sh).' >&2; \
exit 1; \
fi
run: $(HUMC_BIN)
@if [ -z "$(FILE)" ]; then \
echo 'Usage: make run FILE=examples/basic.humc [ARGS="..."]' >&2; \
exit 2; \
fi
"$(HUMC_BIN)" run "$(FILE)" $(ARGS)
$(SANITIZE_BIN): $(SOURCES) $(HEADERS)
@mkdir -p "$(dir $@)"
$(CC) $(CPPFLAGS) -std=c11 -O1 -g -Wall -Wextra -Wpedantic \
-fsanitize=address,undefined -fno-omit-frame-pointer \
$(SOURCES) -o "$@" -fsanitize=address,undefined $(LDLIBS)
sanitize: $(SANITIZE_BIN)
sanitize-test: $(SANITIZE_BIN)
@if [ -n "$(SMOKE_TEST)" ]; then \
CC="$(CC)" \
HUMC_BIN="$(abspath $(SANITIZE_BIN))" \
HUMC_SOURCE_DIR="$(CURDIR)" \
sh "$(CURDIR)/$(SMOKE_TEST)"; \
else \
echo 'No smoke-test script found.' >&2; \
exit 1; \
fi
install: $(HUMC_BIN)
install -d "$(DESTDIR)$(PREFIX)/bin"
install -m 755 "$(HUMC_BIN)" "$(DESTDIR)$(PREFIX)/bin/humc"
uninstall:
rm -f "$(DESTDIR)$(PREFIX)/bin/humc"
clean:
rm -f "$(HUMC_BIN)" "$(SANITIZE_BIN)" ./humc ./humalc
clean-all:
rm -rf "$(BUILD_DIR)" "$(SANITIZE_DIR)"