From 5df3ee0dc1a6b67cebb173d74afeb1e48395bff1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 4 Nov 2021 07:38:20 +0200 Subject: [PATCH] Complete built-in checks support, add few checks --- README.md | 44 +++++++++-- libbuild2-autoconf-tests/basics/testscript | 30 ++++---- .../libbuild2/autoconf/.gitignore | 5 +- .../libbuild2/autoconf/buildfile | 73 ++++++++++++++++++- .../libbuild2/autoconf/checks/HAVE_STDLIB_H.h | 2 + .../libbuild2/autoconf/checks/HAVE_STRLCAT.h | 9 +++ .../libbuild2/autoconf/checks/HAVE_STRLCPY.h | 9 +++ .../libbuild2/autoconf/checks/STDC_HEADERS.h | 2 + .../libbuild2/autoconf/checks/const.h | 2 + .../libbuild2/autoconf/checks/inline.h | 2 + .../libbuild2/autoconf/checks/volatile.h | 2 + .../libbuild2/autoconf/rule.cxx | 15 +--- 12 files changed, 159 insertions(+), 36 deletions(-) create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STDLIB_H.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCAT.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCPY.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/STDC_HEADERS.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/const.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/inline.h create mode 100644 libbuild2-autoconf/libbuild2/autoconf/checks/volatile.h diff --git a/README.md b/README.md index d38b136..df2a1fa 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,47 @@ GNU Autoconf emulation build system module for `build2`. Specifically, this module provides an [`in`][module-in]-based rule for -processing `config.h.in` files. Besides the Autoconf flavor, it also supports -CMake and Meson variants. +processing `config.h.in` files. Besides the Autoconf special line flavor +(`#undef`), it also supports the CMake (`#cmakedefine`) and Meson +(`#mesondefine`) variants. -Similar to Autoconf, the module provides built-in support for a number of +Similar to Autoconf, this module provides built-in support for a number of common `HAVE_*` configuration options. However, the values of these options are not discovered by dynamic probing, such as trying to compile a test -program to check if the header is present. Instead, they are set to static -expected values based on the platform/compiler macros. +program to check if the feature is present. Instead, they are set to static +expected values based on the platform/compiler macros (see note at the +beginning of [Project Configuration][proj-config] for rationale). + +See [`libbuild2/autoconf/checks/`][checks] for the list of available build-in +configuration options. + +## Adding new configuration options. + +To add a new configuration option `` simply create the `.h` header +file with the corresponding check and place it into +[`libbuild2/autoconf/checks/`][checks] (use existing checks for inspiration). + +The first line in this header file must be in the form: + +``` +// +``` + +Subsequent lines should be C-style comments or preprocessor directives that +`#define` or `#undef` `` depending on whether the feature is available +(though there can be idiosyncrasies; see `const.h`, for example). Note that +there should be no double-quotes or backslashes except for line +continuations. For example: + +``` +// HAVE_FOO +#ifndef _WIN32 +# define HAVE_FOO 1 +#else +# undef HAVE_FOO /* No foo on Windows. */ +#endif +``` [module-in]: https://build2.org/build2/doc/build2-build-system-manual.xhtml#module-in +[proj-config]: https://build2.org/build2/doc/build2-build-system-manual.xhtml#proj-config +[checks]: https://github.com/build2/libbuild2-autoconf/tree/master/libbuild2-autoconf/libbuild2/autoconf/checks/ diff --git a/libbuild2-autoconf-tests/basics/testscript b/libbuild2-autoconf-tests/basics/testscript index 85a8940..6c0c471 100644 --- a/libbuild2-autoconf-tests/basics/testscript +++ b/libbuild2-autoconf-tests/basics/testscript @@ -43,8 +43,8 @@ cat <=config.h.in; #undef CUSTOM_LINE #undef CUSTOM_BLOCK - #undef HAVE_TEST_DUMMY1_H - #undef HAVE_TEST_DUMMY2_H + #undef zzz_TEST_DUMMY1_H + #undef zzz_TEST_DUMMY2_H EOI $* <>EOO @@ -84,8 +84,8 @@ cat config.h >>EOO # define CUSTOM 123 #endif - #define HAVE_TEST_DUMMY1_H 1 - #define HAVE_TEST_DUMMY2_H 2 + #define zzz_TEST_DUMMY1_H 1 + #define zzz_TEST_DUMMY2_H 2 EOO : basics-cmake @@ -111,8 +111,8 @@ cat <=config.h.in; #cmakedefine FALSE false #cmakedefine VALUE @VALUE@ /* @version@ */ - #cmakedefine HAVE_TEST_DUMMY1_H @HAVE_TEST_DUMMY1_H@ - #cmakedefine HAVE_TEST_DUMMY2_H + #cmakedefine zzz_TEST_DUMMY1_H @zzz_TEST_DUMMY1_H@ + #cmakedefine zzz_TEST_DUMMY2_H EOI $* <>EOO @@ -162,8 +162,8 @@ cat config.h >>EOO #undef FALSE #define VALUE 123 /* 1.2.3 */ - #define HAVE_TEST_DUMMY1_H 1 - #define HAVE_TEST_DUMMY2_H 2 + #define zzz_TEST_DUMMY1_H 1 + #define zzz_TEST_DUMMY2_H 2 EOO : basics-meson @@ -184,8 +184,8 @@ cat <=config.h.in; #mesondefine CUSTOM_LINE #mesondefine CUSTOM_BLOCK - #mesondefine HAVE_TEST_DUMMY1_H - #mesondefine HAVE_TEST_DUMMY2_H + #mesondefine zzz_TEST_DUMMY1_H + #mesondefine zzz_TEST_DUMMY2_H EOI $* <>EOO @@ -227,6 +227,6 @@ cat config.h >>EOO # define CUSTOM 123 #endif - #define HAVE_TEST_DUMMY1_H 1 - #define HAVE_TEST_DUMMY2_H 2 + #define zzz_TEST_DUMMY1_H 1 + #define zzz_TEST_DUMMY2_H 2 EOO diff --git a/libbuild2-autoconf/libbuild2/autoconf/.gitignore b/libbuild2-autoconf/libbuild2/autoconf/.gitignore index 0c9102a..4f263b5 100644 --- a/libbuild2-autoconf/libbuild2/autoconf/.gitignore +++ b/libbuild2-autoconf/libbuild2/autoconf/.gitignore @@ -1,3 +1,4 @@ -# Generated version header. +# Generated sources. # -version.hxx +checks.?xx + diff --git a/libbuild2-autoconf/libbuild2/autoconf/buildfile b/libbuild2-autoconf/libbuild2/autoconf/buildfile index 393c8c0..e7be180 100644 --- a/libbuild2-autoconf/libbuild2/autoconf/buildfile +++ b/libbuild2-autoconf/libbuild2/autoconf/buildfile @@ -4,7 +4,78 @@ impl_libs = # Implementation dependencies. import impl_libs += build2%lib{build2} # Implied interface dependency. import impl_libs += build2%lib{build2-in} -lib{build2-autoconf}: {hxx ixx txx cxx}{**} $impl_libs $intf_libs +lib{build2-autoconf}: {hxx ixx txx cxx}{* -checks} {hxx cxx}{checks} \ + $impl_libs $intf_libs + +# - File name must be the exact variable name plus .h (used for sorting). +# - First line in the file should be `// `. +# - No double-quote or backslash escaping except for line continuations. +# +# NOTE: remember to update README.md if changing anything here. +# +<{hxx cxx}{checks}>: checks/file{*.h} +{ + install = false + backlink = true +} +{{ + diag gen ($>[1]) + + # We have to sort without the extension. + # + i = $regex.apply($sort($base($path($<))), '(.+)', '\1.h') + + h = $path($>[0]) + s = $path($>[1]) + + # We regularize the output with a dummy start entry plus add two end dummies + # that are used in tests. + # + n = $size($<) + n += 3 + + cat <<"EOI" >$h + namespace build2 + { + namespace autoconf + { + struct check + { + const char* name; + const char* value; + }; + + extern const check checks[$n]; + } + } + EOI + + cat <<"EOI" >$s + #include + + const build2::autoconf::check build2::autoconf::checks[$n] = { + {\"\", \"\" + EOI + + # @@ TODO: add \n once sed supports it. + # + cat $i | sed -n \ + -e 's|^// ([^ ]+) *$|},{"\1",|p' \ + -e 's|^(.*)\\$|"\1\\\\\\n"|p' \ + -e 's|^(.*)$|"\1\\n"|p' \ + - >>$s + + cat <>$s + }, + {"zzz_TEST_DUMMY1_H", + "#define zzz_TEST_DUMMY1_H 1" + }, + {"zzz_TEST_DUMMY2_H", + "#define zzz_TEST_DUMMY2_H 1" + } + }; + EOI +}} # Build options. # diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STDLIB_H.h b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STDLIB_H.h new file mode 100644 index 0000000..6c091bd --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STDLIB_H.h @@ -0,0 +1,2 @@ +// HAVE_STDLIB_H +#define HAVE_STDLIB_H 1 diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCAT.h b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCAT.h new file mode 100644 index 0000000..a626541 --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCAT.h @@ -0,0 +1,9 @@ +// HAVE_STRLCAT +#if defined(__FreeBSD__) || \ + defined(__OpenBSD__) || \ + defined(__NetBSD__) || \ + defined(__APPLE__) +# define HAVE_STRLCAT 1 +#else +# undef HAVE_STRLCAT +#endif diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCPY.h b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCPY.h new file mode 100644 index 0000000..f0ff465 --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/HAVE_STRLCPY.h @@ -0,0 +1,9 @@ +// HAVE_STRLCPY +#if defined(__FreeBSD__) || \ + defined(__OpenBSD__) || \ + defined(__NetBSD__) || \ + defined(__APPLE__) +# define HAVE_STRLCPY 1 +#else +# undef HAVE_STRLCPY +#endif diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/STDC_HEADERS.h b/libbuild2-autoconf/libbuild2/autoconf/checks/STDC_HEADERS.h new file mode 100644 index 0000000..687005c --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/STDC_HEADERS.h @@ -0,0 +1,2 @@ +// STDC_HEADERS +#define STDC_HEADERS 1 diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/const.h b/libbuild2-autoconf/libbuild2/autoconf/checks/const.h new file mode 100644 index 0000000..abff54f --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/const.h @@ -0,0 +1,2 @@ +// const +#undef const diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/inline.h b/libbuild2-autoconf/libbuild2/autoconf/checks/inline.h new file mode 100644 index 0000000..d0b9ec9 --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/inline.h @@ -0,0 +1,2 @@ +// inline +#undef inline diff --git a/libbuild2-autoconf/libbuild2/autoconf/checks/volatile.h b/libbuild2-autoconf/libbuild2/autoconf/checks/volatile.h new file mode 100644 index 0000000..f3b8f67 --- /dev/null +++ b/libbuild2-autoconf/libbuild2/autoconf/checks/volatile.h @@ -0,0 +1,2 @@ +// volatile +#undef volatile diff --git a/libbuild2-autoconf/libbuild2/autoconf/rule.cxx b/libbuild2-autoconf/libbuild2/autoconf/rule.cxx index a3d045a..6cf1231 100644 --- a/libbuild2-autoconf/libbuild2/autoconf/rule.cxx +++ b/libbuild2-autoconf/libbuild2/autoconf/rule.cxx @@ -4,6 +4,8 @@ #include #include +#include + using namespace std; namespace build2 @@ -364,19 +366,6 @@ namespace build2 in::rule::process (l, a, t, dd, dd_skip, s, b, nl, sym, strict, null); } - struct check - { - const char* name; - const char* value; - }; - - // Note: must be sorted. - // - const check checks[] = { - {"HAVE_TEST_DUMMY1_H", "#define HAVE_TEST_DUMMY1_H 1"}, - {"HAVE_TEST_DUMMY2_H", "#define HAVE_TEST_DUMMY2_H 1"}, - }; - string rule:: lookup (const location& l, action a, const target& t,