hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 48363ba8d736e48ccf358bc69f2db8fd35076111 (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
CC      = clang
LEX     = flex
YACC    = bison
CFLAGS  = -std=c17 -Wall -Wextra -Werror -Wpedantic -O2 -Ibin
SOURCES = ast.c ast.h eval.c eval.h lexer.h main.c
OBJECTS = bin/lexer.o bin/parser.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/lexer.c: sfinae.l | bin
	$(LEX) -o bin/lexer.c sfinae.l

bin/lexer.o: bin/lexer.c bin/parser.h ast.h lexer.h
	$(CC) -std=c17 -w -I. -c -o $@ bin/lexer.c

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=c17 -w -I. -c -o $@ bin/parser.c

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

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 \
		echo "== $$example"; \
		./sfinae "$$example" || exit 1; \
	done

format:
	clang-format -i $(SOURCES)

lint:
	clang-tidy ast.c eval.c main.c -- -std=c17 -Ibin

clean:
	rm -rf bin sfinae