I'm trying to copy multiple files from one directory to another via a Makefile.
However this does not work...
SHELL=/bin/bash
copy:
@cp /dir1/dir2/{file1,file2} /dir3/
Output:
cp: /dir1/dir2/{file1,file2}: No such file or directory
*** Error code 1
Stop.
make: stopped in /dir1/dir2
Specifying a single file at a time works though
SHELL=/bin/bash
copy:
@cp /dir1/dir2/file1 /dir3/
@cp /dir1/dir2/file2 /dir3/
This issue is specific to freebsd make (/usr/bin/make
) and the same Makefile works with gmake on freebsd (/usr/local/bin/gmake
).
So can I assume that freebsd make doesn't understand the braces syntax in paths? And any tweaks with which I can correct my Makefile according to freebsd make syntax?
It's the shell that expands these braces, not make. Make just passes the recipe commands to the shell. In FreeBSD make, the SHELL
variable doesn't change the shell. In this way I suppose FreeBSD make does not conform to POSIX.
In FreeBSD make, you have to use the .SHELL
special target instead. See: https://man.freebsd.org/cgi/man.cgi?make(1)
Since .SHELL
isn't important to GNU Make, you can just add it to your makefile and GNU Make will ignore it.