1From 65561b53344b834877e6b63320066a1e26038a3c Mon Sep 17 00:00:00 2001
2From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
3Date: Fri, 9 Dec 2022 18:18:27 +0100
4Subject: [PATCH] Fix getopt linking error
5
6The buildroot project, to which the sscep application was added, has
7configurations that raise the following linking error:
8buildroot/output/host/lib/gcc/arc-buildroot-linux-uclibc/11.3.0/../../../../arc-buildroot-linux-uclibc/bin/ld: buildroot/output/host/bin/../arc-buildroot-linux-uclibc/sysroot/usr/lib/libc.a(getopt.os):(.data+0x8): multiple definition of `optind'; src/getopt.o:(.data+0x0): first defined here
9buildroot/output/host/lib/gcc/arc-buildroot-linux-uclibc/11.3.0/../../../../arc-buildroot-linux-uclibc/bin/ld: buildroot/output/host/bin/../arc-buildroot-linux-uclibc/sysroot/usr/lib/libc.a(getopt.os): in function `__GI_getopt':
10getopt.c:(.text+0x5a4): multiple definition of `getopt'; src/getopt.o:getopt.c:(.text+0x0): first defined here
11buildroot/output/host/lib/gcc/arc-buildroot-linux-uclibc/11.3.0/../../../../arc-buildroot-linux-uclibc/bin/ld: buildroot/output/host/bin/../arc-buildroot-linux-uclibc/sysroot/usr/lib/libc.a(getopt.os): in function `getopt_long':
12getopt.c:(.text+0x5b0): multiple definition of `getopt_long'; src/getopt.o:getopt.c:(.text+0x128): first defined here
13collect2: error: ld returned 1 exit status
14make[2]: *** [Makefile:507: sscep] Error 1
15make[1]: *** [package/pkg-generic.mk:293: buildroot/output/build/sscep-0.10.0/.stamp_built] Error 2
16
17The patch re-added a check that commit
1881f56f635259b9 ("Replaced GNU getopt by a BSD licensed alternative")
19removed.
20
21Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
22[yann.morin.1998@free.fr: make that an actual backport]
23Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
24---
25 src/getopt.c | 12 ++++++++++++
26 1 file changed, 12 insertions(+)
27
28diff --git a/src/getopt.c b/src/getopt.c
29index eae36a6..0109406 100644
30--- a/src/getopt.c
31+++ b/src/getopt.c
32@@ -31,6 +31,16 @@
33 #include <stddef.h>
34 #include <string.h>
35
36+#define GETOPT_INTERFACE_VERSION 2
37+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
38+# include <gnu-versions.h>
39+# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
40+#  define ELIDE_CODE
41+# endif
42+#endif
43+
44+#ifndef ELIDE_CODE
45+
46 char* optarg;
47 int optopt;
48 /* The variable optind [...] shall be initialized to 1 by the system. */
49@@ -226,3 +236,5 @@ int getopt_long(int argc, char* const argv[], const char* optstring,
50   ++optind;
51   return retval;
52 }
53+
54+#endif	/* Not ELIDE_CODE.  */
55--
562.25.1
57
58