-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
67 lines (42 loc) · 1.35 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
# Tell make to stop removing intermediate files
.SECONDARY:
CC ?= gcc
CFLAGS = -Wall -Werror -Wextra -Wno-missing-field-initializers -pipe -fstack-protector -Wformat-security -std=c99
# marcel requires POSIX.1-2001 base specification + XSI extensions
_DEFINES = _XOPEN_SOURCE=600
DEFINES = $(addprefix -D, $(_DEFINES))
EXE = marcel
LIBS = -lreadline -lfl
SRCDIR = src
OBJDIR = obj
$(shell `mkdir -p $(OBJDIR)`)
CSRCS = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/ds/*.c)
BSON = $(patsubst %.y, %.c, $(wildcard $(SRCDIR)/*.y))
FLEX = $(patsubst %.l, %.c, $(wildcard $(SRCDIR)/*.l))
SRCS = $(BSON) $(FLEX) $(CSRCS)
HDRS = $(SRCS:.c=.h)
OBJS = $(addprefix obj/,$(notdir $(SRCS:.c=.o)))
define cc-command
$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<
endef
debug: CFLAGS += -O0 -ggdb3
debug: all
release: CFLAGS += -O3
release: all
profile: CFLAGS += -pg
profile: release
all: $(EXE)
%.c %.h: %.y
bison --defines=$(@:.c=.h) --output=$(@:.h=.c) $<
%.c %.h: %.l
flex --header-file=$(@:.c=.h) --outfile=$(@:.h=.c) $<
$(EXE): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HDRS) Makefile
$(cc-command)
$(OBJDIR)/%.o: $(SRCDIR)/ds/%.c $(HDRS) Makefile
$(cc-command)
-include $(wildcard $(OBJDIR)/*.d)
clean:
rm -f core $(EXE) $(basename $(FLEX)).h $(basename $(FLEX)).c $(basename $(BSON)).h $(basename $(BSON)).c
rm -r $(OBJDIR)