]> git.draconx.ca Git - dxcommon.git/commitdiff
help: Allow tests to build/run without <getopt.h>
authorNick Bowler <nbowler@draconx.ca>
Fri, 17 Nov 2023 02:29:27 +0000 (21:29 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 18 Nov 2023 21:39:51 +0000 (16:39 -0500)
We only need a suitable definition of struct option in order to build
the tests; this can be provided by a stub header if the system does not
provide it.

Makefile.am
configure.ac
t/getopt/getopt.h [new file with mode: 0644]

index e859c4d7b3a6b7f8e27d3cf54b4cb8655e5b32b6..20116257eabdff9216eabf8aba4f11057458f884 100644 (file)
@@ -6,7 +6,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-AM_CPPFLAGS = -I$(top_srcdir)/src
+AM_CPPFLAGS = -I$(top_srcdir)/src $(STUB_INCLUDES)
 
 check_LIBRARIES = t/libdummy.a t/libempty.a
 
@@ -17,22 +17,19 @@ t_packtests_SOURCES = t/packtests.c src/pack.c src/tap.c
 t_packtestu64_SOURCES = t/packtestu64.c src/pack.c src/tap.c
 t_packtests64_SOURCES = t/packtests64.c src/pack.c src/tap.c
 
-if HAVE_STRUCT_OPTION
 check_PROGRAMS += t/helpdesc t/helpopt t/helpopt2
-
 if HAVE_WCWIDTH
 check_PROGRAMS += t/helpopt3
 endif
-endif
 
 EXTRA_LIBRARIES = libglohelp.a
 libglohelp_a_SOURCES = src/help.c
-libglohelp_a_CPPFLAGS = -DHELP_GETOPT_LONG_ONLY
+libglohelp_a_CPPFLAGS = $(AM_CPPFLAGS) -DHELP_GETOPT_LONG_ONLY
 libglohelp_a_SHORTNAME = glo
 
 EXTRA_LIBRARIES += libnlshelp.a
 libnlshelp_a_SOURCES = src/help.c t/nls/mbswidth.c
-libnlshelp_a_CPPFLAGS = -DENABLE_NLS -I$(top_srcdir)/t/nls
+libnlshelp_a_CPPFLAGS = $(AM_CPPFLAGS) -DENABLE_NLS -I$(top_srcdir)/t/nls
 libnlshelp_a_SHORTNAME = nls
 
 t_helpdesc_SOURCES = t/helpdesc.c src/help.c src/tap.c
@@ -53,7 +50,7 @@ EXTRA_t_copysym_DEPENDENCIES = $(t_copysym_LDADD)
 
 EXTRA_LIBRARIES += libnlscopysym.a
 libnlscopysym_a_SOURCES = src/copysym.c
-libnlscopysym_a_CPPFLAGS = -DENABLE_NLS
+libnlscopysym_a_CPPFLAGS = $(AM_CPPFLAGS) -DENABLE_NLS
 libnlscopysym_a_SHORTNAME = nls
 
 DISTCLEANFILES =
index 0aabe4737d3d8e1001eaea6b2756cea7615d4d66..cf152d889e9029147c6604c3a850dd13463e2cfd 100644 (file)
@@ -21,6 +21,10 @@ AM_SILENT_RULES([yes])
 DX_INIT([.])
 
 AC_USE_SYSTEM_EXTENSIONS
+AC_C_INLINE
+
+AC_SUBST([STUB_INCLUDES], [@&t@])
+
 AC_CHECK_FUNCS_ONCE([wcwidth])
 AM_CONDITIONAL([HAVE_WCWIDTH], [test x"$ac_cv_func_wcwidth" = x"yes"])
 
@@ -33,6 +37,9 @@ AC_CACHE_CHECK([for struct option in <getopt.h>], [dx_cv_have_struct_option],
 [[struct option opt = { "aaaa", 2, (void *)0, 'a' };
 return opt.name[opt.flag ? opt.val : opt.has_arg];]])],
   [dx_cv_have_struct_option=yes], [dx_cv_have_struct_option=no])])
+AS_IF([test x"$dx_cv_have_struct_option" != x"yes"],
+  [AS_VAR_APPEND([STUB_INCLUDES], ['-I${top_srcdir}/t/getopt'])])
+
 AM_CONDITIONAL([HAVE_STRUCT_OPTION],
   [test x"$dx_cv_have_struct_option" = x"yes"])
 
diff --git a/t/getopt/getopt.h b/t/getopt/getopt.h
new file mode 100644 (file)
index 0000000..56c2642
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright © 2023 Nick Bowler
+ *
+ * Stub getopt.h for test purposes.
+ *
+ * License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+ * This is free software: you are free to do what the fuck you want to.
+ * There is NO WARRANTY, to the extent permitted by law.
+ */
+
+#ifndef TEST_GETOPT_H_
+#define TEST_GETOPT_H_
+
+struct option {
+       const char *name;
+       int has_arg;
+       int *flag;
+       int val;
+};
+
+#endif