-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (40 loc) · 1.04 KB
/
Copy pathMakefile
File metadata and controls
55 lines (40 loc) · 1.04 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
CC = gcc
CFLAGS = -Wall -Werror -Wfatal-errors -std=c99 -Isrc -g
CFLAGS_FLEX = -std=c99 -D_POSIX_SOURCE
SOURCES = $(filter-out src/schc.c, $(wildcard src/*.c src/**/*.c))
OBJECTS = $(patsubst src/%.c, build/%.o, $(SOURCES)) build/gen_lexer.o
TESTS = $(patsubst tests/%.c, %-test, $(wildcard tests/*.c))
.PHONY: all
all: debug
.PHONY: debug
debug: CFLAGS += -DDEBUG -g
debug: build
.PHONY: release
release: CFLAGS += -DNDEBUG -O3
release: build
.PHONY: build
build: dirs schc
.PHONY: tests
tests: CFLAGS += -DDEBUG -g
tests: dirs $(TESTS)
schc: $(OBJECTS) build/schc.o
$(CC) $^ -o $@
%-test: $(OBJECTS) build/%-test.o
$(CC) $^ -o $@
.PHONY: dirs
dirs:
@mkdir -p build
.PHONY: clean
clean:
rm -rf build schc $(TESTS)
build/gen_lexer.c: src/gen_lexer.l
flex -o $@ $^
build/gen_lexer.o: build/gen_lexer.c
$(CC) $(CFLAGS_FLEX) -o $@ -c $<
build/%-test.o: tests/%.c src/test.h
$(CC) $(CFLAGS) -o $@ -c $<
build/%/:
mkdir -p $@
build/%.o: src/%.c
$(CC) $(CFLAGS) -o $@ -c $<
$(foreach OBJECT, $(OBJECTS), $(eval $(OBJECT): | $(dir $(OBJECT))))