-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
128 lines (114 loc) · 2.94 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
#
# Copyright (c) 2013-2015 Vladimir Alemasov
# All rights reserved
#
# This program and the accompanying materials are distributed under
# the terms of GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
TARGET = whsnbg
OBJDIR = obj
SRCDIR = src
SOURCES = $(wildcard $(SRCDIR)/*.c)
HEADERS = $(wildcard $(SRCDIR)/*.h)
OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS = $(HEADERS)
INCLPATH += -I.
# Installation directories by convention
# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
PREFIX = /usr/local
EXEC_PREFIX = $(PREFIX)
BINDIR = $(EXEC_PREFIX)/bin
SYSCONFDIR = $(PREFIX)/etc
LOCALSTATEDIR = $(PREFIX)/var
CFLAGS += -DSYSCONFDIR=\"$(SYSCONFDIR)\"
CFLAGS += -DLOCALSTATEDIR=\"$(LOCALSTATEDIR)\"
# Syntax of Conditionals
# https://www.gnu.org/software/make/manual/html_node/Conditional-Syntax.html
ifdef DAEMON_VERSION
CFLAGS += -DLINUX_DAEMON_VERSION
endif
ifndef DETAILED_LOG
CFLAGS += -DNDPRINTF
endif
ifdef RULES_ENGINE
CFLAGS += -DRULES_ENGINE
endif
ifdef TLS_LIB_AXTLS
CFLAGS += -DUSE_TLS_LIBRARY
CFLAGS += -DAXTLS_LIBRARY
LIBS += -laxtls
endif
ifdef TLS_LIB_OPENSSL
CFLAGS += -DUSE_TLS_LIBRARY
CFLAGS += -DOPENSSL_LIBRARY
LIBS += -lssl -lcrypto
ifdef STATIC_LINK
LIBS += -lz
endif
endif
ifdef SENSOR_DATA_DECODING
CFLAGS += -DSENSOR_DATA
endif
ifdef SENSOR_DATA_STORING
CFLAGS += -DSENSOR_DATA_MYSQL
endif
ifdef MQTT_DATA_STORING
CFLAGS += -DMQTT_DATA_MYSQL
endif
ifneq ($(SENSOR_DATA_STORING),$(filter $(MQTT_DATA_STORING),))
INCLPATH += -I/usr/include/mysql
LIBS += -lmysqlclient
ifdef STATIC_LINK
LIBS += -lz
endif
endif
LIBS += -lpthread -lgcc_eh -lm
ifdef STATIC_LINK
LIBS += -ldl -static
endif
ifdef WITH_DEBUG
CFLAGS += -g
else
CFLAGS += -O2 -DNDEBUG
endif
# main goal
all: $(TARGET)
# target executable
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) -o $(TARGET) $(OBJECTS) $(LIBPATH) $(LIBS)
# object files
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c $(DEPS) | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@ $(INCLPATH)
# create object files directory
$(OBJDIR):
mkdir -p $(OBJDIR)
# clean
clean:
rm -rf $(OBJDIR)
# distclean
distclean: clean
rm -f $(TARGET)
# install
# http://unixhelp.ed.ac.uk/CGI/man-cgi?install
install: all
install -d -m 755 $(BINDIR)
install -m 755 $(TARGET) $(BINDIR)
install -d -m 755 $(SYSCONFDIR)
cp -n ./res/whsnbg.conf $(SYSCONFDIR) || true
chmod 644 $(SYSCONFDIR)/whsnbg.conf
cp -n ./res/whsnbg.pem $(SYSCONFDIR) || true
chmod 444 $(SYSCONFDIR)/whsnbg.pem
# uninstall
uninstall:
rm -f $(BINDIR)/$(TARGET)
rm -f $(SYSCONFDIR)/whsnbg.conf
rm -f $(SYSCONFDIR)/whsnbg.pem
rm -f $(LOCALSTATEDIR)/whsnbg.rules
rm -f $(LOCALSTATEDIR)/whsnbg.log
.PHONY: all clean distclean install uninstall