Chris
Chris

Reputation: 31216

Is there a way to source a shell script in the makefile SHELL declaration?

Suppose I write:

SHELL:=/usr/bin/env bash

commands:
  source sourceme.sh && alias

But I wanted to push that source sourceme.sh back into the SHELL declaration:

SHELL:=/usr/bin/env bash -c "source sourceme.sh" # or something along these lines

Can this be done, and if so, how?

Upvotes: 1

Views: 526

Answers (1)

MadScientist
MadScientist

Reputation: 100856

No, you can't do that. Make takes your recipe lines and sends them to, effectively, $(SHELL) -c <recipeline> The shell, unfortunately, doesn't accept multiple -c options so to do what you want you'd need to have a way for make to insert that string at the beginning of every recipe line and there's no way to do that.

You can do it yourself, from outside your makefile, by writing your own wrapper:

$ cat wrapper.sh
#!/usr/bin/env bash
shift
source sourceme.sh
eval "$@"

$ cat Makefile
SHELL := wrapper.sh

commands:
        alias

Upvotes: 1

Related Questions