-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathMakefile
95 lines (80 loc) · 3.22 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
CFLAGS := -std=gnu11 -O2 -Wall -Wextra -Wshadow -Wpointer-arith \
-Wcast-align -Wmissing-prototypes -Wstrict-overflow -Wformat=2 \
-Wwrite-strings -Warray-bounds -Wstrict-prototypes \
-Wno-maybe-uninitialized \
-Werror $(CFLAGS)
CPPFLAGS += -I/usr/X11R6/include -L/usr/X11R6/lib
LDLIBS += -lX11 -lXfixes
PREFIX ?= /usr/local
bindir := $(PREFIX)/bin
systemd_user_dir = $(DESTDIR)$(PREFIX)/lib/systemd/user
debug_cflags := -D_FORTIFY_SOURCE=2 -fsanitize=leak -fsanitize=address \
-fsanitize=undefined -Og -ggdb -fno-omit-frame-pointer \
-fstack-protector-strong
c_files := $(wildcard src/*.c)
h_files := $(wildcard src/*.h)
libs := $(filter $(c_files:.c=.o), $(h_files:.h=.o))
bins := clipctl clipmenud clipdel clipserve clipmenu
all: $(addprefix src/,$(bins))
src/%: src/%.c $(libs)
$(CC) $(CFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
src/%.o: src/%.c src/%.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
debug: all
debug: CFLAGS+=$(debug_cflags)
install: all
mkdir -p $(DESTDIR)$(bindir)/
install -pt $(DESTDIR)$(bindir)/ $(addprefix src/,$(bins))
mkdir -p $(systemd_user_dir)
sed 's|@bindir@|$(bindir)|g' init/clipmenud.service.in > $(systemd_user_dir)/clipmenud.service
uninstall:
rm -f $(addprefix $(DESTDIR)$(PREFIX)/bin/,$(bins))
rm -f "$(DESTDIR)${PREFIX}/lib/systemd/user/clipmenud.service"
clean:
rm -f src/*.o src/*~ $(addprefix src/,$(bins))
clang_supports_unsafe_buffer_usage := $(shell clang -x c -c /dev/null -o /dev/null -Werror -Wunsafe-buffer-usage > /dev/null 2>&1; echo $$?)
ifeq ($(clang_supports_unsafe_buffer_usage),0)
extra_clang_flags := -Wno-unsafe-buffer-usage
else
extra_clang_flags :=
endif
c_analyse_targets := $(c_files:%=%-analyse)
h_analyse_targets := $(h_files:%=%-analyse)
analyse: CFLAGS+=$(debug_cflags)
analyse: $(c_analyse_targets) $(h_analyse_targets)
$(c_analyse_targets): %-analyse:
# -W options here are not clang compatible, so out of generic CFLAGS
gcc $< -o /dev/null -c \
-std=gnu99 -Ofast -fwhole-program -Wall -Wextra \
-Wlogical-op -Wduplicated-cond \
-fanalyzer $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
clang $< -o /dev/null -c -std=gnu99 -Ofast -Weverything \
-Wno-documentation-unknown-command \
-Wno-language-extension-token \
-Wno-disabled-macro-expansion \
-Wno-padded \
-Wno-covered-switch-default \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-declaration-after-statement \
-Wno-cast-qual \
-Wno-unused-command-line-argument \
$(extra_clang_flags) \
$(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
$(MAKE) $*-shared-analyse
$(h_analyse_targets): %-analyse:
$(MAKE) $*-shared-analyse
%-shared-analyse: %
# cppcheck is a bit dim about unused functions/variables, leave that to
# clang/GCC
cppcheck $< --std=c99 --quiet --inline-suppr --force \
--enable=all --suppress=missingIncludeSystem \
--suppress=unusedFunction --suppress=unmatchedSuppression \
--suppress=unreadVariable \
--suppress=checkersReport \
--suppress=normalCheckLevelMaxBranches \
--suppress=unusedStructMember \
--max-ctu-depth=32 --error-exitcode=1
# clang-analyzer-unix.Malloc does not understand _drop_()
clang-tidy $< --quiet -checks=-clang-analyzer-unix.Malloc -- -std=gnu99
clang-format --dry-run --Werror $<
.PHONY: all debug install uninstall clean analyse