# SPDX-License-Identifier: GPL-2.0-only .SUFFIXES: MAKEFLAGS += -Rr ifeq ("$(origin CC)", "default") CC := cc endif ifeq ("$(origin V)", "command line") SAY = else SAY = @echo '$(strip $(1))' endif PACKAGE := micoforia DEFINES = \ $(call DEFINE,PACKAGE,$(PACKAGE)) \ $(call DEFINE,AUTHOR,Andre Noll) \ $(call DEFINE,COPYRIGHT_YEAR,2019) \ $(call DEFINE,SLOGAN,Minimal Containers for Instant Access) \ $(call DEFINE,EMAIL,maan@tuebingen.mpg.de) \ $(call DEFINE,URL,https://people.tuebingen.mpg.de/maan/$(PACKAGE)/) \ $(call DEFINE,CLONE_URL,https://git.tuebingen.mpg.de/$(PACKAGE)) \ $(call DEFINE,GITWEB_URL,https://git.tuebingen.mpg.de/$(PACKAGE).git) \ $(call DEFINE,HOME_URL,https://people.tuebingen.mpg.de/maan/) \ $(call DEFINE,LICENSE,GNU GPL version 3) \ $(call DEFINE,LICENSE_URL,https://www.gnu.org/licenses/gpl-3.0-standalone.html) DEFINE = -D$(1)='"$(2)"' # LOGLEVELS is special because it is defined unquoted LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG CPP_DEFINES := $(DEFINES) -DLOGLEVELS='$(LOGLEVELS)' DEFINE = -D "$(1)=$(2)" M4_DEFINES := $(DEFINES) .ONESHELL: .SHELLFLAGS := -ec PREFIX ?= /usr/local INSTALL ?= install MKDIR_P := mkdir -p RM := rm -f CHMOD := chmod B := build all := micoforia micoforia.8 all: $(all) www := $(B)/index.html www: $(www) units := micoforia util version micoforia.lsg deps := $(addprefix $(B)/, $(addsuffix .d, $(units))) objs := $(addprefix $(B)/, $(addsuffix .o, $(units))) ifeq ($(findstring clean, $(MAKECMDGOALS)),) -include $(deps) -include $(B)/config.mak endif M4 += $(M4_DEFINES) defs.m4 XCPPFLAGS := $(CPP_DEFINES) -I$(B) -Wunused-macros XCFLAGS := XCFLAGS += -fno-strict-aliasing XCFLAGS += -g XCFLAGS += -Os XCFLAGS += -Wundef -W -Wuninitialized XCFLAGS += -Wchar-subscripts XCFLAGS += -Werror-implicit-function-declaration XCFLAGS += -Wmissing-noreturn XCFLAGS += -Wbad-function-cast XCFLAGS += -Wredundant-decls XCFLAGS += -Wno-sign-compare -Wno-unknown-pragmas XCFLAGS += -Wdeclaration-after-statement XCFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute XCFLAGS += -fsanitize=undefined XCFLAGS += -fdata-sections -ffunction-sections XCFLAGS += -Wstrict-prototypes XCFLAGS += -Wshadow XCFLAGS += -Wunused -Wall XCFLAGS += -Wformat-signedness XCFLAGS += -Wdiscarded-qualifiers XLDFLAGS := -lubsan -Wl,--gc-sections version_file := $(B)/version.c GIT_VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(version_file)) CC_CMD = $(CC) -c -o $@ $(XCPPFLAGS) $(CPPFLAGS) \ $(XCFLAGS) $(CFLAGS) -MMD -MP -MF $(B)/$(*F).d -MT $@ $(objs): m7a.h $(B)/micoforia.lsg.h $(B): @$(MKDIR_P) $@ $(B)/config.h.in: configure.ac | $(B) $(call SAY, AH $<) cd $(B) autoheader -f ../configure.ac $(B)/configure.sh: configure.ac | $(B) $(call SAY, AC $<) cd $(B) autoconf ../configure.ac > configure.sh $(CHMOD) 755 configure.sh $(B)/config.status: $(B)/configure.sh | $(B) $(call SAY, SH $<) cd $(B) if test -x config.status; then \ ./config.status --quiet --recheck; \ else \ ./configure.sh --no-create; \ fi $(B)/config.mak $(B)/config.h: $(B)/config.status config.mak.in $(B)/config.h.in $(call SAY, CS $@) cd $(B) ln -f ../config.mak.in ./config.status -q test -f config.h && touch config.h $(B)/index.html $(B)/micoforia.suite: $(B)/%: %.m4 Makefile $(B)/config.mak $(call SAY, M4 $<) $(M4) $< > $@ $(B)/%.lsg.c: $(B)/%.suite $(call SAY, LSGC $<) $(LOPSUBGEN) --gen-c --output-dir $(B) < $< $(B)/%.lsg.h: $(B)/%.suite $(call SAY, LSGH $<) $(LOPSUBGEN) --gen-header --output-dir $(B) < $< %.8: $(B)/%.suite $(B)/version.c $(call SAY, LSGM $<) $(LOPSUBGEN) --gen-man=$(*F).8 --version-string $(GIT_VERSION) < $< $(B)/%.o: %.c | $(B) $(call SAY, CC $<) $(CC_CMD) $< $(B)/%.o: $(B)/%.c $(call SAY, CC $<) $(CC_CMD) $< micoforia: $(objs) $(call SAY, LD $@) $(CC) -o $@ $^ $(XLDFLAGS) $(LDFLAGS) -llopsub -lmnl -lutil -lcap mandir := $(datarootdir)/man/man8 INSTALL ?= install INSTALL_PROGRAM ?= $(INSTALL) -m 755 INSTALL_DATA ?= $(INSTALL) -m 644 ifneq ($(findstring strip, $(MAKECMDGOALS)),) strip_option := -s endif install install-strip: all $(MKDIR_P) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir) $(INSTALL_PROGRAM) $(strip_option) micoforia $(DESTDIR)$(sbindir) $(INSTALL_DATA) micoforia.8 $(DESTDIR)$(mandir) clean: $(RM) $(B)/*.o $(all) $(www) distclean: clean $(RM) -r $(B) maintainer-clean: git clean -dfqx > /dev/null 2>&1 README: README.m4 Makefile $(B)/config.mak @$(M4) $< .PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.8 .PHONY: all www clean install distclean maintainer-clean README -include Makefile.local