-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.in
More file actions
199 lines (154 loc) · 5.48 KB
/
Makefile.in
File metadata and controls
199 lines (154 loc) · 5.48 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# SPDX-License-Identifier: GPL-2.0-or-later
PACKAGE_NAME := @PACKAGE_NAME@
PACKAGE_VERSION := @PACKAGE_VERSION@
VERBOSE ?= $(V)
Q = $(if $(VERBOSE),,@)
PROGS =
PLUGINS =
GARBAGE =
bindir = @bindir@
libdir = @libdir@
libexecdir = @libexecdir@
pluginsdir = @libexecdir@/@PACKAGE_NAME@
PLUGINSDIR := $(CURDIR)/plugins
PTHREAD_CFLAGS := @PTHREAD_CFLAGS@
PTHREAD_LIBS := @PTHREAD_LIBS@
NCURSES_CFLAGS := @NCURSES_CFLAGS@
NCURSES_LIBS := @NCURSES_LIBS@
PANEL_CFLAGS := @PANEL_CFLAGS@
PANEL_LIBS := @PANEL_LIBS@
WARNINGS = \
-Wall -W -Waggregate-return -Wconversion -Wdisabled-optimization \
-Wmissing-declarations -Wmissing-format-attribute -Wmissing-noreturn \
-Wmissing-prototypes -Wpointer-arith -Wredundant-decls -Wshadow \
-Wstrict-prototypes -Wwrite-strings -Wmismatched-dealloc \
#
CPPFLAGS = \
-std=gnu99 -D_GNU_SOURCE -I$(CURDIR) -I$(CURDIR)/src \
-DPLUGINSDIR=\"$(pluginsdir)\" \
#
CFLAGS = -g -O0 -fPIC $(if $(DEBUG),-DDEBUG)
CFLAGS += $(PTHREAD_CFLAGS) $(NCURSES_CFLAGS) $(PANEL_CFLAGS)
override CFLAGS := $(WARNINGS) $(CFLAGS)
LDLIBS =
COMMON_SO = libplainmouth.so
COMMON_SRC = src/ipc.c src/request.c src/plugin.c src/dump.c \
src/warray.c \
src/widget.c \
src/widget_border.c \
src/widget_button.c \
src/widget_checkbox.c \
src/widget_hbox.c \
src/widget_hscroll.c \
src/widget_input.c \
src/widget_label.c \
src/widget_list_vbox.c \
src/widget_meter.c \
src/widget_pad_box.c \
src/widget_scroll_vbox.c \
src/widget_select.c \
src/widget_select_opt.c \
src/widget_spinbox.c \
src/widget_textview.c \
src/widget_tooltip.c \
src/widget_vbox.c \
src/widget_vscroll.c \
src/widget_window.c \
#
COMMON_OBJ = $(COMMON_SRC:.c=.o)
COMMON_LIBS = $(NCURSES_LIBS) $(PANEL_LIBS)
GARBAGE += $(COMMON_SO) $(COMMON_OBJ)
PROGS += plainmouthd
SRC_plainmouthd = src/plainmouthd.c
OBJ_plainmouthd = $(SRC_plainmouthd:.c=.o)
LIB_plainmouthd = $(PTHREAD_LIBS) $(NCURSES_LIBS) $(PANEL_LIBS) -L$(CURDIR) -lplainmouth
GARBAGE += plainmouthd $(OBJ_plainmouthd)
PROGS += plainmouth
SRC_plainmouth = src/plainmouth.c
OBJ_plainmouth = $(SRC_plainmouth:.c=.o)
LIB_plainmouth = -L$(CURDIR) -lplainmouth
GARBAGE += plainmouth $(OBJ_plainmouth)
PLUGINS = $(basename $(notdir $(wildcard src/plugins/*-main.c)))
PLUGINS := $(PLUGINS:-main=)
GARBAGE += $(PLUGINSDIR)
quiet_cmd = $(if $(VERBOSE),$(3),$(Q)printf " %-08s%s\n" "$(1)" "$(2)"; $(3))
cmd_MKDIR = $(call quiet_cmd,MKDIR,$(patsubst $(CURDIR)/%,%,$(1))/,mkdir -p) -- $(1)
cmd_COPY = $(call quiet_cmd,COPY,$(patsubst $(CURDIR)/%,%,$(1)),cp -a) -- $(1) $(2)
cmd_LINK = $(call quiet_cmd,LD,$(patsubst $(CURDIR)/%,%,$@),$(LINK.o)) $(1) $(LOADLIBES) $(LDLIBS) -o $@
.PHONY: all clean
TARGETS = \
$(PROGS) \
$(patsubst %,$(PLUGINSDIR)/%.so,$(PLUGINS)) \
#
all: $(TARGETS)
clean:
$(Q)$(RM) -r -- $(GARBAGE)
plugins: Makefile
$(call cmd_MKDIR,$(PLUGINSDIR))
%.o: %.c
$(call quiet_cmd,CC,$<,$(COMPILE.c)) $(CFLAGS) $(OUTPUT_OPTION) $<
$(COMMON_SO): Makefile $(COMMON_OBJ)
$(call quiet_cmd,LD,$@,$(CC) -shared -o $@ $(COMMON_OBJ)) $(COMMON_LIBS)
plainmouthd: Makefile $(COMMON_SO) $(OBJ_plainmouthd) plugins
$(call cmd_LINK,$(OBJ_plainmouthd)) $(LIB_plainmouthd)
plainmouth: Makefile $(COMMON_SO) $(OBJ_plainmouth)
$(call cmd_LINK,$(OBJ_plainmouth)) $(LIB_plainmouth)
### Plugins
PLUGINS_LIBS = -shared -ldl $(NCURSES_LIBS) $(PANEL_LIBS) -L$(CURDIR) -lplainmouth
PLUGINS_SRC = $(wildcard src/plugins/*.c)
PLUGINS_OBJ = $(PLUGINS_SRC:.c=.o)
PLUGINS_NAMES = $(patsubst src/plugins/%-main.c,%,$(PLUGINS_SRC))
GARBAGE += $(PLUGINS_OBJ)
plugin_objs = $(filter src/plugins/$(1)-%.o,$(PLUGINS_OBJ))
define build_plugin =
$(PLUGINSDIR)/$(1).so: $$(call plugin_objs,$(1))
$$(call cmd_LINK,$$^) $(PLUGINS_LIBS)
endef
$(foreach n,$(PLUGINS_NAMES),\
$(eval $(call build_plugin,$(n))))
### Tests
.PHONY: check build-checks
VALGRIND = valgrind --error-exitcode=1 \
--leak-check=full --time-stamp=yes --trace-children=yes \
--track-fds=yes --track-origins=yes \
#
TESTS := $(sort $(basename \
$(wildcard tests/ipc/ipc_*.c) \
$(wildcard tests/warray/warray_*.c) \
$(wildcard tests/widget/widget_*.c) \
))
TESTS_E2E := $(sort $(basename \
$(wildcard tests/e2e-*.sh) \
))
GARBAGE += $(TESTS) \
$(wildcard tests/*.chk) \
$(wildcard tests/*.chk.e2e) \
$(wildcard tests/*.dump) \
$(wildcard tests/*.log) \
$(wildcard tests/*.sock)
.NOTINTERMEDIATE: $(TESTS)
build-checks: $(TESTS)
tests/ipc/%: tests/ipc/%.o src/ipc.o
$(call cmd_LINK,$^)
tests/warray/%: tests/warray/%.o src/warray.o
$(call cmd_LINK,$^)
tests/widget/%: tests/widget/%.o src/widget.o
$(call cmd_LINK,$^) $(NCURSES_LIBS) $(PANEL_LIBS)
tests/%.chk: tests/%
@timeout -s KILL 5s $(VALGRIND) "$<" >"$<.log" 2>&1 && status='ok' || status='fail'; \
flock -x $(CURDIR)/tests printf '%4s %s\n' "$$status" "$<"; \
echo $$status > $@
tests/%.chk.e2e: tests/%.sh $(TARGETS)
@timeout -s KILL 5s "$<" >"$<.log" 2>&1 && status='ok' || status='fail'; \
flock -x $(CURDIR)/tests printf '%4s %s\n' "$$status" "$<"; \
echo $$status > $@
check: $(addsuffix .chk,$(TESTS)) $(addsuffix .chk.e2e,$(TESTS_E2E))
@ret=0; ! grep -qsx fail -- $^ || ret=1; $(RM) -- $^; exit $$ret;
.PHONY: install
install: $(TARGETS)
$(call cmd_MKDIR,$(DESTDIR)$(bindir))
$(call cmd_MKDIR,$(DESTDIR)$(libdir))
$(call cmd_MKDIR,$(DESTDIR)$(pluginsdir))
$(call cmd_COPY,$(PROGS),$(DESTDIR)$(bindir))
$(call cmd_COPY,$(COMMON_SO),$(DESTDIR)$(libdir))
$(call cmd_COPY,$(PLUGINSDIR)/*.so,$(DESTDIR)$(pluginsdir))