0
  • On ubuntu 24.04

  • GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)

  • automake (GNU automake) 1.16.5

  • autoconf (GNU Autoconf) 2.71

From automake doc

${var:+value} Old BSD shells, including the Ultrix sh, don’t accept the colon for any shell substitution, and complain and die. Similarly for ${var:=value}, ${var:?value}, etc. However, all shells that support functions allow the use of colon in shell substitution, and since m4sh requires functions, you can portably use null variable substitution patterns in configure scripts.

The substituion does not happen in the following example

Given : SOURCE_DATE_EPOCH = 333

src/Makefile.am

bin_PROGRAMS = myproject myproject_SOURCES = main.c param6=123 a=${param6:+xyz} $(info ####### a = $(a)#######) $(info ####### $(SOURCE_DATE_EPOCH) #######) $(info ########## ${SOURCE_DATE_EPOCH:+ -d @${SOURCE_DATE_EPOCH}}) 

output :

####### a = ####### ####### 333 ####### ########## 

The third info log isn't printing SOURCE_DATE_EPOCH value despite it being defined

Is it possible to use variable substitution like ":+" in automake files ?

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 27 at 9:26

1 Answer 1

0

The doc can be misinterpreted as I did.

:+ is not supposed to be expanded by automake, but by the shell.

So by prepending $ twice, two expansions will occur: one by automake that expands every $ occurence ($$SOURCE_DATE_EPOCH into $SOURCE_DATE_EPOCH), the second one by shell which expands $SOURCE_DATE_EPOCH into the value stored in the environment variable SOURCE_DATE_EPOCH.

# This will return the value of SOURCE_DATE_EPOCH if defined, # when called from a command line inside a Makefile.am (automake + shell expansions) `$${SOURCE_DATE_EPOCH:+ -d @$${SOURCE_DATE_EPOCH}}` 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.