]> git.tuebingen.mpg.de Git - misma.git/blob - Makefile
Fix seconds_to_human().
[misma.git] / Makefile
1 # SPDX-License-Identifier: GPL-2.0+
2 .SUFFIXES:
3 MAKEFLAGS += -Rr
4 ifeq ("$(origin CC)", "default")
5         CC := cc
6 endif
7 ifeq ("$(origin V)", "command line")
8         SAY =
9 else
10         SAY = @echo '$(strip $(1))'
11 endif
12
13 .ONESHELL:
14 .SHELLFLAGS := -ec
15 PREFIX ?= /usr/local
16 INSTALL ?= install
17 MKDIR_P := mkdir -p
18 RM := rm -f
19 CHMOD := chmod
20 GROFF := groff
21 B := build
22 all := misma misma.8
23 all: $(all)
24
25 PACKAGE := misma
26 SLOGAN := the minimal snapshot manager
27 AUTHOR := Andre Noll
28 EMAIL := maan@tuebingen.mpg.de
29 COPYRIGHT_YEAR := 2024
30 URL := http://people.tuebingen.mpg.de/maan/$(PACKAGE)/
31 CLONE_URL := git://git.tuebingen.mpg.de/$(PACKAGE)
32 GITWEB_URL := http://git.tuebingen.mpg.de/$(PACKAGE).git
33 HOME_URL := http://people.tuebingen.mpg.de/maan/
34 LICENSE := GPL-2.0+
35 LICENSE_URL := https://www.gnu.org/licenses/gpl-3.0-standalone.html
36 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
37
38 units := misma util version misma.lsg
39 deps := $(addprefix $(B)/, $(addsuffix .d, $(units)))
40 objs := $(addprefix $(B)/, $(addsuffix .o, $(units)))
41
42 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
43 ifeq ($(findstring README, $(MAKECMDGOALS)),)
44 -include $(deps)
45 -include $(B)/config.mak
46 endif
47 endif
48
49 XCPPFLAGS :=
50 XCPPFLAGS += -I$(B)
51 XCPPFLAGS += -Wunused-macros
52 XCPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
53 XCPPFLAGS += -DPACKAGE='"$(PACKAGE)"'
54 XCPPFLAGS += -DAUTHOR='"$(AUTHOR)"'
55 XCPPFLAGS += -DEMAIL='"$(EMAIL)"'
56 XCPPFLAGS += -DURL='"$(URL)"'
57 XCPPFLAGS += -DCLONE_URL='"$(CLONE_URL)"'
58 XCPPFLAGS += -DGITWEB_URL='"$(GITWEB_URL)"'
59 XCPPFLAGS += -DHOME_URL='"$(HOME_URL)"'
60 XCPPFLAGS += -DGET_VERSION='$(PACKAGE)_version'
61 XCPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
62 XCPPFLAGS += -DBUILD_DATE='"$(build_date)"'
63 XCPPFLAGS += -DCC_VERSION='"$(cc_version)"'
64 XCPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
65 XCPPFLAGS += -DLICENSE='"$(LICENSE)"'
66 XCPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
67
68 XCFLAGS :=
69 XCFLAGS += -fno-strict-aliasing
70 XCFLAGS += -g
71 XCFLAGS += -Os
72 XCFLAGS += -Wundef -W -Wuninitialized
73 XCFLAGS += -Wchar-subscripts
74 XCFLAGS += -Werror-implicit-function-declaration
75 XCFLAGS += -Wmissing-noreturn
76 XCFLAGS += -Wbad-function-cast
77 XCFLAGS += -Wredundant-decls
78 XCFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
79 XCFLAGS += -Wdeclaration-after-statement
80 XCFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
81 XCFLAGS += -fdata-sections -ffunction-sections
82 XCFLAGS += -Wstrict-prototypes
83 XCFLAGS += -Wshadow
84 XCFLAGS += -Wunused -Wall
85 XCFLAGS += -Wformat-signedness
86 XCFLAGS += -Wdiscarded-qualifiers
87
88 XLDFLAGS := -Wl,--gc-sections
89 version_file := $(B)/version.c
90 GIT_VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(version_file))
91
92 CC_CMD = $(CC) -c -o $@ $(XCPPFLAGS) $(CPPFLAGS) \
93         $(XCFLAGS) $(CFLAGS) -MMD -MF $(B)/$(*F).d -MT $@
94
95 $(objs): misma.h $(B)/misma.lsg.h Makefile
96
97 $(B):
98         @$(MKDIR_P) $@
99
100 $(B)/config.h.in: configure.ac | $(B)
101         $(call SAY, AH $<)
102         cd $(B)
103         autoheader -f ../configure.ac
104 $(B)/configure.sh: configure.ac | $(B)
105         $(call SAY, AC $<)
106         cd $(B)
107         autoconf ../configure.ac > configure.sh
108         $(CHMOD) 755 configure.sh
109 $(B)/config.status: $(B)/configure.sh | $(B)
110         $(call SAY, SH $<)
111         cd $(B)
112         if test -x config.status; then \
113                 ./config.status --quiet --recheck; \
114         else \
115                 ./configure.sh --no-create; \
116         fi
117 $(B)/config.mak $(B)/config.h: $(B)/config.status config.mak.in $(B)/config.h.in
118         $(call SAY, CS $@)
119         cd $(B)
120         ln -f ../config.mak.in
121         ./config.status -q
122         test -f config.h && touch config.h
123
124 define DESCRIPTION1 :=
125         PACKAGE() is an open source application which maintains snapshots of one
126         or more thin provisioned logical volumes on Linux systems.
127 endef
128
129 define DESCRIPTION2 :=
130         Snapshots are created and removed automatically according to the
131         configured schedule. Old snapshots are replaced so that the time
132         between two consecutive snapshots doubles at each step. To prevent data
133         or metadata space exhaustion, the available space of the underlying
134         thin pools is monitored periodically and snapshots are removed early
135         when space gets tight.
136 endef
137
138 define DESCRIPTION3 :=
139         Besides the run subcommand which implements snapshot scheduling and
140         free space monitoring, PACKAGE() supports additional subcommands
141         to list existing snapshots and the utilization of the thin pools,
142         or to create/remove snapshots manually.
143 endef
144
145 define M4_CMD =
146         $(call SAY, M4 $<)
147         $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
148                 -D "PACKAGE=$(PACKAGE)" \
149                 -D "SLOGAN=$(SLOGAN)" \
150                 -D "EMAIL=$(EMAIL)" \
151                 -D "URL=$(URL)" \
152                 -D "CLONE_URL=$(CLONE_URL)" \
153                 -D "GITWEB_URL=$(GITWEB_URL)" \
154                 -D "HOME_URL=$(HOME_URL)" \
155                 -D "LICENSE=$(LICENSE)" \
156                 -D "LICENSE_URL=$(LICENSE_URL)" \
157                 -D "DESCRIPTION1=$(DESCRIPTION1)" \
158                 -D "DESCRIPTION2=$(DESCRIPTION2)" \
159                 -D "DESCRIPTION3=$(DESCRIPTION3)"
160 endef
161
162 $(B)/logo.svg: index.html.m4 Makefile
163         $(M4_CMD) -D MODE=svg $< > $@
164 $(B)/index.html: index.html.m4 Makefile
165         $(M4_CMD) $< > $@
166 $(B)/misma.suite: misma.suite.m4 Makefile
167         $(M4_CMD) $< > $@
168 $(B)/%.lsg.c: $(B)/%.suite
169         $(call SAY, LSGC $<)
170         $(LOPSUBGEN) --gen-c --output-dir $(B) < $<
171 $(B)/%.lsg.h: $(B)/%.suite
172         $(call SAY, LSGH $<)
173         $(LOPSUBGEN) --gen-header --output-dir $(B) < $<
174 %.8: $(B)/%.suite $(B)/version.c
175         $(call SAY, LSGM $<)
176         $(LOPSUBGEN) --gen-man=$(*F).8 --version-string $(GIT_VERSION) < $<
177 $(B)/%.8.html: %.8
178         $(GROFF) -m man -Thtml -Wbreak < $< > $@
179
180 $(B)/%.o: %.c | $(B)
181         $(call SAY, CC $<)
182         $(CC_CMD) $<
183 $(B)/%.o: $(B)/%.c
184         $(call SAY, CC $<)
185         $(CC_CMD) $<
186 $(PACKAGE): $(objs)
187         $(call SAY, LD $@)
188         $(CC) -o $@ $^ $(XLDFLAGS) $(LDFLAGS) -llopsub -lm
189 $(B)/$(PACKAGE): $(objs)
190         $(call SAY, LD-STATIC $@)
191         $(CC) -static -o $@ $^ $(XLDFLAGS) $(LDFLAGS) -llopsub -lm
192
193 mandir := $(datarootdir)/man/man8
194 INSTALL ?= install
195 INSTALL_PROGRAM ?= $(INSTALL) -m 755
196 INSTALL_DATA ?= $(INSTALL) -m 644
197 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
198         strip_option := -s
199 endif
200 install install-strip: all
201         $(MKDIR_P) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)
202         $(INSTALL_PROGRAM) $(strip_option) misma $(DESTDIR)$(sbindir)
203         $(INSTALL_DATA) misma.8 $(DESTDIR)$(mandir)
204
205 clean:
206         $(RM) $(B)/*.o $(all)
207 distclean: clean
208         $(RM) -r $(B)
209 maintainer-clean:
210         git clean -dfqx > /dev/null 2>&1
211
212 define README :=
213 $(PACKAGE) -  $(SLOGAN)
214
215 $(DESCRIPTION1)
216
217 $(DESCRIPTION2)
218
219 $(DESCRIPTION3)
220
221 Resources
222 ~~~~~~~~~
223 |       web page: $(URL)
224 |       git clone URL: $(CLONE_URL)
225 |       gitweb: $(GITWEB_URL)
226 |       author's home page: $(HOME_URL)
227 |       Send feedback to: $(AUTHOR) <$(EMAIL)>
228
229 License
230 ~~~~~~~
231 Open source, licensed under the $(LICENSE) license.
232
233 Documentation
234 ~~~~~~~~~~~~~
235 See misma.suite.m4. Or build the man page with \"make\" and run
236 \"man -l misma.8\".
237
238 Dependencies
239 ~~~~~~~~~~~~
240 This package requires m4, autoconf, gnu make, gcc or clang, and
241 lopsub. The configure script checks if all dependencies are installed
242 and prints a meaningful error message if one of them is missing.
243
244 Building
245 ~~~~~~~~
246 Run \"make\" to build the package with the default settings. Run
247 \"./configure -h\" to list configuration options.
248
249 Installation
250 ~~~~~~~~~~~~
251 Run \"sudo make install\" to install to /usr/local. To install to
252 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
253 first.
254 endef
255
256 README:
257         @printf '%s\n' "$(README)"
258
259 .PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.8
260 .PHONY: all clean install distclean maintainer-clean README
261 -include Makefile.local