diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-04-16 18:43:49 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-04-16 18:58:51 -0400 |
commit | c4c063e9844f2bd2271b2e3391f59f872c66f69a (patch) | |
tree | d09c0852ae24c78e723e425306ae006fae16e076 /config/config.mk | |
parent | 98c539eeda8f9adfd22a3b2b6ece4fe1ca06b3b4 (diff) | |
download | bfs-c4c063e9844f2bd2271b2e3391f59f872c66f69a.tar.xz |
build: Refactor configuration
We now use a recursive make invocation to do the work of `make config`.
The new implementation is also compatible with GNU make 3.81 found on
macOS.
Diffstat (limited to 'config/config.mk')
-rw-r--r-- | config/config.mk | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/config/config.mk b/config/config.mk new file mode 100644 index 0000000..c8d7f19 --- /dev/null +++ b/config/config.mk @@ -0,0 +1,77 @@ +# Copyright © Tavian Barnes <tavianator@tavianator.com> +# SPDX-License-Identifier: 0BSD + +# Makefile fragment that implements `make config` + +include config/prelude.mk +include config/exports.mk + +# Makefile fragments generated by `make config` +MKS := \ + ${GEN}/vars.mk \ + ${GEN}/flags.mk \ + ${GEN}/deps.mk \ + ${GEN}/objs.mk \ + ${GEN}/pkgs.mk + +# The main configuration file, which includes the others +${CONFIG}: ${MKS} + ${MSG} "[ GEN] $@" + @printf '# %s\n' "$@" >$@ + @printf 'include $${GEN}/%s\n' ${.ALLSRC:${GEN}/%=%} >>$@ + ${VCAT} ${CONFIG} +.PHONY: ${CONFIG} + +# Saves the configurable variables +${GEN}/vars.mk:: + @${MKDIR} ${@D} + ${MSG} "[ GEN] $@" + @printf '# %s\n' "$@" >$@ + @printf 'PREFIX := %s\n' "$$XPREFIX" >>$@ + @printf 'MANDIR := %s\n' "$$XMANDIR" >>$@ + @printf 'OS := %s\n' "$${OS:-$$(uname)}" >>$@ + @printf 'ARCH := %s\n' "$${ARCH:-$$(uname -m)}" >>$@ + @printf 'CC := %s\n' "$$XCC" >>$@ + @printf 'INSTALL := %s\n' "$$XINSTALL" >>$@ + @printf 'MKDIR := %s\n' "$$XMKDIR" >>$@ + @printf 'RM := %s\n' "$$XRM" >>$@ + @printf 'PKGS :=\n' >>$@ + ${VCAT} $@ + +# Sets the build flags. This depends on vars.mk and uses a recursive make so +# that the default flags can depend on variables like ${OS}. +${GEN}/flags.mk: ${GEN}/vars.mk + @+${MAKE} -sf config/flags.mk +.PHONY: ${GEN}/flags.mk + +# Check for dependency generation support +${GEN}/deps.mk: ${GEN}/flags.mk + @+${MAKE} -sf config/deps.mk +.PHONY: ${GEN}/deps.mk + +# Lists file.o: file.c dependencies +${GEN}/objs.mk:: + @${MKDIR} ${@D} + ${MSG} "[ GEN] $@" + @printf '# %s\n' "$@" >$@ + @for obj in ${OBJS:${OBJ}/%.o=%}; do printf '$${OBJ}/%s.o: %s.c\n' "$$obj" "$$obj"; done >>$@ + +# External dependencies +PKG_MKS := \ + ${GEN}/libacl.mk \ + ${GEN}/libcap.mk \ + ${GEN}/libselinux.mk \ + ${GEN}/liburing.mk \ + ${GEN}/oniguruma.mk + +# Auto-detect dependencies and their build flags +${GEN}/pkgs.mk: ${PKG_MKS} + @printf '# %s\n' "$@" >$@ + @printf 'include $${GEN}/%s\n' ${.ALLSRC:${GEN}/%=%} >>$@ + @+${MAKE} -sf config/pkgs.mk +.PHONY: ${GEN}/pkgs.mk + +# Auto-detect dependencies +${PKG_MKS}: ${GEN}/flags.mk + @+${MAKE} -sf config/pkg.mk TARGET=$@ +.PHONY: ${PKG_MKS} |