~emersion/hut#14: 
Cross-platform Makefile

TL;DR - Makefile depends on coreutils install, fails on BSD install.

Installation fails on MacOS where /usr/bin/install is the BSD install command. I resolved the issue by installing coreutils (brew install coreutils) and editing the Makefile (INSTALL = ginstall). Homebrew installs the coreutils with the prefix "g".

For the record, the errors that I saw originally:

~/Projects/hut> sudo make install
install -dp \
		/usr/local/bin/ \
		/usr/local/share/man/man1/ \
		/usr/local/share/bash-completion/completions \
		/usr/local/share/zsh/site-functions \
		/usr/local/share/fish/vendor_completions.d
install: the -d and -C options may not be specified together
install -pm 0755 hut -t /usr/local/bin/
install: -t: No such file or directory
make: *** [install] Error 71

It would be nice if the Makefile was cross-platform.

Status
REPORTED
Submitter
~crg
Assigned to
No-one
Submitted
5 months ago
Updated
2 months ago
Labels
No labels applied.

~habibalamin 2 months ago

install: the -d and -C options may not be specified together

This is probably because of the -p flag on the first install command line;

     -p      Preserve the modification time.  Copy the file, as if the -C
             (compare and copy) option is specified, except if the target file
             doesn't already exist or is different, then preserve the
             modification time of the file.

This reads to me like the target file will have the same modification time as the source file, so at first, I thought we're copying directories across and we want to preserve the modification times of the directories, but no, even after a make, the directories being installed don't exist in the repo directory, they're just being created directly on the target path. Using the -p flag is just pointless in this case.

Assuming I read the -p flag documentation correctly, the fix seems simple enough:

diff --git a/Makefile b/Makefile
index 07947a0..5565e63 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ clean:
 	$(RM) -f hut doc/hut.1 hut.bash hut.zsh hut.fish
 
 install:
-	$(INSTALL) -dp \
+	$(INSTALL) -d \
 		$(DESTDIR)$(PREFIX)/$(BINDIR)/ \
 		$(DESTDIR)$(PREFIX)/$(MANDIR)/man1/ \
 		$(DESTDIR)$(BASHCOMPDIR) \

~habibalamin 2 months ago

install: -t: No such file or directory

BSD install doesn't have the -t option, but according to the GNU info page for install:

  • If the ‘--target-directory’ (‘-t’) option is given, or failing that
    if the last file is a directory and the ‘--no-target-directory’
    (‘-T’) option is not given, ‘install’ copies each SOURCE file to
    the specified directory, using the SOURCEs’ names.

The directories are strictly specified with a trailing slash, and I suspect if the directory didn't exist, GNU install would still treat it as a directory and complain about it being missing. That said, we don't need to rely on that because the previous line which gives us the error about combining -C and -d is exactly the line that creates the required directories.

Again, the fix seems simple enough:

diff --git a/Makefile b/Makefile
index 07947a0..5ab2588 100644
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,8 @@ install:
 		$(DESTDIR)$(BASHCOMPDIR) \
 		$(DESTDIR)$(ZSHCOMPDIR) \
 		$(DESTDIR)$(FISHCOMPDIR)
-	$(INSTALL) -pm 0755 hut -t $(DESTDIR)$(PREFIX)/$(BINDIR)/
-	$(INSTALL) -pm 0644 doc/hut.1 -t $(DESTDIR)$(PREFIX)/$(MANDIR)/man1/
+	$(INSTALL) -pm 0755 hut $(DESTDIR)$(PREFIX)/$(BINDIR)/
+	$(INSTALL) -pm 0644 doc/hut.1 $(DESTDIR)$(PREFIX)/$(MANDIR)/man1/
 	$(INSTALL) -pm 0644 hut.bash $(DESTDIR)$(BASHCOMPDIR)/hut
 	$(INSTALL) -pm 0644 hut.zsh $(DESTDIR)$(ZSHCOMPDIR)/_hut
 	$(INSTALL) -pm 0644 hut.fish $(DESTDIR)$(FISHCOMPDIR)/hut.fish

~habibalamin 2 months ago*

Combined diff:

diff -ru a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -36,14 +36,14 @@
 	$(RM) -f hut doc/hut.1 hut.bash hut.zsh hut.fish
 
 install:
-	$(INSTALL) -dp \
+	$(INSTALL) -d \
 		$(DESTDIR)$(PREFIX)/$(BINDIR)/ \
 		$(DESTDIR)$(PREFIX)/$(MANDIR)/man1/ \
 		$(DESTDIR)$(BASHCOMPDIR) \
 		$(DESTDIR)$(ZSHCOMPDIR) \
 		$(DESTDIR)$(FISHCOMPDIR)
-	$(INSTALL) -pm 0755 hut -t $(DESTDIR)$(PREFIX)/$(BINDIR)/
-	$(INSTALL) -pm 0644 doc/hut.1 -t $(DESTDIR)$(PREFIX)/$(MANDIR)/man1/
+	$(INSTALL) -pm 0755 hut $(DESTDIR)$(PREFIX)/$(BINDIR)/
+	$(INSTALL) -pm 0644 doc/hut.1 $(DESTDIR)$(PREFIX)/$(MANDIR)/man1/
 	$(INSTALL) -pm 0644 hut.bash $(DESTDIR)$(BASHCOMPDIR)/hut
 	$(INSTALL) -pm 0644 hut.zsh $(DESTDIR)$(ZSHCOMPDIR)/_hut
 	$(INSTALL) -pm 0644 hut.fish $(DESTDIR)$(FISHCOMPDIR)/hut.fish

This fixes the issue on BSD install (macOS 12.1), and though it should work on GNU install as well, given the assumptions above hold, I haven't tested this on GNU install.

~emersion 2 months ago

Would you be willing to submit a patch on the ML?

Register here or Log in to comment, or comment via email.