### Build and install bmakelib from source Source: https://github.com/bahmanm/bmakelib/blob/main/doc/system-wide-installation.md Builds and installs bmakelib from source. Requires git, make, and sudo privileges. The PREFIX variable sets the installation prefix. ```bash git clone https://github.com/bahmanm/bmakelib.git cd bmakelib sudo make install PREFIX=/usr/local ``` -------------------------------- ### Install bmakelib via Homebrew Source: https://github.com/bahmanm/bmakelib/blob/main/doc/system-wide-installation.md Installs bmakelib system-wide on macOS and Linux using Homebrew. Requires Homebrew to be installed and configured. ```bash brew update brew tap bahmanm/bmakelib brew install bmakelib ``` -------------------------------- ### Notes: Quoting examples for bmakelib.shell.error-if-nonzero Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Examples from the notes section showing how to quad-quote shell variables and structures when using bmakelib.shell.error-if-nonzero. ```makefile $(call bmakelib.shell.error-if-nonzero,echo $$$$HOSTNAME) ``` ```makefile $(call bmakelib.shell.error-if-nonzero,PATH="/usr/local/foo/bin:$$$$PATH" foo $$$$(date)) ``` -------------------------------- ### Bootstrap snippet for bmakelib in Makefile Source: https://github.com/bahmanm/bmakelib/blob/main/doc/index.md Zero-installation snippet to download, install, and include bmakelib. It fetches the latest version by default, installs to ./bmakelib/ (or BMAKELIB_DIR), and uses the local cache on subsequent runs. Pin the version with BMAKELIB_VERSION and reset by deleting BMAKELIB_DIR. ```makefile ###################### bmakelib: download, install and include. -include $(or $(BMAKELIB_DIR),$(PWD)/.bmakelib)/bmakelib.mk $(or $(BMAKELIB_DIR),$(PWD)/.bmakelib)/bmakelib.mk: @mkdir -p $(@D) @curl -fsSL https://github.com/bahmanm/bmakelib/releases/$(if $(BMAKELIB_VERSION),download/$(BMAKELIB_VERSION),latest/download)/bmakelib-portable.tar.gz \ | tar -xz -C $(@D) --strip-components=3 ###################### bmakelib: done build: bmakelib.error-if-blank( ENVIRONMENT ) ## Build application artefacts build: @echo "Building for $(ENVIRONMENT)..." ``` -------------------------------- ### Install bmakelib DEB package on Debian/Ubuntu Source: https://github.com/bahmanm/bmakelib/blob/main/doc/system-wide-installation.md Downloads and installs the Debian package for Debian/Ubuntu systems. Requires wget and sudo privileges. ```bash wget https://github.com/bahmanm/bmakelib/releases/download/v0.9.1/bmakelib_0.9.1-1_all.deb sudo dpkg -i bmakelib_0.9.1-1_all.deb ``` -------------------------------- ### Install bmakelib RPM package on RHEL/Fedora/CentOS Source: https://github.com/bahmanm/bmakelib/blob/main/doc/system-wide-installation.md Downloads and installs the RPM package for RHEL/Fedora/CentOS systems. Requires wget and sudo privileges. ```bash wget https://github.com/bahmanm/bmakelib/releases/download/v0.9.1/bmakelib-0.9.1-1.1.noarch.rpm sudo rpm -i bmakelib-0.9.1-1.1.noarch.rpm ``` -------------------------------- ### Example 3: Using bmakelib.shell.error-if-nonzero with docker and conditional commands Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Shows usage with docker run and a conditional shell command that checks JAVA_HOME. The output shows the results of both commands. ```makefile VAR1 := $(call bmakelib.shell.error-if-nonzero,\ docker run --rm ubuntu:22.04 echo Hello, world. && echo Goodbye, world.) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero,\ [[ ! -z $$$$JAVA_HOME ]] \ && ls $$$$JAVA_HOME/bin/java \ || echo JAVA_HOME not set.) some-target : @echo 👉 VAR1=$(VAR1) @echo 👉 VAR2=$(VAR2) ``` ```text $ make some-target 👉 VAR1=Hello, world. Goodbye, world. 👉 VAR2=/home/bahman/.sdkman/candidates/java/current/bin/java ``` -------------------------------- ### Upgrade GNU Make from source Source: https://github.com/bahmanm/bmakelib/blob/main/README.md Download, compile, and install GNU Make 4.4.1 from source when the system's version is older than 4.4. ```bash wget https://mirrors.kernel.org/gnu/make/make-4.4.1.tar.gz tar xzf make-4.4.1.tar.gz cd make-4.4.1 ./configure --prefix=/usr/local make sudo make install ``` -------------------------------- ### Include bmakelib in Makefile for global installation Source: https://github.com/bahmanm/bmakelib/blob/main/doc/system-wide-installation.md Includes bmakelib in a Makefile when installed globally to standard locations such as /usr/local or /usr. ```makefile include bmakelib/bmakelib.mk ``` -------------------------------- ### Makefile: Define target for second example Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Defines a make target 'some-target' that echoes a different message. Used with bmakelib.logged and configuration variables to suppress output. ```makefile some-target : @echo 🤖 Done this and that. ``` -------------------------------- ### Use bmakelib.dict macros to build library and executable Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Shows the macro form of bmakelib.dict.define, put, and get to build a library and executable. Defines LIBCONF and EXECONF dictionaries, retrieves values into EXE and LIB, and uses them in targets and recipes. ```Makefile $(call bmakelib.dict.define,LIBCONF) $(call bmakelib.dict.put,LIBCONF,lib-name,libhello.a) $(call bmakelib.dict.put,LIBCONF,lib-objs,hello_impl.o) $(call bmakelib.dict.define,EXECONF) $(call bmakelib.dict.put,EXECONF,exe-name,hello) $(call bmakelib.dict.put,EXECONF,exe-objs,hello_main.o) EXE := $(call bmakelib.dict.get,EXECONF,exe-name) LIB := $(call bmakelib.dict.get,LIBCONF,lib-name) .PHONY : all all : $(EXE) $(EXE) : $(call bmakelib.dict.get,EXECONF,exe-objs) $(LIB) $(CC) $(CFLAGS) -o $@ $^ $(LIB) : $(call bmakelib.dict.get,LIBCONF,lib-objs) $(AR) $(ARFLAGS) $@ $^ ``` -------------------------------- ### Example 2: Using bmakelib.shell.error-if-nonzero with shell variables and commands Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Shows usage with shell variables and commands, including whoami, perl, and emacs. The output demonstrates the expanded values. Note the use of quad-quoting for shell variables. ```makefile VAR1 := $(call bmakelib.shell.error-if-nonzero,\ echo 🧑 $$$$(whoami) 💻 $$$$(perl -nE'say $$$$1 if /^ID="(.+)"$$$$/' < /etc/os-release)) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero,emacs --version | head -n 1) some-target : @echo VAR1=$(VAR1) @echo VAR2=$(VAR2) ``` ```text $ make some-target 👉 VAR1=🧑 bahman 💻 opensuse-tumbleweed 👉 VAR2=GNU Emacs 29.1 ``` -------------------------------- ### Define enums using variable (macro) (Example 1) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines the same enums as the target dependency example, but using the variable (macro) variation. This is an alternative style that produces the same result. ```Makefile $(call bmakelib.enum.define,DaysOfWeek/SUN,MON,TUE,WED,THU,FRI,SAT) $(call bmakelib.enum.define,DISTRO/openSUSE,Debian,Fedora) ``` -------------------------------- ### Verify GNU Make version with make -v Source: https://github.com/bahmanm/bmakelib/blob/main/README.md Check the installed GNU Make version to ensure it meets the 4.4+ requirement. ```bash make -v ``` -------------------------------- ### Example 1: Basic usage of bmakelib.shell.error-if-nonzero in Makefile Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Shows basic usage of bmakelib.shell.error-if-nonzero in a Makefile. The first call fails immediately, causing the recipe to be unreachable. The second call is used as a target-specific variable. The shell output shows the error message when the command fails. ```makefile VAR1 := $(call bmakelib.shell.error-if-nonzero, echo Kaboom! 💣 && false) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero, echo Hello, world) some-target : @echo Unreachable recipe ⛔ ``` ```text $ make some-target Makefile:4: *** bmakelib.shell: Command exited with non-zero value 1. Stop. ``` -------------------------------- ### Verify enum membership with error-unless-member (Example 1) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines an enum DEPLOY-ENV and uses bmakelib.enum.error-unless-member to check the ENV variable. The shell output shows the failure and success cases. ```Makefile $(call bmakelib.enum.define,DEPLOY-ENV/development,staging,production) deploy : bmakelib.enum.error-unless-member( DEPLOY-ENV,ENV ) deploy : @echo 🚀 Deploying to $(ENV)... ``` ```text $ make ENV=local-laptop deploy *** 'local-laptop' is not a member of enum 'DEPLOY-ENV'. Stop. $ make ENV=production deploy 🚀 Deploying to production... ``` -------------------------------- ### Define enum using variable (macro) (Example 2) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines the same enum PKG-TYPE using the variable (macro) variation. This is an alternative to the target dependency approach. ```Makefile $(call bmakelib.enum.define,PKG-TYPE/deb,rpm,aur) ``` -------------------------------- ### Verify enum membership with error-unless-member (Example 2) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines an enum BUILD-TARGET and uses bmakelib.enum.error-unless-member to check the TARGET variable. The shell output shows the failure and success cases. ```Makefile define-enum : bmakelib.enum.define( BUILD-TARGET/android,ios,linux ) include define-enum deploy : $(call bmakelib.enum.error-unless-member,BUILD-TARGET,TARGET) @echo 🏭 Building for $(TARGET)... ``` ```text $ make TARGET=windows deploy *** 'windows' is not a member of enum 'BUILD-TARGET'. Stop. $ make TARGET=ios deploy 🏭 building for ios... ``` -------------------------------- ### Set defaults for multiple variables with bmakelib.default-if-blank Source: https://github.com/bahmanm/bmakelib/blob/main/doc/default-if-blank.md Shows how to set defaults for multiple blank variables in one call. The output confirms VAR1 gets 'foo' while VAR2 keeps its existing value '100'. ```Makefile VAR1 = VAR2 = 100 some-target : bmakelib.default-if-blank( VAR1,foo VAR2,bar ) @echo 👉 VAR1=$(VAR1), VAR2=$(VAR2) ``` ```text $ make some-target 👉 VAR1=foo, VAR2=100 ``` -------------------------------- ### Define enums using target dependency (Example 1) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines two enums, DaysOfWeek and DISTRO, using the target dependency variation. The include line ensures the enums are defined before other targets are evaluated. ```Makefile define-enums : bmakelib.enum.define( DaysOfWeek/SUN,MON,TUE,WED,THU,FRI,SAT ) define-enums : bmakelib.enum.define( DISTRO/openSUSE,Debian,Fedora ) include define-enums ``` -------------------------------- ### Get dictionary value in recipe Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Retrieves and prints the value of a-key from MY-DICT when some-target runs. bmakelib.dict.get is a function macro evaluated via $(call ...) and cannot be used as a target prerequisite. ```Makefile some-target : @echo $(call bmakelib.dict.get,MY-DICT,a-key) ``` -------------------------------- ### Get dictionary value in variable assignment Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Retrieves the value of a-key from MY-DICT and assigns it to VAR1. bmakelib.dict.get is a function macro evaluated via $(call ...) and cannot be used as a target prerequisite. ```Makefile VAR1 = $(call bmakelib.dict.get,MY-DICT,a-key) ``` -------------------------------- ### Define enum using target dependency (Example 2) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines an enum PKG-TYPE with values deb, rpm, and aur using the target dependency variation. The enum is not accessible before the publish-package target is invoked. ```Makefile publish-package : bmakelib.enum.define( PKG-TYPE/deb,rpm,aur ) publish-package : ... ``` -------------------------------- ### Use bmakelib.dict as target prerequisites for deployment Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Shows the prerequisite form of bmakelib.dict.define and put to populate a DEPLOY dictionary, then uses bmakelib.dict.get in a recipe. Note that values set via target prerequisites are not available in prerequisite lists. ```Makefile define-config : bmakelib.dict.define( DEPLOY ) define-config : bmakelib.dict.put( DEPLOY,env,prod ) define-config : bmakelib.dict.put( DEPLOY,service,accounts ) define-config : bmakelib.dict.put( DEPLOY,host,accounts.example.com ) deploy : define-config deploy : /usr/bin/deploy \ --env $(call bmakelib.dict.get,DEPLOY,env) \ --server $(call bmakelib.dict.get,DEPLOY,service) \ $(call bmakelib.dict.get,DEPLOY,host) ``` -------------------------------- ### Makefile with documented targets and variables and `bmakelib.help` output Source: https://github.com/bahmanm/bmakelib/blob/main/doc/help.md Shows a Makefile with documented targets and variables, then the output of running `make bmakelib.help` to display them. The output groups targets and variables under the LOCAL scope. ```makefile build: ## Compile and package all build artefacts PREFIX ?= /usr ## Base installation prefix directory ``` ```text $ make bmakelib.help ================================================================================ LOCAL ================================================================================ TARGETS build Compile and package all build artefacts VARIABLES PREFIX Base installation prefix directory ``` -------------------------------- ### Shell: Use convenience target !!logged Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Shows how to use the convenience target '!!logged' from the command line. ```text $ make my-target!!logged ``` -------------------------------- ### Self-documenting Makefile with help output Source: https://github.com/bahmanm/bmakelib/blob/main/README.md Shows how to document variables and targets with ## comments and generate a help screen. The Makefile uses bmakelib.error-if-blank to require ENVIRONMENT. The output demonstrates the help screen with targets and variables sections. ```makefile ENVIRONMENT ?= development ## Target deployment environment (development|staging|production) build: bmakelib.error-if-blank( ENVIRONMENT ) ## Compile binaries and package distribution artefacts build: @echo ✅ Building for $(ENVIRONMENT)... ``` ```text $ make help ================================================================================ LOCAL: defined inside the source tree ================================================================================ TARGETS build Compile binaries and package distribution artefacts VARIABLES ENVIRONMENT Target deployment environment (development|staging|production) -------------------------------------------------------------------------------- ``` -------------------------------- ### Define dictionary as prerequisite with bmakelib.dict.define Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Defines dictionary MY-DICT when my-config-target runs, using the prerequisite form of bmakelib.dict.define. ```Makefile my-config-target : bmakelib.dict.define( MY-DICT ) ``` -------------------------------- ### Shell: Running make with bmakelib.error-if-blank Source: https://github.com/bahmanm/bmakelib/blob/main/doc/error-if-blank.md Shows the command to run the target and the resulting error output. The error message 'Provide value for 'VAR1'.' is displayed and make stops. ```text $ make some-target *** Provide value for 'VAR1'. Stop. ``` -------------------------------- ### bmakelib.shell.error-if-nonzero Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Executes a shell command and expands its output, failing the Make process on non-zero exit codes. ```APIDOC ## bmakelib.shell.error-if-nonzero ### Description Executes the given shell command and expands the output. If the command fails with any non-zero code, fails the Make process with an "error" message. ### Usage `$(call bmakelib.shell.error-if-nonzero, )` ### Parameters - **command** (string) - Required - The shell command to execute. The command can contain up to 9 commas, which must be manually inserted if needed. ### Notes - Set `bmakelib.conf.shell.error-if-nonzero.SILENT` to "no" to emit an info message before running the command. - Quad-quote all variables and structures that are supposed to be only understood by shell. ### Example 1 ```Makefile VAR1 := $(call bmakelib.shell.error-if-nonzero, echo Kaboom! 💣 && false) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero, echo Hello, world) some-target : @echo Unreachable recipe ⛔ ``` ### Example 2 ```Makefile VAR1 := $(call bmakelib.shell.error-if-nonzero,\ echo 🧑 $$$$(whoami) 💻 $$$$(perl -nE'say $$$$1 if /^ID="(.+)"$$$$/' < /etc/os-release)) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero,emacs --version | head -n 1) some-target : @echo VAR1=$(VAR1) @echo VAR2=$(VAR2) ``` ### Example 3 ```Makefile VAR1 := $(call bmakelib.shell.error-if-nonzero,\ docker run --rm ubuntu:22.04 echo Hello, world. && echo Goodbye, world.) some-target : VAR2 := $(call bmakelib.shell.error-if-nonzero,\ [[ ! -z $$$$JAVA_HOME ]] \ && ls $$$$JAVA_HOME/bin/java \ || echo JAVA_HOME not set.) some-target : @echo 👉 VAR1=$(VAR1) @echo 👉 VAR2=$(VAR2) ``` ``` -------------------------------- ### Shell: Run target with bmakelib.logged and view log Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Runs the target with the bmakelib.logged target, which logs the output to a timestamped file. The command echoes the logging command and then the log file contents. ```text $ make my-target!!bmakelib.logged Logging target some-target to some-target-20230808-16221691536940-884103049.logged exec 3>&1 4>&2 \ && trap 'exec 2>&4 1>&3' 0 1 2 3 \ && exec 1>/tmp/tmp.37mr7DpGnn/test_logged/some-target-20230808-16221691536940-884103049.logged 2>&1 \ && make -f Makefile some-target $ cat some-target-20230808-16221691536940-884103049.logged ✅ some-target is done! ``` -------------------------------- ### Makefile: Use convenience target !!logged Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Shows how to use the convenience target '!!logged' as a drop-in replacement for '!!bmakelib.logged' in a makefile. ```makefile some-target : other-target!!logged ``` -------------------------------- ### Set default for a single variable and show info message Source: https://github.com/bahmanm/bmakelib/blob/main/doc/default-if-blank.md Demonstrates setting a default for a single variable and shows the info message emitted when bmakelib.conf.default-if-blank.SILENT is set to 'no'. ```Makefile some-target : bmakelib.default-if-blank( VAR1,foo ) @echo ✅ VAR1 is $(VAR1) ``` ```text $ make bmakelib.conf.default-if-blank.SILENT=no some-target Using default value 'foo' for variable 'VAR1'. ✅ VAR1 is foo ``` -------------------------------- ### Put value as prerequisite with bmakelib.dict.put Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Stores a-value under key a-key in MY-DICT when my-config-target runs, using the prerequisite form of bmakelib.dict.put. ```Makefile my-config-target : bmakelib.dict.define( MY-DICT ) my-config-target : bmakelib.dict.put( MY-DICT,a-key,a-value ) ``` -------------------------------- ### Parameter validation with bmakelib.error-if-blank Source: https://github.com/bahmanm/bmakelib/blob/main/README.md Demonstrates parameter validation with bmakelib.error-if-blank. When RELEASE_STAGE is missing, the build aborts with an error; when provided, the recipe runs successfully. ```makefile build: bmakelib.error-if-blank( RELEASE_STAGE ) build: @echo ✅ Deploying to $(RELEASE_STAGE) ``` ```text $ make build *** Provide a value for 'RELEASE_STAGE'. Stop. $ make RELEASE_STAGE=staging build ✅ Deploying to staging ``` -------------------------------- ### Shell: Run target with silent and no-echo options Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Runs the target with bmakelib.logged while setting SILENT=yes and ECHO_COMMAND=no to suppress informational output and command echoing. Then displays the log file contents. ```text $ make bmakelib.conf.logged.SILENT=yes \ bmakelib.conf.logged.ECHO_COMMAND=no \ some-target!!bmakelib.logged $ cat some-target-20230808-16221691536940-834199518.logged 🤖 Done this and that. ``` -------------------------------- ### Time a prerequisite and use the duration variable Source: https://github.com/bahmanm/bmakelib/blob/main/doc/timed.md Shows a Makefile that sets stdlib.conf.timed.SILENT to yes for my-target and times the prerequisite some-target with !bmakelib.timed. The shell output shows the duration variable stdlib.vars.timed.duration.some-target being used in the recipe. ```makefile some-target : @sleep 2 my-target : stdlib.conf.timed.SILENT = yes my-target : some-target!bmakelib.timed @echo ✅ Made some-target in $(stdlib.vars.timed.duration.some-target)ms 🙌 ``` ```text $ make my-target ✅ Made some-target in 2008ms 🙌 ``` -------------------------------- ### Unsupported space-containing value for bmakelib.default-if-blank Source: https://github.com/bahmanm/bmakelib/blob/main/doc/default-if-blank.md Illustrates the limitation that values containing spaces are not supported and will have undesired effects. ```Makefile some-target : bmakelib.default-if-blank( VAR1,hello world ) ``` -------------------------------- ### Define dictionary with bmakelib.dict.define macro Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Defines a dictionary named MY-DICT using the macro form of bmakelib.dict.define. ```Makefile $(call bmakelib.dict.define,MY-DICT) ``` -------------------------------- ### Use the !timed convenience target in a Makefile Source: https://github.com/bahmanm/bmakelib/blob/main/doc/timed.md Shows the shorter !timed convenience target used as a prerequisite suffix in a Makefile rule. ```makefile some-target : other-target!timed ``` -------------------------------- ### Put value in dictionary with bmakelib.dict.put macro Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Stores a-value under key a-key in MY-DICT using the macro form of bmakelib.dict.put. Requires the dictionary to be defined first. ```Makefile $(call bmakelib.dict.define,MY-DICT) $(call bmakelib.dict.put,MY-DICT,a-key,a-value) ``` -------------------------------- ### Makefile: Using bmakelib.error-if-blank Source: https://github.com/bahmanm/bmakelib/blob/main/doc/error-if-blank.md Defines two variables, VAR1 (blank) and VAR2 (100), and a target that calls bmakelib.error-if-blank with both variables. When the target is run, the function checks if VAR1 is blank and fails the build with an error message. ```makefile VAR1 = VAR2 = 100 some-target : bmakelib.error-if-blank( VAR1 VAR2 ) ``` -------------------------------- ### bmakelib.dict.define Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Defines a dictionary. Can be called as a macro via $(call bmakelib.dict.define,NAME) or used as a prerequisite target using bmakelib.dict.define(NAME). No return value. ```APIDOC ## bmakelib.dict.define ### Description Defines a dictionary with the given name. ### Usage as Macro $(call bmakelib.dict.define,NAME) - NAME (string) - Required - The name of the dictionary to define. ### Usage as Prerequisite TARGET : bmakelib.dict.define( NAME ) - NAME (string) - Required - The name of the dictionary to define. ### Example 1: As Macro ```Makefile $(call bmakelib.dict.define,MY-DICT) ``` Defines a dictionary named `MY-DICT`. ### Example 2: As Prerequisite ```Makefile my-config-target : bmakelib.dict.define( MY-DICT ) ``` Defines dictionary `MY-DICT` when `my-config-target` runs. ### Return Value None (empty string). ``` -------------------------------- ### bmakelib.conf.shell.error-if-nonzero.SILENT Source: https://github.com/bahmanm/bmakelib/blob/main/doc/shell.md Configuration variable to control whether an info message is emitted before running the shell command. ```APIDOC ## bmakelib.conf.shell.error-if-nonzero.SILENT ### Description Controls whether `bmakelib.shell.error-if-nonzero` should emit an info message before running the command. ### Precedence 1. `bmakelib.conf.shell.error-if-nonzero.SILENT` (Make variable) 2. `BMAKELIB_CONF_SHELL_ERROR_IF_NONZERO_SILENT` (environment variable) 3. `yes` (default) ### Values - `yes` (default) - Suppress info message. - `no` - Emit an info message before running the command. ``` -------------------------------- ### bmakelib.dict.get Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Retrieves the value of a given key from a dictionary. This is a function macro evaluated via $(call ...) and cannot be used as a target prerequisite because prerequisites cannot return values. ```APIDOC ## bmakelib.dict.get ### Description Retrieves the value of a given key from a specified dictionary. ### Usage as Macro $(call bmakelib.dict.get,DICT,KEY) - DICT (string) - Required - The name of the dictionary. - KEY (string) - Required - The key whose value to retrieve. ### Example 1: In Variable Assignment ```Makefile VAR1 = $(call bmakelib.dict.get,MY-DICT,a-key) ``` Retrieves the value of `a-key` from `MY-DICT` and assigns it to `VAR1`. ### Example 2: In Recipe ```Makefile some-target : @echo $(call bmakelib.dict.get,MY-DICT,a-key) ``` Retrieves and prints the value of `a-key` from `MY-DICT` when `some-target` runs. ### Return Value The value stored under the given key, or empty if not found. ``` -------------------------------- ### Makefile: Define target to log Source: https://github.com/bahmanm/bmakelib/blob/main/doc/logged.md Defines a make target 'some-target' that echoes a message. This target is used with the bmakelib.logged target to log its output. ```makefile some-target : @echo ✅ some-target is done! ``` -------------------------------- ### bmakelib.dict.put Source: https://github.com/bahmanm/bmakelib/blob/main/doc/dict.md Stores a value in a dictionary under a specified key. Can be called as a macro via $(call bmakelib.dict.put,DICT,KEY,VALUE) or used as a prerequisite target. No return value. ```APIDOC ## bmakelib.dict.put ### Description Stores a given value under a given key in a specified dictionary. ### Usage as Macro $(call bmakelib.dict.put,DICT,KEY,VALUE) - DICT (string) - Required - The name of the dictionary. - KEY (string) - Required - The key under which to store the value. - VALUE (string) - Required - The value to store. ### Usage as Prerequisite TARGET : bmakelib.dict.put( DICT,KEY,VALUE ) - DICT (string) - Required - The name of the dictionary. - KEY (string) - Required - The key under which to store the value. - VALUE (string) - Required - The value to store. ### Example 1: As Macro ```Makefile $(call bmakelib.dict.define,MY-DICT) $(call bmakelib.dict.put,MY-DICT,a-key,a-value) ``` Stores `a-value` under key `a-key` in `MY-DICT`. ### Example 2: As Prerequisite ```Makefile my-config-target : bmakelib.dict.define( MY-DICT ) my-config-target : bmakelib.dict.put( MY-DICT,a-key,a-value ) ``` Stores `a-value` under key `a-key` in `MY-DICT` when `my-config-target` runs. ### Return Value None (empty string). ``` -------------------------------- ### bmakelib.default-if-blank( variable, default_value ) Source: https://github.com/bahmanm/bmakelib/blob/main/doc/default-if-blank.md If the given variable is blank, sets its value to the provided default. Can be used as a prerequisite in a Makefile target. ```APIDOC ## bmakelib.default-if-blank( variable, default_value ) ### Description If the given variable is blank, sets its value to the provided default. ### Usage In a Makefile, typically as a prerequisite: ```Makefile some-target : bmakelib.default-if-blank( VAR1,foo ) @echo VAR1=$(VAR1) ``` ### Parameters - **variable** (string) - Required - The name of the variable to check and set if blank. - **default_value** (string) - Required - The value to set the variable to if it is blank. ### Configuration Set `bmakelib.conf.default-if-blank.SILENT` to "no" to emit an info message when using the default value. ### Notes Currently there is no way to pass a value containing spaces for a variable. ``` -------------------------------- ### Invoke a target with !timed from the shell Source: https://github.com/bahmanm/bmakelib/blob/main/doc/timed.md Shows invoking a target with the !timed convenience suffix from the shell. ```text $ make my-target!timed ``` -------------------------------- ### Time a target with !bmakelib.timed Source: https://github.com/bahmanm/bmakelib/blob/main/doc/timed.md Shows a Makefile target and the shell output when invoking it with the !bmakelib.timed suffix. The output includes a default-value notice for stdlib.conf.timed.SILENT and the reported duration in milliseconds. ```makefile my-target : @sleep 2 @echo 😴 I slept for 2 seconds. ``` ```text $ make my-target!bmakelib.timed Using default value 'yes' for variable 'stdlib.conf.timed.SILENT' 😴 I slept for 2 seconds. Target 'my-target' took 2009ms to complete. ``` -------------------------------- ### bmakelib.conf.default-if-blank.SILENT Source: https://github.com/bahmanm/bmakelib/blob/main/doc/default-if-blank.md Controls whether bmakelib.default-if-blank emits an info message when using the default value. ```APIDOC ## bmakelib.conf.default-if-blank.SILENT ### Description Controls whether `bmakelib.default-if-blank` should emit an info message when using the default provided. ### Values - **yes** (default) - Suppress info message. - **no** - Emit an info message. ### Precedence 1. `bmakelib.conf.default-if-blank.SILENT` (Make variable) 2. `BMAKELIB_CONF_DEFAULT_IF_BLANK_SILENT` (environment variable) 3. `yes` (default) ``` -------------------------------- ### bmakelib.enum.define Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Defines an enum (aka variant or option) that can later be used to verify the value of variables using `bmakelib.enum.error-unless-member`. It can be used as a target dependency or as a variable (macro). ```APIDOC ## bmakelib.enum.define ### Description Defines an enum (aka variant or option) that can later be used to verify the value of variables using `bmakelib.enum.error-unless-member`. It can be used as a target dependency or as a variable (macro). ### Usage - As a target dependency: `bmakelib.enum.define( ENUM_NAME/value1,value2,... )` - As a variable (macro): `$(call bmakelib.enum.define,ENUM_NAME/value1,value2,...)` ### Parameters - `ENUM_NAME` (string) - Required - The name of the enum to define. - `value1,value2,...` (string) - Required - Comma-separated list of possible values for the enum. ### Example ```Makefile # Target dependency include define-enums define-enums : bmakelib.enum.define( DaysOfWeek/SUN,MON,TUE,WED,THU,FRI,SAT ) # Variable (macro) $(call bmakelib.enum.define,DISTRO/openSUSE,Debian,Fedora) ``` ### Notes - When used as a target dependency, the enum is defined when the target is evaluated. Including a non-PHONY target causes it to be evaluated before other targets. - When used as a variable, the enum is defined at the point of the call. ``` -------------------------------- ### bmakelib.enum.error-unless-member Source: https://github.com/bahmanm/bmakelib/blob/main/doc/enum.md Verifies if a variable's value is a member of a given enum and aborts make in case it's not. It can be used as a target dependency or as a variable (macro). ```APIDOC ## bmakelib.enum.error-unless-member ### Description Verifies if a variable's value is a member of a given enum and aborts make in case it's not. It can be used as a target dependency or as a variable (macro). ### Usage - As a target dependency: `bmakelib.enum.error-unless-member( ENUM_NAME,VARIABLE_NAME )` - As a variable (macro): `$(call bmakelib.enum.error-unless-member,ENUM_NAME,VARIABLE_NAME)` ### Parameters - `ENUM_NAME` (string) - Required - The name of the enum to check against. - `VARIABLE_NAME` (string) - Required - The name of the variable whose value is to be verified. ### Example ```Makefile $(call bmakelib.enum.define,DEPLOY-ENV/development,staging,production) deploy : bmakelib.enum.error-unless-member( DEPLOY-ENV,ENV ) deploy : @echo 🚀 Deploying to $(ENV)... ``` ### Behavior - If the variable's value is not a member of the enum, make aborts with an error message. - If the variable's value is a member, execution continues. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.