blob: 60481b39a8f061f6eb68a487505200f6d782cfb3 (
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
|
CC?=gcc
XFLAGS=
CFLAGS?=-std=c11 -O2 -Wall $(XFLAGS)
LIBS:=
IDIRS:=$(addprefix -iquote,include)
BUILDIR?=build/release
ifdef DEBUG
BUILDIR:=build/debug
CFLAGS:=-std=c11 -O0 -DDEBUG $(XFLAGS) -g
endif
ifdef ASAN
CFLAGS+= -fsanitize=address -fno-omit-frame-pointer
endif
OBJDIR=$(BUILDIR)/obj
CMONKEY_SRCS:=$(shell find src -name '*.c' -not -path '*/tests/*')
CMONKEY_OBJS:=$(CMONKEY_SRCS:%.c=$(OBJDIR)/%.o)
ALL_OBJS:=$(CMONKEY_OBJS)
TEST_OBJS:=$(filter-out $(OBJDIR)/src/cmonkey.o,$(ALL_OBJS))
all: cmonkey
test: tests/lexer tests/slice tests/parser tests/ast tests/eval
tests/%: $(OBJDIR)/src/tests/%.o $(TEST_OBJS)
mkdir -p $(BUILDIR)/$(@D)
$(CC) -o $(BUILDIR)/$@ $^ $(IDIRS) $(LIBS) $(CFLAGS)
$(OBJDIR)/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(IDIRS) -o $@ $< $(LIBS) $(CFLAGS)
cmonkey: $(ALL_OBJS)
mkdir -p $(@D)
$(CC) -o $(BUILDIR)/$@ $^ $(LIBS) $(CFLAGS)
clean:
rm -r build
.PHONY: clean all test
.PRECIOUS: $(OBJDIR)/src/tests/%.o
|