1
votes

This is a follow up on this question: Can I use GNU make's SHELL variable to connect to a remote shell?

I'd like to use two different shells in a single recipe. One shell is on a host machine, and the other is on a target device that doesn't have make. The shell on the host machine is used for tracking tests' success and failure. The shell on the target device is used for performing the test. I've successfully used $(eval SHELL=) to change from the host shell to the target shell. However, when I add $(eval SHELL=) to the recipe, it seems like the SHELL never changes. I assume that the two eval functions are evaluated before the recipe is run, so the second expansion cancels the first one out. Is there a way to make these eval functions expand during run time, or otherwise change the SHELL variable twice in a single recipe?

To illustrate what I'm aiming at, it will be something like this:

test: test_dependencies  
    touch $host_files_for_tracking  
    SHELL = target_shell  
    $(program_to_test) $(params) -o result  
    cmp result gold  
    SHELL = host_shell  
    rm $host_files_for_tracking

Thanks.

Note: When I'm talking about SHELL, I'm referring to the make-internal variable that determines which shell make invokes in order to executes recipe steps, not the environment variable.

1

1 Answers

1
votes

If you're not bound to using only a single recipe, you could split the rule as follows:

.PHONY: test test_dependencies

test : test_target test_host
test_host : test_target # to enforce the order
test_target test_host : test_dependencies

shell_orig := $(SHELL)

Target related rules would look like these:

.PHONY: test_target test_target_touch

test_target: test_target_touch
test_target_touch: SHELL = $(shell_orig)
    touch $host_files_for_tracking  

test_target: SHELL = target_shell
    $(program_to_test) $(params) -o result  

And host:

.PHONY: test_host test_host_cmp

test_host: test_host_cmp
test_host_cmp: SHELL = $(shell_orig)
    cmp result gold  

test_host: SHELL = host_shell
    rm $host_files_for_tracking

In case of using the most recent GNU Make 3.82, shell_orig hack can be avoided by using private modifier for target-specific SHELL variables.