I want to write a Makefile which would run tests. Test are in a directory ‘./tests’ and executable files to be tested are in the directory ‘./bin’.
When I run the tests, they don’t see the exec files, as the directory ./bin is not in the $PATH.
When I do something like this:
EXPORT PATH=bin:$PATH
make test
everything works. However I need to change the $PATH in the Makefile.
Simple Makefile content:
test all:
PATH=bin:${PATH}
@echo $(PATH)
x
It prints the path correctly, however it doesn’t find the file x.
When I do this manually:
$ export PATH=bin:$PATH
$ x
everything is OK then.
How could I change the $PATH in the Makefile?
Did you try
exportdirective of Make itself (assuming that you use GNU Make)?Also, there is a bug in you example:
First, the value being
echoed is an expansion ofPATHvariable performed by Make, not the shell. If it prints the expected value then, I guess, you’ve setPATHvariable somewhere earlier in your Makefile, or in a shell that invoked Make. To prevent such behavior you should escape dollars:Second, in any case this won’t work because Make executes each line of the recipe in a separate shell. This can be changed by writing the recipe in a single line: