GNU Astronomy Utilities



11.2.1 Text functions for Makefiles

The functions described below are generic (not limited to astronomy/FITS) functions that operate on plain text. You can see these as functions that should have been implemented in GNU Make itself. The names of these functions start with ast-text-* and each has a fully working example to demonstrate its usage.

$(ast-text-contains STRING, TEXT)

Returns all white-space-separated words in TEXT that contain the STRING, removing any words that do not match. For example, the following minimal Makefile will only print the bAaz Aah word of the list.

load /usr/local/lib/libgnuastro_make.so

list = fooo baar bAaz uggh Aah
all:
     echo $(ast-text-contains Aa, $(list))

This can be thought of as Make’s own filter function, but if it would accept two patterns in a format like this $(filter %Aa%,$(list)) (for the example above). In fact, the first sentence describing this function is taken from the Make manual’s first sentence that describes the filter function! However, unfortunately Make’s filter function only accepts a single %, not two!

$(ast-text-not-contains STRING, TEXT)

Returns all white-space-separated words in TEXT that do not contain the STRING, removing any words that do not match. This is the inverse of the ast-text-contains function. For example, the following minimal Makefile will print fooo baar uggh word of the list.

load /usr/local/lib/libgnuastro_make.so

list = fooo baar bAaz uggh Aah
all:
     echo $(ast-text-not-contains Aa, $(list))
$(ast-text-to-upper STRING)

Returns the input string but with all characters in UPPER-CASE. For example, the following minimal Makefile will print FOOO BAAR UGGH word of the list.

load /usr/local/lib/libgnuastro_make.so

list   = fOOo bAar UggH
ulist := $(ast-text-to-upper $(list))
all:; echo $(ulist)
$(ast-text-to-lower STRING)

Returns the input string but with all characters in lower-case. For example, the following minimal Makefile will print fooo baar uggh word of the list.

load /usr/local/lib/libgnuastro_make.so

list  = fOOo bAar UggH
list := $(ast-text-to-lower $(list))
all:; echo $(ulist)