Subject: bug#76706: [PATCH] build: fix compile errors on platforms without getopt.h

From: Collin Funk <[email-masked]>
Date: Sun, 02 Mar 2025 22:32:48 -0800

Hi,

I found that GNU sed does not compile on platforms with <getopt.h> or
getopt_long. For example on AIX:

    make[2]: Entering directory '/home/collinfunk/sed-4.9.51-0f74-modified'
      CC       sed/sed-sed.o
    sed/sed.c:20:10: fatal error: getopt.h: No such file or directory
       20 | #include <getopt.h>
          |          ^~~~~~~~~~
    compilation terminated.
    make[2]: *** [Makefile:6188: sed/sed-sed.o] Error 1
    make[2]: Leaving directory '/home/collinfunk/sed-4.9.51-0f74-modified'
    make[1]: *** [Makefile:6425: all-recursive] Error 1
    make[1]: Leaving directory '/home/collinfunk/sed-4.9.51-0f74-modified'
    make: *** [Makefile:3595: all] Error 2

This is because the following commit:

    commit 71de42fd346688b131e7364d7ea7be4e973fb0c3
    Author:     Assaf Gordon <[email-masked]>
    AuthorDate: Sat Jan 2 23:41:51 2021 -0700
    Commit:     Assaf Gordon <[email-masked]>
    CommitDate: Tue Jan 5 17:02:10 2021 -0700
    
        maint: update all copyright year number ranges
        
        Run "make update-copyright" and then...
        [...]
        * bootstrap.conf (gnulib_modules): Remove getopt module, depracated in
        https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=0abc38bd2a1398f0
        [...]

The deprecation of getopt was because it split into getopt-posix and
getopt-gnu. GNU sed uses <getopt.h> and getopt_long, so we need
getopt-gnu.

I have attached a patch that fixes this. I added a note in NEWS since
the 4.9 was released after that commit so the tarball won't build on
platforms like AIX.

Collin

>From a5a8de867f4619be2b0613ea1dc9dff92edee74e Mon Sep 17 00:00:00 2001
From: Collin Funk <[email-masked]>
Date: Sun, 2 Mar 2025 22:09:47 -0800
Subject: [PATCH] build: fix compile errors on platforms without getopt.h

* bootstrap.conf (gnulib_modules): Add getopt-gnu.
* lib/.gitignore: Update from gnulib-tool --import.
* m4/.gitignore: Likewise.
* NEWS: Mention the fix.
---
 NEWS           |  5 +++++
 bootstrap.conf |  1 +
 lib/.gitignore | 37 +++++++++++++++++++++++++++++++++++++
 m4/.gitignore  | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+)

diff --git a/NEWS b/NEWS
index 40f85db..4543325 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,11 @@ GNU sed NEWS                                    -*- outline -*-
   apostrophes) instead of `like this' (with a grave accent and an
   apostrophe).  This tracks the GNU coding standards.
 
+** Build-related
+
+  builds no longer fail on platforms without the <getoph.h> header or
+  getopt_long function.
+  [bug introduced in sed 4.9]
 
 * Noteworthy changes in release 4.9 (2022-11-06) [stable]
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 8f11c9a..f21fadc 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -30,6 +30,7 @@ eloop-threshold
 extensions
 fwriting
 getdelim
+getopt-gnu
 gettext-h
 git-version-gen
 gitlog-to-changelog
diff --git a/lib/.gitignore b/lib/.gitignore
index 4c92286..bc65cdf 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -209,7 +209,9 @@
 /time.h
 /time.in.h
 /uchar.h
+/unicase
 /unicase.h
+/unictype
 /unictype.h
 /uninorm.h
 /unistd.c
@@ -245,3 +247,38 @@
 /xalloc.h
 /xmalloc.c
 /stdlib.c
+/c32is-impl.h
+/c32isprint.c
+/c32isspace.c
+/c32rtomb.c
+/c32to-impl.h
+/c32tob.c
+/c32tolower.c
+/c32toupper.c
+/iswblank.c
+/iswctype-impl.h
+/iswctype.c
+/iswdigit.c
+/iswpunct.c
+/iswxdigit.c
+/mbrtoc32.c
+/mbszero.c
+/obstack.in.h
+/same-inode.c
+/setlocale_null-unlocked.c
+/uchar.in.h
+/unicase.in.h
+/unictype.in.h
+/uninorm.in.h
+/unitypes.in.h
+/wctype-impl.h
+/wctype.c
+/getopt-cdefs.in.h
+/getopt-core.h
+/getopt-ext.h
+/getopt-pfx-core.h
+/getopt-pfx-ext.h
+/getopt.c
+/getopt.in.h
+/getopt1.c
+/getopt_int.h
diff --git a/m4/.gitignore b/m4/.gitignore
index 973ec19..41a104b 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -235,3 +235,41 @@
 /semaphore.m4
 /sys_cdefs_h.m4
 /yield.m4
+/build-to-host.m4
+/c32rtomb.m4
+/exponentd.m4
+/exponentf.m4
+/exponentl.m4
+/extensions-aix.m4
+/fclose.m4
+/float_h.m4
+/fpieee.m4
+/gnulib-i18n.m4
+/init-package-version.m4
+/isnand.m4
+/isnanf.m4
+/isnanl.m4
+/iswblank.m4
+/iswctype.m4
+/iswdigit.m4
+/iswpunct.m4
+/iswxdigit.m4
+/libunistring-base.m4
+/locale-en.m4
+/math_h.m4
+/mbrtoc32.m4
+/nan-mips.m4
+/once.m4
+/signbit.m4
+/snan.m4
+/stpcpy.m4
+/time.m4
+/uchar_h.m4
+/unicase_h.m4
+/unictype_h.m4
+/uninorm_h.m4
+/wctype.m4
+/windows-rc.m4
+/xgetcwd.m4
+/getlocalename_l.m4
+/getopt.m4
-- 
2.48.1