-
Notifications
You must be signed in to change notification settings - Fork 97
/
Makefile
executable file
·96 lines (78 loc) · 2.25 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
CFLAGS = -Wall -Wextra -std=c99 -pedantic-errors -O2
DEBUG_FLAGS = -O0 -g -DBE_DEBUG
TEST_FLAGS = $(DEBUG_FLAGS) --coverage -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined
LIBS = -lm
TARGET = berry
CC = gcc
MKDIR = mkdir
LFLAGS =
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
INCPATH = src default
SRCPATH = src default
GENERATE = generate
CONFIG = default/berry_conf.h
COC = tools/coc/coc
CONST_TAB = $(GENERATE)/be_const_strtab.h
ifeq ($(OS), Windows_NT) # Windows
CFLAGS += -Wno-format # for "%I64d" warning
LFLAGS += -Wl,--out-implib,berry.lib # export symbols lib for dll linked
TARGET := $(TARGET).exe
PYTHON ?= python # only for windows and need python3
COC := $(PYTHON) $(COC)
else
CFLAGS += -DUSE_READLINE_LIB
LIBS += -lreadline -ldl
OS := $(shell uname)
ifeq ($(OS), Linux)
LFLAGS += -Wl,--export-dynamic
endif
endif
ifneq ($(V), 1)
Q=@
MSG=@echo
else
MSG=@true
endif
SRCS = $(foreach dir, $(SRCPATH), $(wildcard $(dir)/*.c))
OBJS = $(patsubst %.c, %.o, $(SRCS))
DEPS = $(patsubst %.c, %.d, $(SRCS))
INCFLAGS = $(foreach dir, $(INCPATH), -I"$(dir)")
.PHONY : clean
all: $(TARGET)
debug: CFLAGS += $(DEBUG_FLAGS)
debug: all
test: CFLAGS += $(TEST_FLAGS)
test: LFLAGS += $(TEST_FLAGS)
test: all
$(MSG) [Run Testcases...]
$(Q) ./testall.be
$(Q) $(RM) */*.gcno */*.gcda
$(TARGET): $(OBJS)
$(MSG) [Linking...]
$(Q) $(CC) $(OBJS) $(LFLAGS) $(LIBS) -o $@
$(MSG) done
$(OBJS): %.o: %.c
$(MSG) [Compile] $<
$(Q) $(CC) -MM $(CFLAGS) $(INCFLAGS) -MT"$*.d" -MT"$(<:.c=.o)" $< > $*.d
$(Q) $(CC) $(CFLAGS) $(INCFLAGS) -c $< -o $@
sinclude $(DEPS)
$(OBJS): $(CONST_TAB)
$(CONST_TAB): $(GENERATE) $(SRCS) $(CONFIG)
$(MSG) [Prebuild] generate resources
$(Q) $(COC) -o $(GENERATE) $(SRCPATH) -c $(CONFIG)
$(GENERATE):
$(Q) $(MKDIR) $(GENERATE)
install:
mkdir -p $(DESTDIR)$(BINDIR)
cp $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
uninstall:
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
prebuild: $(GENERATE)
$(MSG) [Prebuild] generate resources
$(Q) $(COC) -o $(GENERATE) $(SRCPATH) -c $(CONFIG)
$(MSG) done
clean:
$(MSG) [Clean...]
$(Q) $(RM) $(OBJS) $(DEPS) $(GENERATE)/* berry.lib
$(MSG) done