File: GNUmakefile

package info (click to toggle)
beep 1.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 524 kB
  • sloc: ansic: 863; sh: 228; python: 26; makefile: 10
file content (349 lines) | stat: -rw-r--r-- 9,869 bytes parent folder | download
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
########################################################################
# Installation directories
########################################################################

# We use GNU makefile conventions for directory names with one notable
# exception: prefix is not /usr/local in order to keep the default
# installation location for beep.

PACKAGE_TARNAME = beep
PACKAGE_VERSION = 1.4.3

DESTDIR=
prefix=/usr
exec_prefix=$(prefix)
bindir=$(exec_prefix)/bin
sbindir=$(exec_prefix)/sbin
datarootdir=$(prefix)/share
mandir=$(datarootdir)/man
man1dir=$(mandir)/man1
docdir=$(datarootdir)/doc
pkgdocdir=$(docdir)/$(PACKAGE_TARNAME)


########################################################################
# Tools
########################################################################

pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))

# Avoid running GNU make builtin rules by mistake
CC = false

GZIP = $(call pathsearch,gzip)
INSTALL = $(call pathsearch,install)
PANDOC = $(call pathsearch,pandoc)
SED = $(call pathsearch,sed)
SLOCCOUNT = $(call pathsearch,sloccount)


########################################################################
# This needs to be the first rule
########################################################################

.PHONY: all
all: all-local


########################################################################
# Variables to add to later
########################################################################

pkgdoc_DATA =

ALL_PROGRAMS =
bin_PROGRAMS =
sbin_PROGRAMS =
CLEANFILES =
HTML_DATA =
man1_DATA =
pkgdoc_DATA =


########################################################################
# Define compilers and their flags
########################################################################

# We want accidental invocations of rules with $(CC) to fail
CC = false

# CPPFLAGS common to all compilers
CPPFLAGS_COMMON = 
CPPFLAGS_COMMON += -DPACKAGE_TARNAME='"$(PACKAGE_TARNAME)"'
CPPFLAGS_COMMON += -DPACKAGE_VERSION='"$(PACKAGE_VERSION)"'

COMPILER_gcc = gcc
LINKER_gcc = gcc
CPPFLAGS_gcc =
CFLAGS_gcc += -Wall -Wextra
CFLAGS_gcc += -std=gnu99 -pedantic
CFLAGS_gcc += -Werror
CFLAGS_gcc += -O -g
CFLAGS_gcc += -Wa,-adhlns=$(@:-o=-lst)
CFLAGS_gcc += -Werror=format-security
CFLAGS_gcc += -Wp,-D_FORTIFY_SOURCE=2
CFLAGS_gcc += -Wp,-D_GLIBCXX_ASSERTIONS
CFLAGS_gcc += -fstack-protector-strong
CFLAGS_gcc += -fasynchronous-unwind-tables
CFLAGS_gcc += -fstack-clash-protection
ifeq (yes,$(shell if $(COMPILER_gcc) -fcf-protection -E -o null.o -c - < /dev/null > /dev/null 2>&1; then echo yes; else echo no; fi))
CFLAGS_gcc += -fcf-protection
endif
CFLAGS_gcc += -save-temps=obj
LDFLAGS_gcc =
LIBS_gcc =

ifneq ($(call pathsearch,$(COMPILER_gcc)),)
ifneq ($(COMPILER_gcc)),no)
COMPILERS += gcc
endif
endif

COMPILER_clang = clang
LINKER_clang = clang
CPPFLAGS_clang =
CFLAGS_clang += -Wall -Wextra
CFLAGS_clang += -Weverything
CFLAGS_clang += -Wno-padded
CFLAGS_clang += -std=gnu99 -pedantic
CFLAGS_clang += -Werror
CFLAGS_clang += -fsanitize=undefined
CFLAGS_clang += -O -g
LDFLAGS_clang =
LIBS_clang =

ifneq ($(call pathsearch,$(COMPILER_clang)),)
ifneq ($(COMPILER_clang),no)
COMPILERS += clang
endif
endif


########################################################################
# Detect libraries
########################################################################


########################################################################
# Define executables and their flags
########################################################################

bin_PROGRAMS += beep
beep_OBJS =
beep_OBJS += beep.o
beep_OBJS += beep-library.o
beep_OBJS += beep-log.o
beep_OBJS += beep-usage.o
beep_OBJS += beep-drivers.o
beep_OBJS += beep-driver-console.o
beep_OBJS += beep-driver-evdev.o
# beep_OBJS += beep-driver-noop.o
beep_LIBS =

beep-log.clang-o : CFLAGS_clang += -Wno-format-nonliteral

# sbin_PROGRAMS += beep-foo
# beep_foo_OBJS =
# beep_foo_OBJS += beep.o
# beep_foo_OBJS += beep-log.o
# beep_foo_LIBS =
# beep_foo_LIBS += -lm


########################################################################
# Built sources
########################################################################

CLEANFILES += beep-usage.c
beep-usage.c: beep-usage.txt
	echo '/* Auto-generated from beep-usage.txt. Modify that file instead. */' > $@
	echo '#include "beep-usage.h"' >> $@
	echo 'char beep_usage[] =' >> $@
	set -e; IFS=""; while read line; do \
		echo "  \"$${line}\\\\n\"" >> $@; \
	done < $<
	echo '  ;' >> $@


########################################################################
# Compile and Link rules including automatic dependency generation
########################################################################

# CALL: LINK_RULE <compiler> <executable> <executable_as_varname_part>
define LINK_RULE
ALL_PROGRAMS += $(2).$(1)

$(2).$(1): $(patsubst %.o,%.$(1)-o,$($(3)_OBJS))
	@: echo "LINK_RULE $$@: $$^"
	$(LINKER_$(1)) $(CFLAGS) $(CFLAGS_$(1)) $(LDFLAGS) $(LDFLAGS_$(1)) -o $$@ $$^ $($(3)_LIBS) $(LIBS_$(1)) $(LIBS)

-include $$(patsubst %.o,%.$(1)-o.dep,$($(3)_OBJS))
endef

# CALL: PER_COMPILER <compiler>
define PER_COMPILER
$(foreach exec,$(bin_PROGRAMS) $(sbin_PROGRAMS),$(eval $(call LINK_RULE,$(1),$(exec),$(subst -,_,$(exec)))))

%.$(1)-o: %.c
	$$(COMPILER_$(1)) $$(CPPFLAGS) $$(CPPFLAGS_COMMON) $$(CPPFLAGS_$(1)) $$(CFLAGS_COMMON) $$(CFLAGS) $$(CFLAGS_$(1)) -o $$@ -c $$<

%.$(1)-o.dep: %.c
	$$(COMPILER_$(1)) $$(CPPFLAGS) $$(CPPFLAGS_COMMON) $$(CPPFLAGS_$(1)) $$(CFLAGS_COMMON) $$(CFLAGS) $$(CFLAGS_$(1)) -MM -MT "$$*.$(1)-o $$@ " $$< > $$@.tmp
	mv -f $$@.tmp $$@
endef

$(foreach compiler,$(COMPILERS),$(eval $(call PER_COMPILER,$(compiler))))

# For each executable, take the first from COMPILERS to use
%: $(firstword $(foreach comp,$(COMPILERS),%.$(comp)))
	cp -f $< $@


########################################################################
# Generate doc and similar files
########################################################################

man1_DATA  += beep.1.gz
CLEANFILES += beep.1.gz
CLEANFILES += beep.1

%.1: %.1.in
	$(SED) -e "s|[@]pkgdocdir@|$(pkgdocdir)|g" < $< > $@.tmp
	mv -f $@.tmp $@

%.1.gz: %.1
	$(GZIP) --best -c < $< > $@

HTML_DATA += html/README.html
HTML_DATA += html/INSTALL.html
HTML_DATA += html/DEVELOPMENT.html
HTML_DATA += html/PACKAGING.html
HTML_DATA += html/PERMISSIONS.html

.PHONY: html
html: $(HTML_DATA)
	@mkdir -p html
	cp -f pandoc.css html/

html/%.html: %.md
	@mkdir -p  html
	@if test -f $(PANDOC); then \
		echo PANDOC $< -o $@; \
		$(PANDOC) --from gfm --to html --standalone -M pagetitle="$$($(SED) -n 1p $<)" -M title="" -c pandoc.css $< -o $@; \
	else \
		echo "You need to install pandoc to generate the HTML files."; \
		exit 1; \
	fi

pkgdoc_DATA += CHANGELOG
pkgdoc_DATA += COPYING
pkgdoc_DATA += CREDITS
pkgdoc_DATA += README.md
pkgdoc_DATA += PERMISSIONS.md


########################################################################
# Generic targets
########################################################################

.PHONY: all-local
all-local: $(bin_PROGRAMS) $(sbin_PROGRAMS) $(ALL_PROGRAMS) $(man1_DATA)

SLOC_SOURCES =
SLOC_SOURCES += beep*.[ch]
SLOC_SOURCES += gen-freq-table
SLOC_SOURCES += tests/run-tests
SLOC_SOURCES += tests/*.sh
SLOC_SOURCES += GNUmakefile

.PHONY: sloccount
sloccount:
	@if test -e $(SLOCCOUNT); then \
		$(SLOCCOUNT) --details $(SLOC_SOURCES); \
		$(SLOCCOUNT) $(SLOC_SOURCES); \
	else \
		echo "sloccount not found"; \
	fi

SPLINT = splint
SPLINT_FLAGS += -standard
# SPLINT_FLAGS += -checks
# SPLINT_FLAGS += -strict
SPLINT_FLAGS += +posixstrictlib
SPLINT_FLAGS += +gnuextensions
SPLINT_FLAGS += -preproc
SPLINT_FLAGS += -syntax
SPLINT_FLAGS += -D__signed__=signed
SPLINT_FLAGS += $(CPPFLAGS_COMMON)

.PHONY: lint
lint:
	$(SPLINT) $(SPLINT_FLAGS) beep*.c beep*.h

.PHONY: check-targets
check-targets: $(TARGETS) $(CHECK_TARGETS)

.PHONY: check
check: beep $(ALL_PROGRAMS)
	env PACKAGE_VERSION="${PACKAGE_VERSION}" \
	/bin/bash tests/run-tests tests $(foreach compiler,$(COMPILERS),beep.$(compiler))

.PHONY: clean
clean:
	rm -f $(bin_PROGRAMS) $(sbin_PROGRAMS)
	rm -f $(CLEANFILES)
	rm -f $(foreach comp,$(COMPILERS),*.$(comp) *.$(comp)-o)
	rm -f *.dep
	rm -f *.lst *.gcc-lst
	rm -f tests/*.new tests/*.output.actual
	rm -rf html
	rm -f *.o *.i *.s

.PHONY: doc
doc: $(pkgdoc_DATA)

.PHONY: install
install: all
ifneq (,$(bin_PROGRAMS))
	$(INSTALL) -m 0755 -d                 $(DESTDIR)$(bindir)
	$(INSTALL) -m 0755 -p $(bin_PROGRAMS) $(DESTDIR)$(bindir)/
endif
ifneq (,$(sbin_PROGRAMS))
	$(INSTALL) -m 0755 -d                  $(DESTDIR)$(sbindir)
	$(INSTALL) -m 0755 -p $(sbin_PROGRAMS) $(DESTDIR)$(sbindir)/
endif
ifneq (,$(man1_DATA))
	$(INSTALL) -m 0755 -d              $(DESTDIR)$(man1dir)
	$(INSTALL) -m 0644 -p $(man1_DATA) $(DESTDIR)$(man1dir)/
endif
ifneq (,$(pkgdoc_DATA))
	$(INSTALL) -m 0755 -d                $(DESTDIR)$(pkgdocdir)
	$(INSTALL) -m 0644 -p $(pkgdoc_DATA) $(DESTDIR)$(pkgdocdir)/
endif

.PHONY: uninstall
uninstall:
	for f in $(bin_PROGRAMS);  do rm -f "$(DESTDIR)$(bindir)/$$f";    done
	for f in $(sbin_PROGRAMS); do rm -f "$(DESTDIR)$(sbindir)/$$f";   done
	for f in $(man1_DATA);     do rm -f "$(DESTDIR)$(man1dir)/$$f";   done
	for f in $(pkgdoc_DATA);   do rm -f "$(DESTDIR)$(pkgdocdir)/$$f"; done


########################################################################
# Development helpers
########################################################################

# List all references to documentation in the git repo
.PHONY: refs
refs:
	git grep -E '((http|https)://[a-zA-Z0-9\._/-]+|([A-Z]+\.md)|([a-zA-Z][a-zA-Z0-9_-]+\([0-9]+\)))'

# List all TODOs and FIXMEs in the git repo
.PHONY: todo
todo:
	git grep -E '(TODO|FIXME):'


########################################################################
# End of GNUmakefile
########################################################################