-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
118 lines (79 loc) · 2.64 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
110
111
112
113
114
115
116
117
118
NAME = evmqtt
VERSION = 0.5
SRCDIR = src
OBJDIR = obj
EXSRCDIR = examples
INCDIR = include
BINDIR = bin
DIRS = $(BINDIR) $(OBJDIR)
CFLAGS += -std=gnu99 -pedantic -Wall -Werror -Wextra -I$(INCDIR)
ifeq (1,$(DEBUG))
CFLAGS += -g
else
CFLAGS += -O2
endif
LDFLAGS += -levent -levent_openssl -lssl -lcrypto -lpcre2-8
LIBCFLAGS := $(CFLAGS) -fPIC
LIBLDFLAGS := $(LDFLAGS) -shared
EXLDFLAGS := $(LDFLAGS) -levtssl -L$(BINDIR)/ -l$(NAME)
SOURCES = $(wildcard $(SRCDIR)/*.c)
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
LIBHEADERS = $(wildcard $(INCDIR)/$(NAME)/*.h)
LIBBIN = $(BINDIR)/lib$(NAME).so
EXSOURCES = $(wildcard $(EXSRCDIR)/*.c)
EXBINS = $(patsubst $(EXSRCDIR)/%.c,$(BINDIR)/%,$(wildcard $(EXSRCDIR)/*.c))
HEADERS = $(wildcard $(SRCDIR)/*.h) $(wildcard $(EXSRCDIR)/*.h) $(LIBHEADERS)
.PHONY: all clean default lib examples debug install uninstall
default: clean lib
all: lib examples
lib: $(LIBBIN)
examples: $(EXBINS)
debug:
$(MAKE) DEBUG=1
$(LIBBIN): % : %.$(VERSION)
cd $(BINDIR) ; ln -sf $(patsubst $(BINDIR)/%,%,$^) $(patsubst $(BINDIR)/%,%,$@)
$(LIBBIN).$(VERSION): $(OBJECTS) | $(BINDIR)
$(CC) $^ -o $@ $(LIBLDFLAGS)
chmod 755 $@
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c | $(OBJDIR)
$(CC) -c $< -o $@ $(LIBCFLAGS)
$(EXBINS): $(BINDIR)/% : $(EXSRCDIR)/%.c | $(BINDIR) $(LIBBIN)
$(CC) $< -o $@ $(CFLAGS) $(EXLDFLAGS)
$(DIRS):
mkdir -p $@
VALGRINDCALLFILE = valgrindcall
valgrind: $(VALGRINDCALLFILE)
tools/startvalgrind $(VALGRINDCALLFILE) $(CALL)
format: $(SOURCES) $(EXSOURCES) $(HEADERS)
tools/format $^
tab_format: $(SOURCES) $(EXSOURCES) $(HEADERS)
tools/tab_format $^
ROOT ?= /
usr ?= usr/local
usrdir = $(ROOT)$(usr)
LIBINSTALLDIR = $(usrdir)lib/
HEADERINSTALLDIR = $(usrdir)include/$(NAME)/
EXAMPLESINSTALLDIR = $(usrdir)bin/
INSTALL_BIN_CMD=install -m 0755
install_lib: $(LIBBIN).$(VERSION)
mkdir -p $(LIBINSTALLDIR)
$(INSTALL_BIN_CMD) $^ $(LIBINSTALLDIR)
cd $(LIBINSTALLDIR) ; ln -fs $(patsubst $(BINDIR)/%,%,$(LIBBIN).$(VERSION)) $(patsubst $(BINDIR)/%,%,$(LIBBIN))
install_headers: $(HEADERS)
mkdir -p $(HEADERINSTALLDIR)
install $(HEADERS) $(HEADERINSTALLDIR)
install_examples: $(EXBINS)
mkdir -p $(EXAMPLESINSTALLDIR)
$(INSTALL_BIN_CMD) $^ $(EXAMPLESINSTALLDIR)
install: install_lib install_headers install_examples
uninstall_lib:
rm -f $(patsubst $(BINDIR)/%,$(LIBINSTALLDIR)/%*,$(LIBBIN))
uninstall_headers:
echo $(HEADERS)
rm -f $(patsubst $(INCDIR)/$(NAME)/%,$(HEADERINSTALLDIR)/%,$(HEADERS))
#TODO remove $(HEADERINSTALLDIR) if empty
uninstall_examples:
rm -f $(patsubst $(BINDIR)/%,$(EXAMPLESINSTALLDIR)/%,$(EXBINS))
uninstall: uninstall_lib uninstall_headers uninstall_examples
clean::
rm -rf $(DIRS)