]> git.tuebingen.mpg.de Git - dss.git/blob - Makefile
Merge topic branch t/realpath into pu
[dss.git] / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2
3 PACKAGE := dss
4 PREFIX ?= /usr/local
5 INSTALL ?= install
6 INSTALL_PROGRAM ?= $(INSTALL)
7 INSTALL_DATA ?= $(INSTALL) -m 644
8 MKDIR_P := mkdir -p
9 B := build
10 VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(B)/version.c)
11 RM := rm -f
12 LSG := lopsubgen
13 GROFF := groff -m man -t -Thtml -P -l -P -r -P -I -P image
14 GZIP := gzip -cfn9
15 GIT := git
16 M4 := m4 -D "PACKAGE=$(PACKAGE)" defs.m4
17 c_source := $(PACKAGE) str file exec sig daemon df tv snap ipc
18 c_generated := $(B)/$(PACKAGE).lsg $(B)/version
19 objs := $(addsuffix .o, $(c_generated) $(addprefix $(B)/, $(c_source)))
20 deps := $(objs:.o=.d)
21 all := $(PACKAGE) $(PACKAGE).1.gz
22 www := $(B)/index.html $(B)/$(PACKAGE).1.html $(B)/$(PACKAGE)
23
24 all: $(all)
25 www: $(www)
26 man: $(PACKAGE).1.gz
27 $(objs): $(B)/$(PACKAGE).lsg.h Makefile
28 -include $(deps)
29
30 DSS_CPPFLAGS += -Wunused-macros
31 DSS_CPPFLAGS += -I$(B)
32
33 DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
34 DSS_CFLAGS += -Wredundant-decls
35 DSS_CFLAGS += -Os
36 DSS_CFLAGS += -Wall
37 DSS_CFLAGS += -Wuninitialized
38 DSS_CFLAGS += -Wchar-subscripts
39 DSS_CFLAGS += -Wformat-security
40 DSS_CFLAGS += -Werror-implicit-function-declaration
41 DSS_CFLAGS += -Wmissing-format-attribute
42 DSS_CFLAGS += -Wunused-parameter
43 DSS_CFLAGS += -Wbad-function-cast
44 DSS_CFLAGS += -Wshadow
45
46 CC_CMD = $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
47                 -MMD -MF $(B)/$(*F).d -MT $@ $<
48 LD_CMD = $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub
49
50 .ONESHELL:
51 .SHELLFLAGS := -ec
52 ifeq ("$(origin V)", "command line")
53         SAY =
54 else
55         SAY = @printf '%s\n' '$(strip $(1))'
56 endif
57 $(B)/version.c:
58         $(call SAY, VG $@)
59         ./version-gen.sh $(PACKAGE) version.c > /dev/null
60 $(PACKAGE): $(objs)
61         $(call SAY, LD $@)
62         $(LD_CMD)
63 $(B)/$(PACKAGE): $(objs)
64         $(call SAY, LD $@)
65         $(LD_CMD) -static
66         strip $@
67 $(B)/%.o: $(B)/%.c
68         $(call SAY, CC $<)
69         $(CC_CMD)
70 $(B)/%.o: %.c
71         $(call SAY, CC $<)
72         $(CC_CMD)
73
74 .PHONY: all www clean distclean maintainer-clean install README
75 .PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.suite $(B)/%.1
76 $(B)/$(PACKAGE).suite: $(PACKAGE).suite.m4 defs.m4 Makefile
77         $(call SAY, M4 $<)
78         $(M4) $< > $@
79 $(B)/%.lsg.h: $(B)/%.suite
80         $(call SAY, LSGH $<)
81         $(LSG) --gen-h=$@ < $<
82 $(B)/%.lsg.c: $(B)/%.suite
83         $(call SAY, LSGC $<)
84         $(LSG) --gen-c=$@ < $<
85 $(B)/%.1: $(B)/%.suite
86         $(call SAY, LSGM $<)
87         $(LSG) --gen-man=$@ --version-string=$(VERSION) < $<
88 %.1.gz: $(B)/%.1
89         $(call SAY, GZIP $<)
90         $(GZIP) < $< > $@
91 $(B)/%.1.html: $(B)/%.1
92         $(call SAY, GROFF $<)
93         cd $(B)
94         $(GROFF) ../$< > ../$@
95 $(B)/index.html: index.html.m4 Makefile defs.m4 dss.svg
96         $(call SAY, M4 $@)
97         $(M4) $< > $@
98 clean:
99         $(call SAY, CLEAN)
100         $(RM) $(B)/*.o $(B)/*.d $(all) $(www)
101 distclean: clean
102         $(call SAY, DISTCLEAN)
103         $(RM) -r $(B)
104 maintainer-clean: distclean
105         $(call SAY, MAINTANER-CLEAN)
106         $(GIT) clean -dfqxe Makefile.local
107
108 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
109        strip_option := -s
110 endif
111 bindir := $(DESTDIR)$(PREFIX)/bin
112 mandir := $(DESTDIR)$(PREFIX)/share/man/man1
113 install install-strip: all
114         $(MKDIR_P) $(bindir) $(mandir)
115         $(INSTALL_PROGRAM) $(strip_option) $(PACKAGE) $(bindir)
116         $(INSTALL_DATA) $(PACKAGE).1.gz $(mandir)
117
118 README:
119         @$(M4) README.m4
120
121 -include Makefile.local