-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
common.mk
76 lines (60 loc) · 1.85 KB
/
common.mk
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
CP = cp -f
AR = ar r
MKDIR=mkdir -p
RM=rm -fr
CFLAGS_OPT = -O2 -DNDEBUG
#CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith #-Wswitch-enum -Wstrict-aliasing=2
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith #-Wswitch-enum -Wstrict-aliasing=2
CFLAGS = -g -D_FILE_OFFSET_BITS=64
CFLAGS+=$(CFLAGS_WARN)
ifeq ($(OLD_OPENSSL),1)
CFLAGS+=-DCYBOZU_USE_OPENSSL_NEW_HASH=0
endif
LDFLAGS = -lcrypto
UNAME_S=$(shell uname -s)
ifeq ($(UNAME_S),Darwin)
EXT_DIR?=/opt/homebrew/
CFLAGS+=-I$(EXT_DIR)/include
LDFLAGS+=-L$(EXT_DIR)/lib
LIB_SUF=dylib
else
LIB_SUF=so
endif
DEBUG=0
ifeq ($(RELEASE),1)
DEBUG=0
endif
ifeq ($(DEBUG),0)
CFLAGS+=$(CFLAGS_OPT)
OBJDIR=release
OBJSUF=
else
OBJDIR=debug
OBJSUF=d
endif
TOPDIR:=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))/
CFLAGS+= -I$(TOPDIR)include -I$(TOPDIR)../cybozulib/include
LDFLAGS+= -L$(TOPDIR)lib -lcrypto -lpthread
ifneq ($(UNAME_S),Darwin)
LDFLAGS+=-lrt
endif
MKDEP = sh -ec '$(CC) -MM $(CFLAGS) $< | sed "s@\($*\)\.o[ :]*@$(OBJDIR)/\1.o $@ : @g" > $@; [ -s $@ ] || rm -f $@'
CLEAN=$(RM) $(TARGET) $(OBJDIR)
define UNIT_TEST
sh -ec 'for i in $(TARGET); do $$i|grep "ctest:name"; done' > result.txt
grep -v "ng=0, exception=0" result.txt || echo "all unit tests are ok"
endef
define SAMPLE_TEST
sh -ec 'for i in $(TARGET); do $$i; done'
endef
.SUFFIXES: .cpp .d .exe
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $< -o $@ $(CFLAGS)
$(OBJDIR)/%.d: %.cpp $(OBJDIR)
@$(MKDEP)
$(TOPDIR)bin/%$(OBJSUF).exe: $(OBJDIR)/%.o $(LIBS)
$(CXX) $< -o $@ $(LIBS) $(LDFLAGS)
OBJS=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
DEPEND_FILE=$(addprefix $(OBJDIR)/, $(SRC:.cpp=.d))
TEST_FILE=$(addprefix $(TOPDIR)bin/, $(SRC:.cpp=$(OBJSUF).exe))
.PHONY: test