diff options
author | David Robillard <d@drobilla.net> | 2021-01-01 14:15:49 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-01-01 17:48:20 +0100 |
commit | 4a54d784af0bec03fdc1f9889157a8c653969db9 (patch) | |
tree | 2c94dec6c4369a9a341cf9da4f4dbcce28cd77cf | |
parent | d101d926946a5e8067a90d157b6553aae7bddc19 (diff) | |
download | serd-4a54d784af0bec03fdc1f9889157a8c653969db9.tar.gz serd-4a54d784af0bec03fdc1f9889157a8c653969db9.tar.bz2 serd-4a54d784af0bec03fdc1f9889157a8c653969db9.zip |
Remove the need for a generated configuration header
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/serd_config.h | 115 | ||||
-rw-r--r-- | src/serdi.c | 4 | ||||
-rw-r--r-- | src/system.c | 8 | ||||
-rw-r--r-- | wscript | 8 |
5 files changed, 127 insertions, 11 deletions
@@ -5,11 +5,12 @@ serd (0.30.7) unstable; * Fix potential memory error when serialising URIs * Move headers to an include directory * Refuse to write relative URI references to NTriples + * Remove the need for a generated configuration header * Remove use of C character class functions that may use locale * Split up and reorganize unit tests * Use aligned allocation via C11 or Windows API where possible - -- David Robillard <d@drobilla.net> Thu, 17 Dec 2020 09:09:31 +0000 + -- David Robillard <d@drobilla.net> Fri, 01 Jan 2021 13:16:40 +0000 serd (0.30.6) stable; diff --git a/src/serd_config.h b/src/serd_config.h new file mode 100644 index 00000000..0038a981 --- /dev/null +++ b/src/serd_config.h @@ -0,0 +1,115 @@ +/* + Copyright 2021 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/* + Configuration header that defines reasonable defaults at compile time. + + This allows compile-time configuration from the command line (typically via + the build system) while still allowing the source to be built without any + configuration. The build system can define SERD_NO_DEFAULT_CONFIG to disable + defaults, in which case it must define things like HAVE_FEATURE to enable + features. The design here ensures that compiler warnings or + include-what-you-use will catch any mistakes. +*/ + +#ifndef SERD_CONFIG_H +#define SERD_CONFIG_H + +// Define version unconditionally so a warning will catch a mismatch +#define SERD_VERSION "0.30.7" + +#if !defined(SERD_NO_DEFAULT_CONFIG) + +// We need unistd.h to check _POSIX_VERSION +# ifndef SERD_NO_POSIX +# ifdef __has_include +# if __has_include(<unistd.h>) +# include <unistd.h> +# endif +# elif defined(__unix__) +# include <unistd.h> +# endif +# endif + +// C99 and C++11: aligned_alloc() +# ifndef HAVE_ALIGNED_ALLOC +# if !defined(__APPLE__) && !defined(_WIN32) +# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define HAVE_ALIGNED_ALLOC +# elif defined(__cplusplus) && __cplusplus >= 201103L) +# define HAVE_ALIGNED_ALLOC +# endif +# endif +# endif + +// POSIX.1-2001: fileno() +# ifndef HAVE_FILENO +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_FILENO +# endif +# endif + +// POSIX.1-2001: posix_fadvise() +# ifndef HAVE_POSIX_FADVISE +# ifndef __APPLE__ +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_POSIX_FADVISE +# endif +# endif +# endif + +// POSIX.1-2001: posix_memalign() +# ifndef HAVE_POSIX_MEMALIGN +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_POSIX_MEMALIGN +# endif +# endif + +#endif // !defined(SERD_NO_DEFAULT_CONFIG) + +/* + Make corresponding USE_FEATURE defines based on the HAVE_FEATURE defines from + above or the command line. The code checks for these using #if (not #ifdef), + so there will be an undefined warning if it checks for an unknown feature, + and this header is always required by any code that checks for features, even + if the build system defines them all. +*/ + +#ifdef HAVE_ALIGNED_ALLOC +# define USE_ALIGNED_ALLOC 1 +#else +# define USE_ALIGNED_ALLOC 0 +#endif + +#ifdef HAVE_FILENO +# define USE_FILENO 1 +#else +# define USE_FILENO 0 +#endif + +#ifdef HAVE_POSIX_FADVISE +# define USE_POSIX_FADVISE 1 +#else +# define USE_POSIX_FADVISE 0 +#endif + +#ifdef HAVE_POSIX_MEMALIGN +# define USE_POSIX_MEMALIGN 1 +#else +# define USE_POSIX_MEMALIGN 0 +#endif + +#endif // SERD_CONFIG_H diff --git a/src/serdi.c b/src/serdi.c index 44644ff4..550da3c0 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -27,7 +27,7 @@ # include <io.h> #endif -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) +#if USE_POSIX_FADVISE && USE_FILENO # include <fcntl.h> #endif @@ -141,7 +141,7 @@ serd_fopen(const char* path, const char* mode) return NULL; } -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) +#if USE_POSIX_FADVISE && USE_FILENO posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); #endif diff --git a/src/system.c b/src/system.c index 3f10b86b..5b40583b 100644 --- a/src/system.c +++ b/src/system.c @@ -21,7 +21,7 @@ #include "serd_config.h" #include "serd_internal.h" -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) +#if USE_POSIX_FADVISE && USE_FILENO # include <fcntl.h> #endif @@ -44,7 +44,7 @@ serd_fopen(const char* path, const char* mode) return NULL; } -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) +#if USE_POSIX_FADVISE && USE_FILENO posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); #endif return fd; @@ -55,9 +55,9 @@ serd_malloc_aligned(const size_t alignment, const size_t size) { #if defined(_WIN32) return _aligned_malloc(size, alignment); -#elif __STDC_VERSION__ >= 201112L && defined(HAVE_ALIGNED_ALLOC) +#elif USE_ALIGNED_ALLOC return aligned_alloc(alignment, size); -#elif defined(HAVE_POSIX_MEMALIGN) +#elif USE_POSIX_MEMALIGN void* ptr = NULL; const int ret = posix_memalign(&ptr, alignment, size); return ret ? NULL : ptr; @@ -155,7 +155,7 @@ def configure(conf): conf.env.SERDI = [serdi_node.abspath()] - conf.write_config_header('serd_config.h', remove=False) + conf.define('SERD_NO_DEFAULT_CONFIG', 1) autowaf.display_summary( conf, @@ -190,7 +190,7 @@ def build(bld): defines = [] lib_args = {'export_includes': ['include'], - 'includes': ['.', 'include', './src'], + 'includes': ['include'], 'cflags': ['-fvisibility=hidden'], 'lib': ['m'], 'vnum': SERD_VERSION, @@ -220,7 +220,7 @@ def build(bld): if bld.env.BUILD_TESTS: coverage_flags = [''] if bld.env.NO_COVERAGE else ['--coverage'] - test_args = {'includes': ['.', 'include', './src'], + test_args = {'includes': ['include'], 'cflags': coverage_flags, 'linkflags': coverage_flags, 'lib': lib_args['lib'], @@ -255,7 +255,7 @@ def build(bld): obj = bld(features = 'c cprogram', source = 'src/serdi.c', target = 'serdi', - includes = ['.', 'include', './src'], + includes = ['include'], use = 'libserd', lib = lib_args['lib'], install_path = '${BINDIR}') |