summaryrefslogtreecommitdiff
path: root/Makefile
blob: db232890a63e4ccf9129d898926aa50745e3abf3 (plain)
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
# SPDX-License-Identifier: GPL-2.0

PACKAGE := dss
PREFIX ?= /usr/local
INSTALL ?= install
INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
MKDIR_P := mkdir -p
B := build
VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(B)/version.c)
RM := rm -f
LSG := lopsubgen
GROFF := groff -m man -t -Thtml -P -l -P -r -P -I -P image
GZIP := gzip -cfn9
GIT := git
M4 := m4 -D "PACKAGE=$(PACKAGE)" defs.m4
c_source := $(PACKAGE) str file exec sig daemon df tv snap ipc
c_generated := $(B)/$(PACKAGE).lsg $(B)/version
objs := $(addsuffix .o, $(c_generated) $(addprefix $(B)/, $(c_source)))
deps := $(objs:.o=.d)
all := $(PACKAGE) $(PACKAGE).1.gz
www := $(B)/index.html $(B)/$(PACKAGE).1.html $(B)/$(PACKAGE)

all: $(all)
www: $(www)
man: $(PACKAGE).1.gz
$(objs): $(B)/$(PACKAGE).lsg.h Makefile
-include $(deps)

DSS_CPPFLAGS += -Wunused-macros
DSS_CPPFLAGS += -I$(B)

DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
DSS_CFLAGS += -Wredundant-decls
DSS_CFLAGS += -Os
DSS_CFLAGS += -Wall
DSS_CFLAGS += -Wuninitialized
DSS_CFLAGS += -Wchar-subscripts
DSS_CFLAGS += -Wformat-security
DSS_CFLAGS += -Werror-implicit-function-declaration
DSS_CFLAGS += -Wmissing-format-attribute
DSS_CFLAGS += -Wunused-parameter
DSS_CFLAGS += -Wbad-function-cast
DSS_CFLAGS += -Wshadow

CC_CMD = $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
		-MMD -MF $(B)/$(*F).d -MT $@ $<
LD_CMD = $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub

.ONESHELL:
.SHELLFLAGS := -ec
ifeq ("$(origin V)", "command line")
	SAY =
else
	SAY = @printf '%s\n' '$(strip $(1))'
endif
$(B)/version.c:
	$(call SAY, VG $@)
	./version-gen.sh $(PACKAGE) version.c > /dev/null
$(PACKAGE): $(objs)
	$(call SAY, LD $@)
	$(LD_CMD)
$(B)/$(PACKAGE): $(objs)
	$(call SAY, LD $@)
	$(LD_CMD) -static
	strip $@
$(B)/%.o: $(B)/%.c
	$(call SAY, CC $<)
	$(CC_CMD)
$(B)/%.o: %.c
	$(call SAY, CC $<)
	$(CC_CMD)

.PHONY: all www clean distclean maintainer-clean install README
.PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.suite $(B)/%.1
$(B)/$(PACKAGE).suite: $(PACKAGE).suite.m4 defs.m4 Makefile
	$(call SAY, M4 $<)
	$(M4) $< > $@
$(B)/%.lsg.h: $(B)/%.suite
	$(call SAY, LSGH $<)
	$(LSG) --gen-h=$@ < $<
$(B)/%.lsg.c: $(B)/%.suite
	$(call SAY, LSGC $<)
	$(LSG) --gen-c=$@ < $<
$(B)/%.1: $(B)/%.suite
	$(call SAY, LSGM $<)
	$(LSG) --gen-man=$@ --version-string=$(VERSION) < $<
%.1.gz: $(B)/%.1
	$(call SAY, GZIP $<)
	$(GZIP) < $< > $@
$(B)/%.1.html: $(B)/%.1
	$(call SAY, GROFF $<)
	cd $(B)
	$(GROFF) ../$< > ../$@
$(B)/index.html: index.html.m4 Makefile defs.m4 dss.svg
	$(call SAY, M4 $@)
	$(M4) $< > $@
clean:
	$(call SAY, CLEAN)
	$(RM) $(B)/*.o $(B)/*.d $(all) $(www)
distclean: clean
	$(call SAY, DISTCLEAN)
	$(RM) -r $(B)
maintainer-clean: distclean
	$(call SAY, MAINTANER-CLEAN)
	$(GIT) clean -dfqxe Makefile.local

ifneq ($(findstring strip, $(MAKECMDGOALS)),)
       strip_option := -s
endif
bindir := $(DESTDIR)$(PREFIX)/bin
mandir := $(DESTDIR)$(PREFIX)/share/man/man1
install install-strip: all
	$(MKDIR_P) $(bindir) $(mandir)
	$(INSTALL_PROGRAM) $(strip_option) $(PACKAGE) $(bindir)
	$(INSTALL_DATA) $(PACKAGE).1.gz $(mandir)

README:
	@$(M4) README.m4

-include Makefile.local