From 1ea7da67c3186119551ff88c5c6b05de05393ce0 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 23 Mar 2024 02:35:32 +0100 Subject: make: config based example --- src/development/make.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/development/make.md b/src/development/make.md index 254a7d7..fdef47e 100644 --- a/src/development/make.md +++ b/src/development/make.md @@ -137,5 +137,40 @@ Resolve each file name as canonical path. $(realpath fname1 fname2 ..) ``` +## Examples + +### Config based settings +```make +conf-y := default +conf-$(FOO) := $(conf-y) foo +conf-$(BAR) := $(conf-y) bar + +libs-y := libdef +libs-$(FOO) += libfoo +libs-$(BAR) += libbar + +all: + @echo "conf-y: $(conf-y)" + @echo "libs-y: $(libs-y)" +``` +Yields the following results. +```sh +$ make +conf-y: default +libs-y: libdef + +$ make FOO=y +conf-y: default foo +libs-y: libdef libfoo + +$ make BAR=y +conf-y: default bar +libs-y: libdef libbar + +$ make FOO=y BAR=y +conf-y: default foo bar +libs-y: libdef libfoo libbar +``` + [make-var-override]: https://www.gnu.org/software/make/manual/html_node/Overriding.html [make-patsubst]: https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#index-patsubst-1 -- cgit v1.2.3