mtm icon indicating copy to clipboard operation
mtm copied to clipboard

Makefile: Use install command to install

Open JohnAZoidberg opened this issue 4 years ago • 9 comments

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.

JohnAZoidberg avatar Jul 30 '19 22:07 JohnAZoidberg

-t is not a standard option of install. It will probably cause trouble for users and package maintainers.

0mp avatar Aug 06 '19 14:08 0mp

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

JohnAZoidberg avatar Aug 06 '19 15:08 JohnAZoidberg

I believe that GNU install's -D is not portable. See GNU install and FreeBSD install manuals, for example.

0mp avatar Aug 06 '19 20:08 0mp

Hmm. It seems like install isn't more helpful in this use-case than mkdir -p and cp, right?

JohnAZoidberg avatar Aug 06 '19 22:08 JohnAZoidberg

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!

0mp avatar Aug 08 '19 11:08 0mp

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).

HalosGhost avatar Aug 24 '19 18:08 HalosGhost

Which systems do not support mkdir -p? Since it's part of the POSIX standard I think it's safe to use.

JohnAZoidberg avatar Aug 24 '19 22:08 JohnAZoidberg

@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.

HalosGhost avatar Aug 26 '19 17:08 HalosGhost

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.

HalosGhost avatar Sep 06 '19 14:09 HalosGhost