]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - Makefile
Makefile: CFLAGS: Don't trigger errors for some warnings
[thirdparty/man-pages.git] / Makefile
index 84f06c0d29e114533014420b6edf75f2c9603928..cea48edae41cc60f6ff8652350971d9fb2efca8d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,9 @@
 #
 ########################################################################
 
+SHELL := /bin/bash -Eeuo pipefail
+
+
 MAKEFLAGS += --no-print-directory
 MAKEFLAGS += --warn-undefined-variables
 
@@ -85,6 +88,18 @@ _mandir     := $(DESTDIR)$(mandir)
 _htmldir    := $(DESTDIR)$(htmldir_)
 
 
+clang-tidy_config       := $(SYSCONFDIR)/clang-tidy/config.yaml
+DEFAULT_CLANG-TIDYFLAGS := --config-file=$(clang-tidy_config)
+DEFAULT_CLANG-TIDYFLAGS += --quiet
+DEFAULT_CLANG-TIDYFLAGS += --use-color
+EXTRA_CLANG-TIDYFLAGS   :=
+CLANG-TIDYFLAGS         := $(DEFAULT_CLANG-TIDYFLAGS) $(EXTRA_CLANG-TIDYFLAGS)
+
+DEFAULT_IWYUFLAGS := -Xiwyu --no_fwd_decls
+DEFAULT_IWYUFLAGS += -Xiwyu --error
+EXTRA_IWYUFLAGS   :=
+IWYUFLAGS         := $(DEFAULT_IWYUFLAGS) $(EXTRA_IWYUFLAGS)
+
 DEFAULT_CPPFLAGS :=
 EXTRA_CPPFLAGS   :=
 CPPFLAGS         := $(DEFAULT_CPPFLAGS) $(EXTRA_CPPFLAGS)
@@ -94,6 +109,10 @@ DEFAULT_CFLAGS += -Wall
 DEFAULT_CFLAGS += -Wextra
 DEAFULT_CFLAGS += -Wstrict-prototypes
 DEFAULT_CFLAGS += -Werror
+DEFAULT_CFLAGS += -Wno-error=unused-parameter
+DEFAULT_CFLAGS += -Wno-error=sign-compare
+DEFAULT_CFLAGS += -Wno-error=format
+DEFAULT_CFLAGS += -Wno-error=uninitialized
 EXTRA_CFLAGS   :=
 CFLAGS         := $(DEFAULT_CFLAGS) $(EXTRA_CFLAGS)
 
@@ -136,6 +155,8 @@ INSTALL_DIR  := $(INSTALL) -m 755 -d
 MKDIR        := mkdir -p
 RM           := rm
 RMDIR        := rmdir --ignore-fail-on-non-empty
+CLANG-TIDY   := clang-tidy
+IWYU         := iwyu
 CC           := cc
 LD           := $(CC) $(CFLAGS)
 GROFF        := groff
@@ -203,16 +224,20 @@ _man8pages  := $(filter %$(man8ext),$(_manpages))
 _LINT_groff :=$(patsubst $(MANDIR)/%,$(_LINTDIR)/%.lint.groff.touch,$(LINTMAN))
 _LINT_mandoc:=$(patsubst $(MANDIR)/%,$(_LINTDIR)/%.lint.mandoc.touch,$(LINTMAN))
 _SRCPAGEDIRS:=$(patsubst $(MANDIR)/%,$(_SRCDIR)/%.d,$(LINTMAN))
-_UNITS_c    :=$(sort $(patsubst $(MANDIR)/%,$(_SRCDIR)/%,$(shell \
+_UNITS_src  :=$(sort $(patsubst $(MANDIR)/%,$(_SRCDIR)/%,$(shell \
                find $(MANDIR)/man?/ -type f \
                | grep '$(manext)$$' \
                | xargs grep -l '^\.TH ' \
                | while read m; do \
                        <$$m \
-                       sed -n "s,^\... SRC BEGIN (\(.*.c\))$$,$$m.d/\1,p"; \
+                       sed -n "s,^\... SRC BEGIN (\(.*.[ch]\))$$,$$m.d/\1,p"; \
                done)))
+_UNITS_h    := $(filter %.h,$(_UNITS_src))
+_UNITS_c    := $(filter %.c,$(_UNITS_src))
 _UNITS_o    := $(patsubst %.c,%.o,$(_UNITS_c))
 _UNITS_bin  := $(patsubst %.c,%,$(_UNITS_c))
+_LINT_clang-tidy := $(patsubst %.c,%.lint.clang-tidy.touch,$(_UNITS_c))
+_LINT_iwyu       := $(patsubst %.c,%.lint.iwyu.touch,$(_UNITS_c))
 
 MANDIRS   := $(sort $(shell find $(MANDIR)/man? -type d))
 _HTMLDIRS  := $(patsubst $(MANDIR)/%,$(_HTMLDIR)/%/.,$(MANDIRS))
@@ -305,9 +330,11 @@ $(_SRCPAGEDIRS): $(_SRCDIR)/%.d: $(MANDIR)/% | $$(@D)/.
        $(MKDIR) $@
        touch $@
 
-$(_UNITS_c): $$(@D)
+$(_UNITS_src): $$(patsubst $(_SRCDIR)/%.d,$(MANDIR)/%,$$(@D)) | $$(@D)
+$(_UNITS_c):   $$(filter $$(@D)/%.h,$(_UNITS_h))
+$(_UNITS_src):
        $(info SED      $@)
-       <$(patsubst $(_SRCDIR)/%.d,$(MANDIR)/%,$<) \
+       <$< \
        sed -n \
                -e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
                -e '/^\.SH EXAMPLES/p' \
@@ -315,8 +342,7 @@ $(_UNITS_c): $$(@D)
        | $(MAN) -P cat -l - \
        | sed '/^[^ ]/d' \
        | sed 's/^       //' \
-       >$@ \
-       || exit $$?
+       >$@
 
 $(_UNITS_o): $(_SRCDIR)/%.o: $(_SRCDIR)/%.c
        $(info CC       $@)
@@ -349,9 +375,20 @@ builddirs-src: $(_SRCDIRS)
 ########################################################################
 # lint
 
-linters := groff mandoc
+linters := clang-tidy iwyu groff mandoc
 lint    := $(foreach x,$(linters),lint-$(x))
 
+$(_LINT_clang-tidy): %.lint.clang-tidy.touch: %.c
+       $(info LINT (clang-tidy)        $@)
+       $(CLANG-TIDY) $(CLANG-TIDYFLAGS) $< -- $(CPPFLAGS) $(CFLAGS) 2>&1 \
+       | sed '/generated\.$$/d'
+       touch $@
+
+$(_LINT_iwyu): %.lint.iwyu.touch: %.c
+       $(info LINT (iwyu)      $@)
+       $(IWYU) $(IWYUFLAGS) $(CPPFLAGS) $(CFLAGS) $<
+       touch $@
+
 $(_LINT_groff): $(_LINTDIR)/%.lint.groff.touch: $(MANDIR)/% | $$(@D)/.
        $(info LINT (groff)     $@)
        $(GROFF) $(GROFFFLAGS) -z $<
@@ -370,7 +407,7 @@ $(lint): lint-%: $$(_LINT_%) | lintdirs
        @:
 
 .PHONY: lintdirs
-lintdirs: $(_LINTDIRS)
+lintdirs: $(_LINTDIRS) $(_SRCDIRS)
        @:
 
 .PHONY: lint
@@ -386,7 +423,7 @@ lint: $(lint)
 # The sed removes the lines "Content-type: text/html\n\n"
 $(_HTMLPAGES): $(_HTMLDIR)/%.html: $(MANDIR)/% | $$(@D)/.
        $(info MAN2HTML $@)
-       $(MAN2HTML) $(MAN2HTMLFLAGS) $< | sed -e 1,2d >$@ || exit $$?
+       $(MAN2HTML) $(MAN2HTMLFLAGS) $< | sed -e 1,2d >$@
 
 $(_HTMLDIRS): %/.: | $$(dir %). $(_HTMLDIR)/.