0001-Fix-getopt-linking-error.patch 2.5 KB

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