From ef5c909a81d0398773e378726708aa7b7da02888 Mon Sep 17 00:00:00 2001 From: suzuki toshiya Date: Thu, 20 Nov 2025 12:59:44 +0900 Subject: [PATCH] Add ft_tar.m4: FT_PROG_TAR, a substitution of _AM_PROG_TAR. Automake has an internal macro _AM_PROG_TAR in tar.m4 to help 'make dist' target, searching a command creating POSIX ustar bitstream and following symbolic link, not only tar variarions but also pax and cpio. To improve the portability of non-automake 'make dist' in toplevel.mk, its imitation FT_PROG_TAR() is introduced. It is useful for POSIX systems with 'pax' but its 'tar' differs from GNU tar or libarchive bsdtar, like Solaris (or Illumos), HP-UX, or AIX. FT_PROG_TAR() sets 'ft_tar_chf_' (usually expanded to 'tar --format=ustar -chf - $${tardir}'), playing the role of 'am__tar' in automake tar.m4. * builds/unix/ft_tar.m4: Added to provide FT_PROG_TAR. * builds/unix/configrue.raw: Call FT_PROG_TAR and set new make variable TAR_CHF_. * builds/unix/unix-def.in: Get TAR_CHF_ from configure. * builds/toplevel.mk (dist): New shell variable 'tardir' (like automake internal), new make variable 'TAR_CHF_', and replace 'tar --format=ustar chf -' by it. The original value 'tar --format=ustar chf -' is preserved as a default value of 'TAR_CHF_'. --- builds/toplevel.mk | 12 ++--- builds/unix/configure.raw | 5 ++ builds/unix/ft_tar.m4 | 101 ++++++++++++++++++++++++++++++++++++++ builds/unix/unix-def.in | 4 ++ 4 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 builds/unix/ft_tar.m4 diff --git a/builds/toplevel.mk b/builds/toplevel.mk index 86dfe379e..c5dba00f5 100644 --- a/builds/toplevel.mk +++ b/builds/toplevel.mk @@ -229,20 +229,22 @@ work := # Not to be run by a normal user -- there are no attempts to make it # generic. +TAR_CHF_ ?= tar --format=ustar -chf - $${tardir} + dist: -rm -rf tmp rm -f freetype-$(version).tar.gz rm -f freetype-$(version).tar.xz rm -f ft$(winversion).zip - for d in `find . -wholename '*/.git' -prune \ + for d in `find . -name '.git' -prune \ -o -type f \ -o -print` ; do \ mkdir -p tmp/$$d ; \ done ; currdir=`pwd` ; \ - for f in `find . -wholename '*/.git' -prune \ + for f in `find . -name '.git' -prune \ -o -name .gitattributes \ -o -name .gitignore \ -o -name .gitlab-ci.yml \ @@ -259,10 +261,8 @@ dist: mv tmp freetype-$(version) - tar --format=ustar -chf - freetype-$(version) \ - | gzip -9 -c > freetype-$(version).tar.gz - tar --format=ustar -chf - freetype-$(version) \ - | xz -c > freetype-$(version).tar.xz + tardir=freetype-$(version) && $(TAR_CHF_) | gzip -9 -c > freetype-$(version).tar.gz + tardir=freetype-$(version) && $(TAR_CHF_) | xz -c > freetype-$(version).tar.xz @# Use CR/LF for zip files. zip -lr9 ft$(winversion).zip freetype-$(version) diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw index 45a9be6e4..6a917cf18 100644 --- a/builds/unix/configure.raw +++ b/builds/unix/configure.raw @@ -1015,6 +1015,11 @@ esac AX_PTHREAD([have_pthread=yes], [have_pthread=no]) +# Check for tar for "make dist" +FT_PROG_TAR([gnutar gtar bsdtar tar pax cpio]) +TAR_CHF_="${ft_tar_chf_}" +AC_SUBST([TAR_CHF_]) + # Check for Python and docwriter PYTHON_MIN_VERSION=3.5 have_py3=no diff --git a/builds/unix/ft_tar.m4 b/builds/unix/ft_tar.m4 new file mode 100644 index 000000000..7b9a7ff58 --- /dev/null +++ b/builds/unix/ft_tar.m4 @@ -0,0 +1,101 @@ +dnl +dnl This is a cloning of _AM_PROG_TAR in aclocal/tar.m4, +dnl although its namespace is FT_XXX. +dnl +dnl +dnl FT_PROG_TAR() +dnl $1 = space separated commands to be tried +dnl (default: gnutar gtar bsdtar tar pax cpio) +dnl +dnl The tested results are recorded in: +dnl ft_tar_cmd: the command to emit POSIX ustar +dnl it can be the commands whose syntax +dnl is incompatible with tar - like, +dnl pax or cpio. +dnl ft_tar_flags: the options to emit POSIX ustar +dnl ft_tar_chf_: the command with flags to emit +dnl ustar bitstream from $(tardir) +dnl to STDOUT. +dnl ft_tar_xf_: the command with flags to extract +dnl ustar bitstream from STDIN. +dnl +dnl Example of usage in configure.ac +dnl +dnl FT_PROG_TAR([gnutar gtar bsdtar tar pax cpio]) +dnl AC_SUBST([TAR_CHF_],[${ft_tar_chf_}]) +dnl AC_SUBST([UNTAR_XF_],[${ft_tar_xf_}]) +dnl +dnl Example of usage in Makefile.am +dnl +dnl freetype-$(version).tar: +dnl ... +dnl tardir=freetype-$(version) && $(TAR_CHF_) > $@ +dnl +dnl +AC_DEFUN([FT_PROG_TAR],[ + tar_candidates="$1" + if test -z "${tar_candidates}" + then + tar_candidates="gnutar gtar bsdtar tar pax cpio" + fi + + AC_MSG_CHECKING([tar supporting ustar and following symlink]) + + unset ft_tarflags + for ft_tar_cmd in ${tar_candidates} + do + case ${ft_tar_cmd} in + *tar) + ft_tar_cflags="--format=ustar -chf -" + ft_tar_xflags="--format=ustar -xf -" + ;; + *pax) + ft_tar_cflags="-w -x ustar -L" + ft_tar_xflags="-r" + ;; + *cpio) + ft_tar_cflags="-o -H ustar -L" + ft_tar_xflags="-i -H ustar" + ;; + *) + AC_MSG_WARN([cannot test ${ft_tar_cmd}]) + continue + ;; + esac + + if expr "${ft_tar_cmd}" : ".*cpio" > /dev/null + then + ft_tar_ok=`(echo . | ${ft_tar_cmd} ${ft_tar_cflags} > /dev/null 2>/dev/null && echo yes) || echo no` + ft_tar_chf_='find $${tardir} -print | '"${ft_tar_cmd} ${ft_tar_cflags}" + else + ft_tar_ok=`(${ft_tar_cmd} ${ft_tar_cflags} . > /dev/null 2>/dev/null && echo yes) || echo no` + ft_tar_chf_="${ft_tar_cmd} ${ft_tar_cflags} "'$${tardir}' + fi + + if test "x${ft_tar_ok}" = xyes + then + AC_MSG_RESULT([found, "${ft_tar_cmd} ${ft_tar_cflags}"]) + break + fi + done + + if test "x${ft_tar_ok}" != xyes + then + AC_MSG_RESULT([not found, fallback plain tar]) + unset ft_tar_cmd + AC_CHECK_PROG([ft_tar_cmd],[tar],[tar],[false]) + if test "x${ft_tar_cmd}" = xtar + then + ft_tar_cflags="chf -" + ft_tar_xflags="xf -" + ft_tar_chf_='tar chf - $${tardir}' + ft_tar_xf_='tar xf -' + else + AC_MSG_WARN(["tar" command is missing, "make dist" will fail]) + ft_tar_cflags="" + ft_tar_xflags="" + ft_tar_chf_=false + ft_tar_xf_=false + fi + fi +]) diff --git a/builds/unix/unix-def.in b/builds/unix/unix-def.in index fe629272d..91756ac8b 100644 --- a/builds/unix/unix-def.in +++ b/builds/unix/unix-def.in @@ -21,6 +21,10 @@ DELDIR := rm -rf CAT := cat SEP := / +# This is used for `make dist' +# +TAR_CHF_ := @TAR_CHF_@ + # This is used for `make refdoc' and `make refdoc-venv' # PYTHON := @PYTHON@