Search code examples
bashmakefileamazon-amiamazon-linux-2

ONESHELL in Makefile not working with bash on Amazon Linux 2 ami


I am using this Amazon Linux 2 AMI on an EC2 instance: amazon/amzn2-ami-hvm-2.0.20210525.0-x86_64-gp2

This Makefile works fine:

.SHELLFLAGS := -euo pipefail -c   
SHELL := bash

all:
    echo here

When I run make all I get:

bash-4.2$ make all
echo here
here

Then I add .ONESHELL: to the Makefile:

.ONESHELL:

.SHELLFLAGS := -euo pipefail -c   
SHELL := bash

all:
    echo here

Now when I run make all I get:

bash-4.2$ make all
echo here
bash: line 0: bash: echo here: invalid option name
make: *** [all] Error 2

Bash version:

GNU bash, version 4.2.46(2)-release (x86_64-koji-linux-gnu)

Make version:

GNU Make 3.82
Built for x86_64-koji-linux-gnu

If I remove the .SHELLFLAGS it will run successfully so it seems like a combination of the two is the problem. It also appears that with ONESHELL, the SHELLFLAGS are getting corrupted.


Solution

  • It's a bug in make 3.82, fixed in 4.0. When both .ONESHELL and .SHELLFLAGS is used, the flags are not tokenized correctly.

    You need to either drop one of the two or upgrade your make (possibly outside your distribution).