From 7b34413e9942b5777aed4fd3dc9c261214981e74 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 16 Nov 2023 21:29:27 -0500 Subject: [PATCH] help: Allow tests to build/run without 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 | 11 ++++------- configure.ac | 7 +++++++ t/getopt/getopt.h | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 t/getopt/getopt.h diff --git a/Makefile.am b/Makefile.am index e859c4d..2011625 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = diff --git a/configure.ac b/configure.ac index 0aabe47..cf152d8 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ], [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 index 0000000..56c2642 --- /dev/null +++ b/t/getopt/getopt.h @@ -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 -- 2.43.2