mirror of
https://git.sr.ht/~nabijaczleweli/tzpfms
synced 2025-04-13 09:37:13 +03:00
Simplify Makefile, make it correcter and more canonical
This commit is contained in:
parent
c727114dce
commit
8e02233ad5
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,7 +5,7 @@
|
|||||||
!.travis.yml
|
!.travis.yml
|
||||||
!gh_rsa.enc
|
!gh_rsa.enc
|
||||||
!.clang-format
|
!.clang-format
|
||||||
!*Makefile
|
!Makefile
|
||||||
!*.sublime-project
|
!*.sublime-project
|
||||||
!*.md
|
!*.md
|
||||||
!*.awk
|
!*.awk
|
||||||
|
80
Makefile
80
Makefile
@ -1,22 +1,40 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
|
||||||
include configMakefile
|
-include Makefile.local
|
||||||
|
|
||||||
|
|
||||||
|
TZPFMS_VERSION ?= "$(patsubst v%,%,$(shell git describe))"
|
||||||
|
TZPFMS_DATE ?= $(shell date -d@$$(git log --no-show-signature -1 --pretty=%at) '+%B %e, %Y')
|
||||||
|
|
||||||
|
AWK ?= awk
|
||||||
|
SED ?= sed
|
||||||
|
MANDOC ?= mandoc
|
||||||
|
PKGCONF ?= pkgconf
|
||||||
|
SHELLCHECK ?= shellcheck
|
||||||
|
OUTDIR ?= out/
|
||||||
|
BLDDIR ?= out/build/
|
||||||
|
|
||||||
|
SYSTEMD_SYSTEM_UNITDIR := $(shell $(PKGCONF) --variable=systemd_system_unit_dir systemd 2>/dev/null || echo /usr/lib/systemd/system)
|
||||||
|
|
||||||
|
|
||||||
LDDLLS := rt tspi crypto
|
|
||||||
PKGS := libzfs libzfs_core tss2-esys tss2-rc
|
PKGS := libzfs libzfs_core tss2-esys tss2-rc
|
||||||
LDAR := $(LNCXXAR) $(foreach l,,-L$(BLDDIR)$(l)) $(foreach dll,$(LDDLLS),-l$(dll)) $(shell pkg-config --libs $(PKGS))
|
PKGCONF_LIBS := $(shell pkg-config --libs $(PKGS))
|
||||||
INCAR := $(foreach l,$(foreach l,,$(l)/include),-isystemext/$(l)) $(foreach l,,-isystem$(BLDDIR)$(l)/include) $(shell pkg-config --cflags $(PKGS))
|
PKGCONF_CFLAGS := $(shell pkg-config --cflags $(PKGS))
|
||||||
VERAR := $(foreach l,TZPFMS,-D$(l)_VERSION='$($(l)_VERSION)')
|
|
||||||
BINARY_SOURCES := $(sort $(wildcard $(SRCDIR)bin/*.cpp $(SRCDIR)bin/**/*.cpp))
|
LDFLAGS += -Wl,--as-needed
|
||||||
COMMON_SOURCES := $(filter-out $(BINARY_SOURCES),$(sort $(wildcard $(SRCDIR)*.cpp $(SRCDIR)**/*.cpp $(SRCDIR)**/**/*.cpp $(SRCDIR)**/**/**/*.cpp)))
|
LDLIBS += -lrt -ltspi -lcrypto $(PKGCONF_LIBS)
|
||||||
MANPAGE_HEADERS := $(sort $(wildcard $(MANDIR)*.h))
|
CXXFLAGS += -g -O3 -std=c++17 -fno-exceptions -fno-rtti -Wall -Wextra -pipe -fPIC $(PKGCONF_CFLAGS)
|
||||||
MANPAGE_SOURCES := $(sort $(wildcard $(MANDIR)*.[012345678].pp))
|
CPPFLAGS += -DTZPFMS_VERSION='$(TZPFMS_VERSION)'
|
||||||
INITRD_HEADERS := $(sort $(wildcard $(INITRDDIR)*.h))
|
BINARY_SOURCES := $(sort $(wildcard src/bin/*.cpp src/bin/**/*.cpp))
|
||||||
|
COMMON_SOURCES := $(filter-out $(BINARY_SOURCES),$(sort $(wildcard src/*.cpp src/**/*.cpp src/**/**/*.cpp src/**/**/**/*.cpp)))
|
||||||
|
MANPAGE_HEADERS := $(sort $(wildcard man/*.h))
|
||||||
|
MANPAGE_SOURCES := $(sort $(wildcard man/*.[0-8].pp))
|
||||||
|
INITRD_HEADERS := $(sort $(wildcard initrd/*.h))
|
||||||
|
|
||||||
|
|
||||||
ifdef TZPFMS_PASSPHRASE_HELPER
|
ifdef TZPFMS_PASSPHRASE_HELPER
|
||||||
DEF_TPH := -DTZPFMS_PASSPHRASE_HELPER='$(TZPFMS_PASSPHRASE_HELPER)'
|
CPPFLAGS += -DTZPFMS_PASSPHRASE_HELPER='$(TZPFMS_PASSPHRASE_HELPER)'
|
||||||
endif
|
endif
|
||||||
ifdef TZPFMS_PASSPHRASE_HELPER_MAN
|
ifdef TZPFMS_PASSPHRASE_HELPER_MAN
|
||||||
DEF_TPH_MAN := .Pp\nDefault:\n.No '\'' Ns $(TZPFMS_PASSPHRASE_HELPER_MAN) Ns '\'' .
|
DEF_TPH_MAN := .Pp\nDefault:\n.No '\'' Ns $(TZPFMS_PASSPHRASE_HELPER_MAN) Ns '\'' .
|
||||||
@ -24,6 +42,20 @@ else
|
|||||||
DEF_TPH_MAN ?= .
|
DEF_TPH_MAN ?= .
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
ifneq "$(findstring clang,$(shell $(CXX) --version))" ""
|
||||||
|
# GCC doesn't have this granularity
|
||||||
|
CXXFLAGS += -flto=full -pedantic -Wno-gnu-statement-expression -Wno-gnu-include-next -Wno-gnu-conditional-omitted-operand -Wno-c++20-designator
|
||||||
|
ifeq "$(AR)" "ar"
|
||||||
|
# Need this because -flto=full produces objects FSF ranlib (ar s) can't index
|
||||||
|
override AR := llvm-ar
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -flto
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY : all clean build shellcheck i-t dracut init.d-systemd manpages htmlpages
|
.PHONY : all clean build shellcheck i-t dracut init.d-systemd manpages htmlpages
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
|
|
||||||
@ -36,20 +68,20 @@ shellcheck : i-t dracut
|
|||||||
clean :
|
clean :
|
||||||
rm -rf $(OUTDIR)
|
rm -rf $(OUTDIR)
|
||||||
|
|
||||||
build : $(subst $(SRCDIR)bin/,$(OUTDIR),$(subst .cpp,,$(BINARY_SOURCES)))
|
build : $(subst src/bin/,$(OUTDIR),$(subst .cpp,,$(BINARY_SOURCES)))
|
||||||
manpages : $(patsubst $(MANDIR)%.pp,$(OUTDIR)man/%,$(MANPAGE_SOURCES))
|
manpages : $(patsubst man/%.pp,$(OUTDIR)man/%,$(MANPAGE_SOURCES))
|
||||||
htmlpages : $(patsubst $(MANDIR)%.pp,$(OUTDIR)man/%.html,$(MANPAGE_SOURCES)) $(OUTDIR)man/style.css
|
htmlpages : $(patsubst man/%.pp,$(OUTDIR)man/%.html,$(MANPAGE_SOURCES)) $(OUTDIR)man/style.css
|
||||||
i-t : $(OUTDIR)initramfs-tools/usr/share/initramfs-tools/hooks/tzpfms $(OUTDIR)initramfs-tools/usr/share/tzpfms/initramfs-tools-zfs-patch.sh
|
i-t : $(OUTDIR)initramfs-tools/usr/share/initramfs-tools/hooks/tzpfms $(OUTDIR)initramfs-tools/usr/share/tzpfms/initramfs-tools-zfs-patch.sh
|
||||||
dracut : $(patsubst $(INITRDDIR)dracut/%,$(OUTDIR)dracut/usr/lib/dracut/modules.d/91tzpfms/%,$(sort $(wildcard $(INITRDDIR)dracut/*.sh)))
|
dracut : $(patsubst initrd/dracut/%,$(OUTDIR)dracut/usr/lib/dracut/modules.d/91tzpfms/%,$(sort $(wildcard initrd/dracut/*.sh)))
|
||||||
init.d-systemd : $(OUTDIR)systemd/$(SYSTEMD_SYSTEM_UNITDIR)/zfs-load-key@.service.d/tzpfms.conf $(OUTDIR)systemd/usr/libexec/tzpfms-zfs-load-key@
|
init.d-systemd : $(OUTDIR)systemd/$(SYSTEMD_SYSTEM_UNITDIR)/zfs-load-key@.service.d/tzpfms.conf $(OUTDIR)systemd/usr/libexec/tzpfms-zfs-load-key@
|
||||||
|
|
||||||
|
|
||||||
$(OUTDIR)initramfs-tools/usr/share/initramfs-tools/hooks/tzpfms: $(INITRDDIR)initramfs-tools/hook $(INITRD_HEADERS)
|
$(OUTDIR)initramfs-tools/usr/share/initramfs-tools/hooks/tzpfms: initrd/initramfs-tools/hook $(INITRD_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(AWK) -f pp.awk $< > $@
|
$(AWK) -f pp.awk $< > $@
|
||||||
chmod --reference $< $@
|
chmod --reference $< $@
|
||||||
|
|
||||||
$(OUTDIR)initramfs-tools/usr/share/tzpfms/initramfs-tools-zfs-patch.sh: $(INITRDDIR)initramfs-tools/zfs-patch.sh $(INITRD_HEADERS)
|
$(OUTDIR)initramfs-tools/usr/share/tzpfms/initramfs-tools-zfs-patch.sh: initrd/initramfs-tools/zfs-patch.sh $(INITRD_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(AWK) -f pp.awk $< > $@
|
$(AWK) -f pp.awk $< > $@
|
||||||
chmod --reference $< $@
|
chmod --reference $< $@
|
||||||
@ -64,7 +96,7 @@ $(OUTDIR)systemd/usr/libexec/tzpfms-zfs-load-key@ : init.d/systemd/libexec-tzpfm
|
|||||||
|
|
||||||
# The d-v-o-s string starts at "BSD" (hence the "BSD General Commands Manual" default); we're not BSD, so hide it
|
# The d-v-o-s string starts at "BSD" (hence the "BSD General Commands Manual" default); we're not BSD, so hide it
|
||||||
# Can't put it at the very top, since man(1) only loads mdoc *after* the first mdoc macro (.Dd in our case)
|
# Can't put it at the very top, since man(1) only loads mdoc *after* the first mdoc macro (.Dd in our case)
|
||||||
$(OUTDIR)man/% : $(MANDIR)%.pp $(MANPAGE_HEADERS)
|
$(OUTDIR)man/% : man/%.pp $(MANPAGE_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(AWK) -f pp.awk $< TZPFMS_PASSPHRASE_HELPER_MAN='$(DEF_TPH_MAN)' | $(AWK) '/^$$/ {prev_empty=1; next} $$1 == "#" && $$2 ~ /^[0-9]*$$/ {prev_empty=0; next} {if(prev_empty) print ""; prev_empty=0; print}' | $(AWK) '$$0 == ".Dd" {$$2 = "$(TZPFMS_DATE)"} $$1 == ".Dt" { print ".ds doc-volume-operating-system" } $$0 == ".Os" {$$2 = "tzpfms"; $$3 = $(TZPFMS_VERSION)} {print}' > $@
|
$(AWK) -f pp.awk $< TZPFMS_PASSPHRASE_HELPER_MAN='$(DEF_TPH_MAN)' | $(AWK) '/^$$/ {prev_empty=1; next} $$1 == "#" && $$2 ~ /^[0-9]*$$/ {prev_empty=0; next} {if(prev_empty) print ""; prev_empty=0; print}' | $(AWK) '$$0 == ".Dd" {$$2 = "$(TZPFMS_DATE)"} $$1 == ".Dt" { print ".ds doc-volume-operating-system" } $$0 == ".Os" {$$2 = "tzpfms"; $$3 = $(TZPFMS_VERSION)} {print}' > $@
|
||||||
! $(MANDOC) -Tlint $@ 2>&1 | grep -vE -e 'mandoc: outdated mandoc.db' -e 'STYLE: referenced manual not found' -e 'STYLE: operating system explicitly specified: Os tzpfms' -e 'WARNING: cross reference to self: Xr zfs-tpm.*-change-key 8' -e 'STYLE: input text line longer than 80 bytes'
|
! $(MANDOC) -Tlint $@ 2>&1 | grep -vE -e 'mandoc: outdated mandoc.db' -e 'STYLE: referenced manual not found' -e 'STYLE: operating system explicitly specified: Os tzpfms' -e 'WARNING: cross reference to self: Xr zfs-tpm.*-change-key 8' -e 'STYLE: input text line longer than 80 bytes'
|
||||||
@ -80,19 +112,19 @@ $(OUTDIR)man/style.css : man/style.css
|
|||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
cp $^ $@
|
cp $^ $@
|
||||||
|
|
||||||
$(BLDDIR)libtzpfms.a : $(subst $(SRCDIR),$(OBJDIR),$(subst .cpp,.o,$(COMMON_SOURCES)))
|
$(BLDDIR)libtzpfms.a : $(subst src/,$(BLDDIR)obj/,$(subst .cpp,.o,$(COMMON_SOURCES)))
|
||||||
$(AR) crs $@ $^
|
$(AR) crs $@ $^
|
||||||
|
|
||||||
|
|
||||||
$(OUTDIR)% : $(OBJDIR)bin/%.o $(BLDDIR)libtzpfms.a
|
$(OUTDIR)% : $(BLDDIR)obj/bin/%.o $(BLDDIR)libtzpfms.a
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CXX) $(CXXAR) -Wl,--as-needed -o$@ $^ $(LDAR)
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||||
|
|
||||||
$(OBJDIR)%.o : $(SRCDIR)%.cpp
|
$(BLDDIR)obj/%.o : src/%.cpp
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CXX) $(CXXAR) $(INCAR) $(VERAR) $(DEF_TPH) -c -o$@ $^
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OUTDIR)dracut/usr/lib/dracut/modules.d/91tzpfms/% : $(INITRDDIR)dracut/% $(INITRD_HEADERS)
|
$(OUTDIR)dracut/usr/lib/dracut/modules.d/91tzpfms/% : initrd/dracut/% $(INITRD_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(AWK) -f pp.awk $< > $@
|
$(AWK) -f pp.awk $< > $@
|
||||||
chmod --reference $< $@
|
chmod --reference $< $@
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
|
|
||||||
CXXVER := $(shell $(CXX) --version)
|
|
||||||
ifneq "$(findstring clang,$(CXXVER))" ""
|
|
||||||
# GCC doesn't have this granularity
|
|
||||||
CXXSPECIFIC := -flto=full -pedantic -Wno-gnu-statement-expression -Wno-gnu-include-next -Wno-gnu-conditional-omitted-operand -Wno-c++20-designator
|
|
||||||
ifeq "$(AR)" "ar"
|
|
||||||
# Need this because -flto=full produces objects FSF ranlib (ar s) can't index
|
|
||||||
override AR := llvm-ar
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
CXXSPECIFIC := -flto
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
ifneq "$(ADDITIONAL_INCLUDE_DIR)" ""
|
|
||||||
INCCXXAR := -isystem$(ADDITIONAL_INCLUDE_DIR)
|
|
||||||
else
|
|
||||||
INCCXXAR :=
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq "$(ADDITIONAL_LINK_DIR)" ""
|
|
||||||
LNCXXAR := -L$(ADDITIONAL_LINK_DIR)
|
|
||||||
else
|
|
||||||
LNCXXAR :=
|
|
||||||
endif
|
|
||||||
|
|
||||||
TZPFMS_VERSION ?= "$(patsubst v%,%,$(shell git describe))"
|
|
||||||
TZPFMS_DATE ?= $(shell date -d@$$(git log --no-show-signature -1 --pretty=%at) '+%B %e, %Y')
|
|
||||||
|
|
||||||
SYSTEMD_SYSTEM_UNITDIR := $(shell ssud="$$(pkg-config --variable=systemd_system_unit_dir systemd 2>/dev/null)"; echo "$${ssud:-/usr/lib/systemd/system}")
|
|
||||||
|
|
||||||
INCCMAKEAR := CXXFLAGS="$(INCCXXAR)"
|
|
||||||
LNCMAKEAR := LDFLAGS="$(LNCXXAR)"
|
|
||||||
|
|
||||||
AWK ?= awk
|
|
||||||
SED ?= sed
|
|
||||||
MANDOC ?= mandoc
|
|
||||||
SHELLCHECK ?= shellcheck
|
|
||||||
CXXAR := -g -O3 -std=c++17 -fno-exceptions -Wall -Wextra $(CXXSPECIFIC) -pipe $(INCCXXAR) -fPIC
|
|
||||||
|
|
||||||
OUTDIR := out/
|
|
||||||
BLDDIR := out/build/
|
|
||||||
OBJDIR := $(BLDDIR)obj/
|
|
||||||
SRCDIR := src/
|
|
||||||
MANDIR := man/
|
|
||||||
INITRDDIR := initrd/
|
|
@ -49,7 +49,7 @@
|
|||||||
"follow_symlinks": true,
|
"follow_symlinks": true,
|
||||||
"name": "Build scripts",
|
"name": "Build scripts",
|
||||||
"path": ".",
|
"path": ".",
|
||||||
"file_include_patterns": [".build.yml", "*Makefile", "*.awk"],
|
"file_include_patterns": [".build.yml", "*Makefile*", "*.awk"],
|
||||||
"folder_exclude_patterns": ["*"]
|
"folder_exclude_patterns": ["*"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user