hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 8d873b9394f3d51ca2f1c34040a6b1cd3dfe2f26 (plain)
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
CC      = cc
YACC    = bison
CFLAGS  = -std=c99 -Wall -Wextra -Werror -Wpedantic -O2 -Ibin
SOURCES = ast.c ast.h eval.c eval.h lexer.c lexer.h main.c
OBJECTS = bin/parser.o bin/lexer.o bin/ast.o bin/eval.o bin/main.o
SANITIZE = -g -O0 -fsanitize=address,undefined

.PHONY: all debug check format lint clean

all: sfinae

bin:
	mkdir -p bin

sfinae: $(OBJECTS)
	$(CC) $(CFLAGS) -o $@ $(OBJECTS)

bin/parser.c bin/parser.h: sfinae.y | bin
	$(YACC) -d -o bin/parser.c sfinae.y

bin/parser.o: bin/parser.c
	$(CC) -std=c99 -w -I. -c -o $@ bin/parser.c

bin/%.o: %.c | bin
	$(CC) $(CFLAGS) -c -o $@ $<

bin/lexer.o: bin/parser.h ast.h lexer.h
bin/main.o: ast.h eval.h lexer.h
bin/ast.o: ast.h lexer.h
bin/eval.o: eval.h ast.h

debug: CFLAGS += $(SANITIZE)
debug: clean sfinae

check: sfinae
	@for example in examples/*.sfinae; do \
		expected="$${example%.sfinae}.expected"; \
		if ./sfinae "$$example" | diff -u "$$expected" - >/dev/null; then \
			echo "ok   $$example"; \
		else \
			echo "FAIL $$example"; ./sfinae "$$example" | diff -u "$$expected" -; exit 1; \
		fi; \
	done

format:
	clang-format -i $(SOURCES)

LINT_FILTER = '[{"name":"parser.h","lines":[[1,1]]}, \
    {"name":"ast.c"},{"name":"eval.c"},{"name":"lexer.c"},{"name":"main.c"}, \
    {"name":"ast.h"},{"name":"eval.h"},{"name":"lexer.h"}]'

lint: bin/parser.h
	clang-tidy --line-filter=$(LINT_FILTER) ast.c eval.c lexer.c main.c -- -std=c99 -Ibin

clean:
	rm -rf bin sfinae