-
Notifications
You must be signed in to change notification settings - Fork 160
/
Makefile
109 lines (70 loc) · 2.19 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
97
98
99
100
101
102
103
104
105
106
107
108
109
CC = g++
CFLAGS_DBG = -g -DDEBUG -D_DEBUG
CFLAGS_REL = -O2 -DNDEBUG
_CFLAGS = -Wall -std=c++11 -Iinclude
CFLAGS_SRC = $(_CFLAGS) -fPIC -D_TPMCPPLIB
CFLAGS_SMPL = $(_CFLAGS)
SRCDIR = Src
SMPLDIR = Samples
BINDIR = bin
TSS_A = $(BINDIR)/tss$(SUFF).a
TSS_SO = $(BINDIR)/tss$(SUFF).so
SAMPLES = $(BINDIR)/samples
OBJDIR = $(BINDIR)/obj
OBJ_SRC_DIR = $(OBJDIR)/$(SRCDIR)/$(CONFIG)
OBJ_SMPL_DIR = $(OBJDIR)/$(SMPLDIR)/$(CONFIG)
SRCS := $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(addprefix $(OBJDIR)/,$(SRCS:$(SRCDIR)/%.cpp=$(SRCDIR)/$(CONFIG)/%.o))
SMPL_SRCS := $(wildcard $(SMPLDIR)/*.cpp)
SMPL_OBJS = $(addprefix $(OBJDIR)/,$(SMPL_SRCS:$(SMPLDIR)/%.cpp=$(SMPLDIR)/$(CONFIG)/%.o))
CONFIG := $(or $(CONFIG),$(config),$(CFG),$(cfg))
ifeq (,$(filter $(CONFIG),debug release))
ifdef CONFIG
$(error If specified, CONFIG can only be {debug|release})
endif
CONFIG = debug
endif
ifeq ($(CONFIG),debug)
CFLAGS_SRC += $(CFLAGS_DBG)
CFLAGS_SMPL += $(CFLAGS_DBG)
SUFF = d
else
CFLAGS_SRC += $(CFLAGS_REL)
CFLAGS_SMPL += $(CFLAGS_REL)
endif
all: tss samples
DEPDIR := $(OBJ_SRC_DIR)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
$(OBJ_SRC_DIR)/%.o: $(SRCDIR)/%.cpp $(DEPDIR)/%.d | $(DEPDIR)
$(CC) -c $< -o $@ $(CFLAGS_SRC) $(DEPFLAGS)
$(DEPDIR): ; @mkdir -p $@
DEPFILES := $(OBJS:%.o=%.d)
$(DEPFILES):
-include $(DEPFILES)
$(TSS_A): $(OBJS)
ar -crs $(TSS_A) $(OBJS)
$(TSS_SO): $(OBJS)
$(CC) -o $(TSS_SO) $(OBJS) -shared
tss: $(TSS_SO)
DEPDIR_SMPL := $(OBJ_SMPL_DIR)
DEPFLAGS_SMPL = -MT $@ -MMD -MP -MF $(DEPDIR_SMPL)/$*.d
$(OBJ_SMPL_DIR)/%.o: $(SMPLDIR)/%.cpp $(DEPDIR_SMPL)/%.d | $(DEPDIR_SMPL)
$(CC) -c $< -o $@ $(CFLAGS_SMPL) $(DEPFLAGS_SMPL)
$(DEPDIR_SMPL): ; @mkdir -p $@
DEPFILES_SMPL := $(SMPL_OBJS:%.o=%.d)
$(DEPFILES_SMPL):
-include $(DEPFILES_SMPL)
$(SAMPLES): $(SMPL_OBJS) $(TSS_A)
$(CC) -o $@ $(SMPL_OBJS) $(TSS_A) $(CFLAGS_SMPL) -L/usr/lib -lcrypto -ldl
samples: $(SAMPLES)
test: $(SAMPLES)
$(SAMPLES)
list:
@echo "Targets: clean, all, tss, samples, test, list, help"
@echo "Build config specification: {CONFIG|config|CFG|cfg} = {debug|release}"
help: list
@echo Default: all debug
clean:
@rm -rf $(OBJDIR)
@rm -f $(SAMPLES) $(TSS_A) $(TSS_SO)
.PHONY: clean all tss test list help