Initial commit.
[micoforia.git] / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
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 B := build
21 all := micoforia micoforia.8
22 all: $(all)
23
24 PACKAGE := micoforia
25 SLOGAN := Minimal Containers for Instant Availability
26 AUTHOR := Andre Noll
27 EMAIL := maan@tuebingen.mpg.de
28 COPYRIGHT_YEAR := 2019
29 URL := http://people.tuebingen.mpg.de/maan/$(PACKAGE)/
30 CLONE_URL := git://git.tuebingen.mpg.de/$(PACKAGE)
31 GITWEB_URL := http://git.tuebingen.mpg.de/$(PACKAGE).git
32 HOME_URL := http://people.tuebingen.mpg.de/maan/
33 LICENSE := GNU GPL version 3
34 LICENSE_URL := https://www.gnu.org/licenses/gpl-3.0-standalone.html
35 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
36
37 units := micoforia util version micoforia.lsg
38 deps := $(addprefix $(B)/, $(addsuffix .d, $(units)))
39 objs := $(addprefix $(B)/, $(addsuffix .o, $(units)))
40
41 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
42 ifeq ($(findstring README, $(MAKECMDGOALS)),)
43 -include $(deps)
44 -include $(B)/config.mak
45 endif
46 endif
47
48 XCPPFLAGS :=
49 XCPPFLAGS += -I$(B)
50 XCPPFLAGS += -Wunused-macros
51 XCPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
52 XCPPFLAGS += -DPACKAGE='"$(PACKAGE)"'
53 XCPPFLAGS += -DAUTHOR='"$(AUTHOR)"'
54 XCPPFLAGS += -DEMAIL='"$(EMAIL)"'
55 XCPPFLAGS += -DURL='"$(URL)"'
56 XCPPFLAGS += -DCLONE_URL='"$(CLONE_URL)"'
57 XCPPFLAGS += -DGITWEB_URL='"$(GITWEB_URL)"'
58 XCPPFLAGS += -DHOME_URL='"$(HOME_URL)"'
59 XCPPFLAGS += -DGET_VERSION='$(PACKAGE)_version'
60 XCPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
61 XCPPFLAGS += -DBUILD_DATE='"$(build_date)"'
62 XCPPFLAGS += -DCC_VERSION='"$(cc_version)"'
63 XCPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
64 XCPPFLAGS += -DLICENSE='"$(LICENSE)"'
65 XCPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
66
67 XCFLAGS :=
68 XCFLAGS += -fno-strict-aliasing
69 XCFLAGS += -g
70 XCFLAGS += -Os
71 XCFLAGS += -Wundef -W -Wuninitialized
72 XCFLAGS += -Wchar-subscripts
73 XCFLAGS += -Werror-implicit-function-declaration
74 XCFLAGS += -Wmissing-noreturn
75 XCFLAGS += -Wbad-function-cast
76 XCFLAGS += -Wredundant-decls
77 XCFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
78 XCFLAGS += -Wdeclaration-after-statement
79 XCFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
80 XCFLAGS += -fsanitize=undefined
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 := -lubsan -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): m7a.h $(B)/micoforia.lsg.h
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 a lightweight container implementation for Linux.
126 It consists of a single program which reads a single configuration
127 file that describes all containers. $(PACKAGE) was written with
128 performance and simplicity in mind, and is designed for trusted
129 in-house web application hosting.
130 endef
131
132 define DESCRIPTION2 :=
133 Like other container frameworks, $(PACKAGE) employs Linux namespaces
134 for isolation and cgroup controllers to limit the resource utilization
135 of the containers. Networking is implemented through bridging and
136 virtual ethernet device pairs. There is built-in support for the cpu,
137 memory, I/O and device controllers. Further customization is possible
138 via startup hooks. For example, the startup hook could activate
139 additional cgroup controllers, make the container enter a different
140 namespace, and mount additional file systems.
141 endef
142
143 define DESCRIPTION3 :=
144 The micoforia program supports a couple of subcommands. Besides
145 the start subcommand which starts one or more containers, there are
146 subcommands for listing, killing or rebooting containers.
147 endef
148
149 # dependency on config.mak is because the command below depends on $(M4)
150 $(B)/index.html $(B)/micoforia.suite: $(B)/%: %.m4 Makefile $(B)/config.mak
151 $(call SAY, M4 $<)
152 $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
153 -D "PACKAGE=$(PACKAGE)" \
154 -D "SLOGAN=$(SLOGAN)" \
155 -D "EMAIL=$(EMAIL)" \
156 -D "URL=$(URL)" \
157 -D "CLONE_URL=$(CLONE_URL)" \
158 -D "GITWEB_URL=$(GITWEB_URL)" \
159 -D "HOME_URL=$(HOME_URL)" \
160 -D "LICENSE=$(LICENSE)" \
161 -D "LICENSE_URL=$(LICENSE_URL)" \
162 -D "DESCRIPTION1=$(DESCRIPTION1)" \
163 -D "DESCRIPTION2=$(DESCRIPTION2)" \
164 -D "DESCRIPTION3=$(DESCRIPTION3)" $< > $@
165 $(B)/%.lsg.c: $(B)/%.suite
166 $(call SAY, LSGC $<)
167 $(LOPSUBGEN) --gen-c --output-dir $(B) < $<
168 $(B)/%.lsg.h: $(B)/%.suite
169 $(call SAY, LSGH $<)
170 $(LOPSUBGEN) --gen-header --output-dir $(B) < $<
171 %.8: $(B)/%.suite $(B)/version.c
172 $(call SAY, LSGM $<)
173 $(LOPSUBGEN) --gen-man=$(*F).8 --version-string $(GIT_VERSION) < $<
174
175 $(B)/%.o: %.c | $(B)
176 $(call SAY, CC $<)
177 $(CC_CMD) $<
178 $(B)/%.o: $(B)/%.c
179 $(call SAY, CC $<)
180 $(CC_CMD) $<
181 micoforia: $(objs)
182 $(call SAY, LD $@)
183 $(CC) -o $@ $^ $(XLDFLAGS) $(LDFLAGS) -llopsub -lmnl -lutil -lcap
184
185 mandir := $(datarootdir)/man/man8
186 INSTALL ?= install
187 INSTALL_PROGRAM ?= $(INSTALL) -m 755
188 INSTALL_DATA ?= $(INSTALL) -m 644
189 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
190 strip_option := -s
191 endif
192 install install-strip: all
193 $(MKDIR_P) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)
194 $(INSTALL_PROGRAM) $(strip_option) micoforia $(DESTDIR)$(sbindir)
195 $(INSTALL_DATA) micoforia.8 $(DESTDIR)$(mandir)
196
197 clean:
198 $(RM) $(B)/*.o $(all)
199 distclean: clean
200 $(RM) -r $(B)
201 maintainer-clean:
202 git clean -dfqx > /dev/null 2>&1
203
204 define README :=
205 $(PACKAGE) - $(SLOGAN)
206
207 $(DESCRIPTION1)
208
209 $(DESCRIPTION2)
210
211 $(DESCRIPTION3)
212
213 Resources
214 ~~~~~~~~~
215 | web page: $(URL)
216 | git clone URL: $(CLONE_URL)
217 | gitweb: $(GITWEB_URL)
218 | author's home page: $(HOME_URL)
219 | Send feedback to: $(AUTHOR) <$(EMAIL)>
220
221 License
222 ~~~~~~~
223 Open source, licensed under the $(LICENSE).
224
225 Documentation
226 ~~~~~~~~~~~~~
227 See micoforia.suite.m4. Or build the man page with \"make\" and run
228 \"man -l micoforia.8\".
229
230 Dependencies
231 ~~~~~~~~~~~~
232 This package requires m4, autoconf, gnu make, gcc or clang, and
233 lopsub. The configure script checks if all dependencies are installed
234 and prints a meaningful error message if one of them is missing.
235
236 Building
237 ~~~~~~~~
238 Run \"make\" to build the package with the default settings. Run
239 \"./configure -h\" to list configuration options.
240
241 Installation
242 ~~~~~~~~~~~~
243 Run \"sudo make install\" to install to /usr/local. To install to
244 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
245 first.
246 endef
247
248 README:
249 @printf '%s\n' "$(README)"
250
251 .PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.8
252 .PHONY: all clean install distclean maintainer-clean README
253 -include Makefile.local