summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-01 17:54:42 +0100
committerDavid Robillard <d@drobilla.net>2021-01-02 13:23:51 +0100
commita124e36c3520e3f887b3a47aac685d9ad453bf09 (patch)
treeb1f43b0206024b06bf51725407c381691591ebb0
parent31cc05d5ef6e840ebe2b4c265f374f913f4758cc (diff)
downloadlilv-a124e36c3520e3f887b3a47aac685d9ad453bf09.tar.gz
lilv-a124e36c3520e3f887b3a47aac685d9ad453bf09.tar.bz2
lilv-a124e36c3520e3f887b3a47aac685d9ad453bf09.zip
Remove the need for a generated configuration header
-rw-r--r--NEWS3
-rw-r--r--src/filesystem.c8
-rw-r--r--src/lilv_config.h128
-rw-r--r--src/world.c2
-rw-r--r--wscript6
5 files changed, 137 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 5c0c7d0..246c4a0 100644
--- a/NEWS
+++ b/NEWS
@@ -5,8 +5,9 @@ lilv (0.24.11) unstable;
* Fix saving state with files on Windows
* Fix unlikely undefined behavior when saving state
* Fix writing state manifests on Windows
+ * Remove the need for a generated configuration header
- -- David Robillard <d@drobilla.net> Fri, 18 Dec 2020 16:30:48 +0000
+ -- David Robillard <d@drobilla.net> Fri, 01 Jan 2021 16:54:05 +0000
lilv (0.24.10) stable;
diff --git a/src/filesystem.c b/src/filesystem.c
index 0d6989b..c42c8d2 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -1,5 +1,5 @@
/*
- Copyright 2007-2020 David Robillard <http://drobilla.net>
+ Copyright 2007-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
@@ -38,7 +38,7 @@
# include <unistd.h>
#endif
-#if defined(HAVE_FLOCK) && defined(HAVE_FILENO)
+#if USE_FLOCK && USE_FILENO
# include <sys/file.h>
#endif
@@ -299,7 +299,7 @@ lilv_path_canonical(const char* path)
bool
lilv_path_exists(const char* path)
{
-#ifdef HAVE_LSTAT
+#if USE_LSTAT
struct stat st;
return !lstat(path, &st);
#else
@@ -386,7 +386,7 @@ lilv_flock(FILE* file, bool lock, bool block)
} else {
return !UnlockFileEx(handle, 0, UINT32_MAX, UINT32_MAX, &overlapped);
}
-#elif defined(HAVE_FLOCK) && defined(HAVE_FILENO)
+#elif USE_FLOCK && USE_FILENO
return flock(fileno(file),
(lock ? LOCK_EX : LOCK_UN) | (block ? 0 : LOCK_NB));
#else
diff --git a/src/lilv_config.h b/src/lilv_config.h
new file mode 100644
index 0000000..9f6c111
--- /dev/null
+++ b/src/lilv_config.h
@@ -0,0 +1,128 @@
+/*
+ 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 LILV_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 LILV_CONFIG_H
+#define LILV_CONFIG_H
+
+// Define version unconditionally so a warning will catch a mismatch
+#define LILV_VERSION "0.24.11"
+
+#if !defined(LILV_NO_DEFAULT_CONFIG)
+
+// We need unistd.h to check _POSIX_VERSION
+# ifndef LILV_NO_POSIX
+# ifdef __has_include
+# if __has_include(<unistd.h>)
+# include <unistd.h>
+# endif
+# elif defined(__unix__)
+# include <unistd.h>
+# endif
+# endif
+
+// POSIX.1-2001: fileno()
+# ifndef HAVE_FILENO
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_FILENO
+# endif
+# endif
+
+// Classic UNIX: flock()
+# ifndef HAVE_FLOCK
+# if defined(__unix__)
+# define HAVE_FLOCK
+# endif
+# endif
+
+// POSIX.1-2001: lstat()
+# ifndef HAVE_LSTAT
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_LSTAT
+# endif
+# endif
+
+#endif // !defined(LILV_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_FILENO
+# define USE_FILENO 1
+#else
+# define USE_FILENO 0
+#endif
+
+#ifdef HAVE_FLOCK
+# define USE_FLOCK 1
+#else
+# define USE_FLOCK 0
+#endif
+
+#ifdef HAVE_LSTAT
+# define USE_LSTAT 1
+#else
+# define USE_LSTAT 0
+#endif
+
+/*
+ Define required values. These are always used as a fallback, even with
+ LILV_NO_DEFAULT_CONFIG, since they must be defined for the build to work.
+*/
+
+// Separator between entries in variables like PATH
+#ifndef LILV_PATH_SEP
+# ifdef _WIN32
+# define LILV_PATH_SEP ";"
+# else
+# define LILV_PATH_SEP ":"
+# endif
+#endif
+
+// Separator between directories in a path
+#ifndef LILV_DIR_SEP
+# ifdef _WIN32
+# define LILV_DIR_SEP "\\"
+# else
+# define LILV_DIR_SEP "/"
+# endif
+#endif
+
+// Default value for LV2_PATH environment variable
+#ifndef LILV_DEFAULT_LV2_PATH
+# ifdef _WIN32
+# define LILV_DEFAULT_LV2_PATH "%APPDATA%/LV2;%COMMONPROGRAMFILES%/LV2"
+# else
+# define LILV_DEFAULT_LV2_PATH "~/.lv2:/usr/lib/lv2:/usr/local/lib/lv2"
+# endif
+#endif
+
+#endif // LILV_CONFIG_H
diff --git a/src/world.c b/src/world.c
index a6f103e..1455b34 100644
--- a/src/world.c
+++ b/src/world.c
@@ -15,7 +15,7 @@
*/
#include "filesystem.h"
-#include "lilv_config.h"
+#include "lilv_config.h" // IWYU pragma: keep
#include "lilv_internal.h"
#include "lilv/lilv.h"
diff --git a/wscript b/wscript
index ab2cdd2..713c0f9 100644
--- a/wscript
+++ b/wscript
@@ -266,15 +266,13 @@ def configure(conf):
lv2_path = lilv_path_sep.join(['~/.lv2',
'/usr/%s/lv2' % libdirname,
'/usr/local/%s/lv2' % libdirname])
- conf.define('LILV_DEFAULT_LV2_PATH', lv2_path)
+ conf.define('LILV_DEFAULT_LV2_PATH', lv2_path.replace('%', '%%'))
# Set up environment for building/using as a subproject
autowaf.set_lib_env(conf, 'lilv', LILV_VERSION,
include_path=str(conf.path.find_node('include')))
- conf.write_config_header('lilv_config.h', remove=False)
-
- conf.undefine('LILV_DEFAULT_LV2_PATH') # Cmd line errors with VC++
+ conf.define('LILV_NO_DEFAULT_CONFIG', 1)
autowaf.display_summary(
conf,