2025-02-03

Twenty years of the "GNU Make Standard Library"

Twenty years ago, on February 3, 2005, I released v1.0.0 of a project I called "GNU Make Standard Library" (GMSL). That first release can still be found in its original location on SourceForge. I moved the project from SourceForge to GitHub and newer releases are there. The latest release is v1.2.2 on March 30, 2024.

The project has its own homepage at https://gmsl.jgc.org/. The page describes the GMSL as "a collection of functions implemented using native GNU Make functionality that provide list and string manipulation, integer arithmetic, associative arrays, stacks, and debugging facilities."

GMSL grew out of work that eventually became my book "The GNU Make Book". What can it do?

Well, things like this:

include gmsl

VAR    := Here is a string with some words in it.
$(info $(VAR))

# Convert VAR to lowercase
LC_VAR := $(call lc,$(VAR))
$(info $(LC_VAR))

# Get the length of LC_VAR as a string
$(info $(call strlen,$(LC_VAR)))

# See if VAR and LC_VAR are the same string
$(info $(if $(call seq,$(VAR),$(LC_VAR)),Same,Different))

# Treat LC_VAR as a list and get the last element
$(info $(call last,$(LC_VAR)))

# Get the number of list elements in LC_VAR
$(info $(call length,$(LC_VAR)))

# Apply the strlen function to each element of LC_VAR
$(info $(call map,strlen,$(LC_VAR)))

# Deduplicate the list of lenghts of elements of LC_VAR
$(info $(call uniq,$(call map,strlen,$(LC_VAR))))

# Split LC_VAR on the letter e and replace with 3
$(info $(call merge,3,$(call split,e,$(LC_VAR))))

# Create an associative array mapping the lengths of words
# in LC_VAR to a count for each length
increment_aa = $(call set,LC_VAR_AA,$1,$(call inc,$(call get,LC_VAR_AA,$1)))
$(call map,increment_aa,$(call map,strlen,$(LC_VAR)))
dump_key = $(info $1: $(call get,LC_VAR_AA,$1))
$(call map,dump_key,$(call keys,LC_VAR_AA))

And a whole lot more. The entire GMSL is written using native GNU Make functionality and pull requests are welcome!

Update 2025-02-05: I decided GMSL was missing a fold function so I added it. So, latest release is today, v1.2.3

No comments: