-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
71 lines (52 loc) · 1.33 KB
/
makefile
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
.SUFFIXES:
SUFFIXES = .c .h .o .l .y .d
CC=gcc
CFLAGS=-std=gnu11 -g -Wall -fno-omit-frame-pointer
LDLIBS=
LDFLAGS=
RTCFLAGS=-std=gnu11 -Wall -fno-omit-frame-pointer
ifndef NDEBUG
ifeq "$(shell uname)" "Darwin"
# RTCFLAGS += -fsanitize=address
endif
ifneq "$(OS)" "Windows_NT"
CFLAGS += -fsanitize=address
LDFLAGS += -fsanitize=address
endif
else
CFLAGS += -O2 -march=native
endif
YACC=bison
YFLAGS=-d -v
LEX=flex
LFLAGS=
# Common files for both SRC and OSRC
BSRC=ast.c codegen.c symbols.c types_and_vars.c
# files that are edited by a hum
SRC=ast.h codegen.h grammar.y lexer.l symbols.h \
types_and_vars.h runtime.c $(BSRC)
# deps for the final binary
OSRC=grammar.tab.c lex.yy.c $(BSRC)
TARGETS := intml runtime.a
all: $(TARGETS)
# Use default rule...
intml: $(OSRC:.c=.o)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
grammar.tab.h grammar.tab.c: grammar.y
$(YACC) $(YFLAGS) $<
lex.yy.c: lexer.l grammar.tab.h
$(LEX) $(LFLAGS) $<
runtime.a: runtime.o
$(AR) -r $@ $^
runtime.o: runtime.c
$(CC) $(RTCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
.PHONY: clean
clean:
$(RM) $(TARGETS) intml.exe *.o lex.yy.c grammar.tab.{c,h} grammar.output *.d
%.d: %.c $(SRC)
$(CC) $(CFLAGS) -MM $< > $@
ifneq "$(MAKECMDGOALS)" "clean"
-include ${OSRC:.c=.d}
endif