diff --git a/meson.build b/meson.build index 815afba8..7d21f364 100644 --- a/meson.build +++ b/meson.build @@ -31,7 +31,11 @@ add_project_arguments(cppflags, language : 'cpp') config_h = configuration_data() config_h.set('_GNU_SOURCE', '1') -config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized' + config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +else + config_h.set_quoted('MESON_BUILD_ROOT', '') +endif prefix = '''#define _GNU_SOURCE 1 #include diff --git a/tools/shared.c b/tools/shared.c index 74c0cdad..3cda4573 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -477,6 +477,11 @@ tools_execdir_is_builddir(void) char *pathsep; ssize_t sz; + /* In the case of release builds, the builddir is + the empty string */ + if (streq(MESON_BUILD_ROOT, "")) + return NULL; + sz = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1); if (sz <= 0 || sz == sizeof(execdir) - 1) return NULL; diff --git a/tools/test-builddir-lookup.c b/tools/test-builddir-lookup.c index fc50b0f6..821ca70f 100644 --- a/tools/test-builddir-lookup.c +++ b/tools/test-builddir-lookup.c @@ -36,9 +36,15 @@ int main(int argc, char **argv) { if (streq(mode, "--builddir-is-null")) { assert(builddir == NULL); } else if (streq(mode, "--builddir-is-set")) { - assert(builddir != NULL); - assert(streq(MESON_BUILD_ROOT, builddir)); - free(builddir); + /* In the case of release builds, the builddir is + the empty string */ + if (streq(MESON_BUILD_ROOT, "")) { + assert(builddir == NULL); + } else { + assert(builddir != NULL); + assert(streq(MESON_BUILD_ROOT, builddir)); + free(builddir); + } } else { abort(); }