forked from Theldus/wsServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (132 loc) · 4.13 KB
/
Makefile
File metadata and controls
150 lines (132 loc) · 4.13 KB
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
# Copyright (C) 2016-2020 Davidson Francis <davidsondfgl@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
CC ?= gcc
AR = ar
INCLUDE = $(CURDIR)/include
SRC = $(CURDIR)/src
CFLAGS += -Wall -Wextra -O2
CFLAGS += -I $(INCLUDE) -std=c99 -pedantic
ARFLAGS = cru
LIB = libws.a
MCSS_DIR ?= /usr/bin/
MANPAGES = $(CURDIR)/doc/man/man3
AFL_FUZZ ?= no
# Prefix
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
# Detect machine type
MACHINE := $(shell uname -m)
ifeq ($(MACHINE), x86_64)
LIBDIR = $(PREFIX)/lib64
else
LIBDIR = $(PREFIX)/lib
endif
# Check if AFL fuzzing enabled
ifeq ($(AFL_FUZZ), yes)
CC = afl-gcc
CFLAGS := $(filter-out -O2,$(CFLAGS))
CFLAGS += -DVERBOSE_MODE -DAFL_FUZZ -g
$(info [+] AFL Fuzzing build enabled)
endif
# Source
C_SRC = $(wildcard $(SRC)/base64/*.c) \
$(wildcard $(SRC)/handshake/*.c) \
$(wildcard $(SRC)/sha1/*.c) \
$(wildcard $(SRC)/*.c)
OBJ = $(C_SRC:.c=.o)
# Conflicts
.PHONY: doc
.PHONY: tests
# Paths
INCDIR = $(PREFIX)/include
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/man
PKGDIR = $(LIBDIR)/pkgconfig
# General objects
%.o: %.c
$(CC) $< $(CFLAGS) -c -o $@
# All
ifeq ($(AFL_FUZZ),no)
all: libws.a examples
else
all: libws.a tests
endif
# Library
libws.a: $(OBJ)
$(AR) $(ARFLAGS) $(LIB) $^
# Examples
examples: libws.a
$(MAKE) -C example/
# Fuzzing tests
tests: libws.a
$(MAKE) -C tests/
# Install rules
install: all wsserver.pc
@#Library
install -d $(DESTDIR)$(LIBDIR)
install -m 644 $(LIB) $(DESTDIR)$(LIBDIR)
@#Headers
install -d $(DESTDIR)$(INCDIR)/wsserver
install -m 644 $(INCLUDE)/*.h $(DESTDIR)$(INCDIR)/wsserver
@#Manpages
install -d $(DESTDIR)$(MANDIR)/man3
install -m 0644 $(MANPAGES)/*.3 $(DESTDIR)$(MANDIR)/man3/
# Uninstall rules
uninstall:
rm -f $(DESTDIR)$(LIBDIR)/$(LIB)
rm -rf $(DESTDIR)$(INCDIR)/wsserver
rm -f $(DESTDIR)$(MANDIR)/man3/ws_getaddress.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_sendframe.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_sendframe_bin.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_sendframe_txt.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_socket.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_close_client.3
rm -f $(DESTDIR)$(MANDIR)/man3/ws_get_state.3
rm -f $(DESTDIR)$(PKGDIR)/wsserver.pc
# Generate wsserver.pc
wsserver.pc:
@install -d $(DESTDIR)$(PKGDIR)
@echo 'prefix='$(DESTDIR)$(PREFIX) > $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'libdir='$(DESTDIR)$(LIBDIR) >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'includedir=$${prefix}/include' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Name: wsServer' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Description: Tiny WebSocket Server Library' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Version: 1.0' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Libs: -L$${libdir} -lws -pthread' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Libs.private:' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
@echo 'Cflags: -I$${includedir}/wsserver' >> $(DESTDIR)$(PKGDIR)/wsserver.pc
# Documentation, requires Doxygen and m.css
# -> https://mcss.mosra.cz/documentation/doxygen/
#
# If for some reason m.css usage is not possible,
# change the following lines in doxy.conf to:
# GENERATE_HTML = no -> GENERATE_HTML = yes
# GENERATE_XML = yes -> GENERATE_XML = no
#
doc:
@echo "Generating docs..."
@doxygen doc/doxygen/doxy.conf
@$(MCSS_DIR)/doxygen.py doc/doxygen/Doxyfile-mcss --no-doxygen\
--templates doc/doxygen/templates/
# Clean
clean:
@rm -f $(SRC)/base64/*.o
@rm -f $(SRC)/handshake/*.o
@rm -f $(SRC)/sha1/*.o
@rm -f $(SRC)/*.o
@rm -f $(LIB)
@$(MAKE) clean -C example/
@$(MAKE) clean -C tests/