forked from kongo2002/nyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
178 lines (135 loc) · 3.69 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# VERSION
VERSION := 1.8.0
# BUILD FLAGS
CC ?= gcc
CXXFLAGS := -std=c99 -pedantic -Wall -Wextra
INCLUDES := -I.
LIBS := -lyaml -lpthread -lm
# DEBUG/RELEASE BUILD
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CXXFLAGS+= -O0 -g -Werror -Wshadow
BUILD=DEBUG
else
CXXFLAGS+= -O2 -DNDEBUG -Wno-unused-parameter
BUILD=RELEASE
endif
# FILES
SRCS := $(wildcard src/*.c)
OBJECTS := $(patsubst src/%.c,src/%.o, $(SRCS))
DEPS := $(OBJECTS:.o=.d)
TSRCS := $(wildcard tests/*.c)
TOBJECTS := $(patsubst tests/%.c,tests/%.o, $(TSRCS))
TLIBS := -lcmocka
TDEPS := $(filter-out src/main.o, $(OBJECTS))
# LOOK FOR LOCALLY CMOCKA SOURCES
CMOCKA_HEADER="$(shell find . -name cmocka.h)"
ifneq ($(CMOCKA_HEADER), "")
CMOCKA_LIB="$(shell find . -name libcmocka.so -or -name libcmocka.dylib | grep -v obj32)"
TINCLUDES+= -I"$(shell dirname $(CMOCKA_HEADER))"
TLIBS+= -L"$(shell dirname $(CMOCKA_LIB))"
endif
# OS SPECIFICS
ifeq ($(shell uname -s), Darwin)
CXXFLAGS+= -DOSX
OBJECTS := $(filter-out src/event.o, $(OBJECTS))
TDEPS := $(filter-out src/event.o, $(TDEPS))
# no OpenSSL on OSX
SSL := 0
IS_OSX := yes
else
IS_OSX := no
endif
# PLUGINS
PLUGINS ?= 0
ifeq ($(PLUGINS), 1)
LIBS+= -ldl -rdynamic
CXXFLAGS+= -DUSE_PLUGINS
HAS_PLUGINS := yes
else
OBJECTS := $(filter-out src/plugins.o, $(OBJECTS))
TDEPS := $(filter-out src/plugins.o, $(TDEPS))
HAS_PLUGINS := no
endif
# SSL
SSL ?= 0
ifeq ($(SSL), 1)
LIBS+= -lssl -lcrypto
CXXFLAGS+= -DUSE_SSL
HAS_SSL := yes
else
OBJECTS := $(filter-out src/ssl.o, $(OBJECTS))
TDEPS := $(filter-out src/ssl.o, $(TDEPS))
HAS_SSL := no
endif
# TRY TO DETERMINE GIT VERSION
GITVERSION ?= $(shell ./utils/git-version.sh)
CXXFLAGS += $(GITVERSION)
CXXFLAGS += -DNYX_VERSION_NUMBER=\"$(VERSION)\"
# INSTALL DIRECTORIES
PREFIX ?= /usr/local
MANPREFIX ?= $(PREFIX)/share/man
DOCDIR ?= $(PREFIX)/share/doc
INSTALLDIR := $(DESTDIR)$(PREFIX)
MANPREFIX := $(DESTDIR)$(MANPREFIX)
DOCDIR := $(DESTDIR)$(DOCDIR)
.PHONY: all options clean dist rebuild check install uninstall
all: options nyx nyx.1.gz
-include $(DEPS)
options:
@echo nyx build options
@echo "build : $(BUILD)"
@echo "CC : $(CC)"
@echo "PLUGINS : $(HAS_PLUGINS)"
@echo "SSL : $(HAS_SSL)"
@echo "OSX : $(IS_OSX)"
@echo "CXXFLAGS : $(CXXFLAGS)"
@echo "INSTALLDIR : $(INSTALLDIR)"
@echo "MANPREFIX : $(MANPREFIX)"
@echo "DOCDIR : $(DOCDIR)"
@echo
nyx: $(OBJECTS)
$(CC) $(OBJECTS) -o nyx $(LIBS)
nyx-static: $(OBJECTS)
$(CC) $(OBJECTS) -s -static -o nyx-static $(LIBS)
check: test
ifneq ("$(CMOCKA_LIB)", "")
@LD_LIBRARY_PATH=$(shell dirname $(CMOCKA_LIB)) ./test
else
@./test
endif
run-tests: nyx
@./tests/scripts/run-tests.sh
@./tests/scripts/run-configs.sh
test: $(TOBJECTS) $(TDEPS)
$(CC) $(TOBJECTS) $(TDEPS) -o test $(LIBS) $(TLIBS)
tests/%.o: tests/%.c
$(CC) -c $(CXXFLAGS) $(INCLUDES) $(TINCLUDES) -o $@ $<
src/%.o: src/%.c
$(CC) -c $(CXXFLAGS) $(INCLUDES) -MMD -MF $(patsubst %.o,%.d,$@) -o $@ $<
nyx.1.gz: nyx.1
@gzip -c $< > $@
dist:
@git archive --output nyx-$(VERSION).tar.gz --prefix nyx-$(VERSION)/ HEAD
tags: $(SRCS)
ctags -R --c-kinds=+lp --fields=+iaS --extra=+q --language-force=C .
install: all
install -d $(INSTALLDIR)/bin
install nyx $(INSTALLDIR)/bin/nyx
install -d $(DOCDIR)/nyx
install -m644 README.markdown LICENSE $(DOCDIR)/nyx
install -d $(MANPREFIX)/man1
install -m644 nyx.1.gz $(MANPREFIX)/man1/
uninstall:
rm -f $(INSTALLDIR)/bin/nyx
rm -f $(MANPREFIX)/man1/nyx.1.gz
rm -rf $(DOCDIR)/nyx
clean:
@rm -rf src/*.o
@rm -rf src/*.d
@rm -rf tests/*.o
@rm -f nyx
@rm -f test
@rm -f nyx.1.gz
@rm -f nyx-$(VERSION).tar.gz
rebuild: clean all