mtm
mtm copied to clipboard
Makefile: Use install command to install
It creates the parent directories of the target if they are not there.
This is especially useful if you want to install it into a non-standard location.
-t
is not a standard option of install
. It will probably cause trouble for users and package maintainers.
Oh, you're right. It seems to be a GNU extension. I'm not sure I understand the manual correctly. It works on GNU, would that do it?
install -m755 mtm -D $(DESTDIR)/bin/mtm
install -m644 mtm.1 -D $(MANDIR)/mtm.1
I believe that GNU install's -D
is not portable. See GNU install and FreeBSD install manuals, for example.
Hmm. It seems like install
isn't more helpful in this use-case than mkdir -p
and cp
, right?
I think that I'd go for mkdir -p
and install -m XXX
. That seems to be fairly standard across different operating systems.
To be extra careful maybe we could go for mkdir
, cp
and chmod
but I am not sure if that's smart.
Cheers!
Note that mkdir -p
is actually also non-portable. It is not uncommon for makefiles attempting to be maximally portable to define MKDIR ?= mkdir -p
and leverage $(MKDIR)
throughout the script (so that if -p
is not possible / would cause problems, the user can declare the use of a different program or script that will handle it properly).
Which systems do not support mkdir -p
?
Since it's part of the POSIX standard I think it's safe to use.
@JohnAZoidberg, for reference: https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html
Though -p
is specified by POSIX, it is underspecified in certain cases which can cause portability issues. It's a minor thing though; and can be easily changed should anyone actually run into it as a problem.
Just to clarify, I do not think you should worry about providing an alternative to mkdir -p
yourself in this PR. Instead, if no one objects, I think it would be ideal to define MKDIR ?= mkdir -p
so that people can override it if they need to for their platform, and then use $(MKDIR)
instead of mkdir -p
throughout the script.
That lets the portability question be dealt with by users of platforms affected, but still empowers them to overcome the issue with minimal extra effort.