[GRASS-dev] cp -r vs -R in make

Glynn Clements glynn at gclements.plus.com
Tue Jan 26 04:28:26 PST 2016


Anna Petrášová wrote:

> cp: the -H, -L, and -P options may not be specified with the -r option.
> 
> make: *** [install] Error 1
> 
> 
> It seems cp -r (lowercase r) is not portable, see [1]. Mac cp man page says:
> 
> Historic versions of the cp utility had a -r option. This implementation
> supports that option; how-ever, however, ever, its use is strongly
> discouraged, as it does not correctly copy special files, symbolic links,
> or fifo's.
> 
> lowercase r is used on couple of places, mainly include/Make/Install.make.
> So my question is if anyone thinks there are some valid reasons for using
> lowercase r.

"cp" probably shouldn't be used at all.

Executable files should be installed with $(INSTALL), non-executable
files with $(INSTALL_DATA).

In either case, they should only be used to copy a rule's prerequisite
to its target (i.e. no unconditional "bulk" copies in the body of an
unrelated rule), as in:

	destination: source
		$(INSTALL_DATA) $< $@

If the number of files is large, $(wildcard ...) and $(patsubst ...) 
should be used to construct a list of targets which should then be
made prerequisites of the Makefile's "default" rule, with the
installation performed by a pattern rule.

The only places "cp" is used in the actual GRASS source tree (not
including "addons") are in Install.make, the "install" targets of a
couple of other *.make files, and the "update-po" target in
locale/Makefile. None of these are part of the actual build process.

(I just removed the one in simlib; Rules.make already has a pattern
rule for installing headers).

FWIW, the "portable" solution for recursive copies has historically
been to use "tar c ... | tar x ...".

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list