From 7698cca6d5634ce0de4bb382e0535e1f02d7fb17 Mon Sep 17 00:00:00 2001
From: xhe <xw897002528@gmail.com>
Date: Sat, 14 Jul 2018 18:45:45 +0800
Subject: [PATCH] install: symlink m4 files to $(dataroot)/aclocal follow
https://github.com/sabotage-linux/gettext-tiny/issues/27.
According to @awilfox, GNU gettext will install m4 files to aclocal dir.
But gettext-tiny did not. So autoreconf just stops working and complains
that it can not find needed macros.
Suggested by rofl0r, symlinking all m4 files into $(dataroot)/aclocal is
a good idea. Save a little disk space.
---
Makefile | 22 ++++++++++++---------
install.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 9 deletions(-)
create mode 100644 install.sh
diff --git a/Makefile b/Makefile
index 7842c0f..927d02e 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,9 @@ bindir=$(prefix)/bin
includedir=$(prefix)/include
libdir=$(prefix)/lib
sysconfdir=$(prefix)/etc
-datadir=$(prefix)/share/gettext-tiny
+datarootdir=$(prefix)/share
+datadir=$(datarootdir)/gettext-tiny
+acdir=$(datarootdir)/aclocal
ifeq ($(LIBINTL), MUSL)
LIBSRC = libintl/libintl-musl.c
@@ -36,13 +38,15 @@ AR ?= $(CROSS_COMPILE)ar
RANLIB ?= $(CROSS_COMPILE)ranlib
CC ?= $(CROSS_COMPILE)cc
+INSTALL ?= ./install.sh
+
-include config.mak
BUILDCFLAGS=$(CFLAGS)
all: $(ALL_LIBS) $(ALL_TOOLS)
-install: $(ALL_LIBS:lib%=$(DESTDIR)$(libdir)/lib%) $(ALL_INCLUDES:%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:%=$(DESTDIR)$(bindir)/%) $(ALL_M4S:%=$(DESTDIR)$(datadir)/%) $(ALL_DATA:%=$(DESTDIR)$(datadir)/%)
+install: $(ALL_LIBS:lib%=$(DESTDIR)$(libdir)/lib%) $(ALL_INCLUDES:%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:%=$(DESTDIR)$(bindir)/%) $(ALL_M4S:%=$(DESTDIR)$(datadir)/%) $(ALL_M4S:%=$(DESTDIR)$(acdir)/%) $(ALL_DATA:%=$(DESTDIR)$(datadir)/%)
clean:
rm -f $(ALL_LIBS)
@@ -70,18 +74,18 @@ autopoint: src/autopoint.in
cat $< | sed 's,@datadir@,$(datadir),' > $@
$(DESTDIR)$(libdir)/%.a: %.a
- install -D -m 755 $< $@
+ $(INSTALL) -D -m 755 $< $@
$(DESTDIR)$(includedir)/%.h: include/%.h
- install -D -m 644 $< $@
+ $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(bindir)/%: %
- install -D -m 755 $< $@
+ $(INSTALL) -D -m 755 $< $@
$(DESTDIR)$(datadir)/%: %
- install -D -m 644 $< $@
-
-.PHONY: all clean install
-
+ $(INSTALL) -D -m 644 $< $@
+$(DESTDIR)$(acdir)/%: %
+ $(INSTALL) -D -l ../$(subst $(datarootdir)/,,$(datadir))/$< $(subst m4/,,$@)
+.PHONY: all clean install
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..0410883
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# Written by Rich Felker, originally as part of musl libc.
+# Multi-licensed under MIT, 0BSD, and CC0.
+#
+# This is an actually-safe install command which installs the new
+# file atomically in the new location, rather than overwriting
+# existing files.
+#
+
+usage() {
+printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
+exit 1
+}
+
+mkdirp=
+symlink=
+mode=755
+
+while getopts Dlm: name ; do
+case "$name" in
+D) mkdirp=yes ;;
+l) symlink=yes ;;
+m) mode=$OPTARG ;;
+?) usage ;;
+esac
+done
+shift $(($OPTIND - 1))
+
+test "$#" -eq 2 || usage
+src=$1
+dst=$2
+tmp="$dst.tmp.$$"
+
+case "$dst" in
+*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
+esac
+
+set -C
+set -e
+
+if test "$mkdirp" ; then
+umask 022
+case "$2" in
+*/*) mkdir -p "${dst%/*}" ;;
+esac
+fi
+
+trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
+
+umask 077
+
+if test "$symlink" ; then
+ln -s "$1" "$tmp"
+else
+cat < "$1" > "$tmp"
+chmod "$mode" "$tmp"
+fi
+
+mv -f "$tmp" "$2"
+test -d "$2" && {
+rm -f "$2/$tmp"
+printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
+exit 1
+}
+
+exit 0