summaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2023-05-02 10:27:31 +0200
committerCarlos Garnacho <carlosg@gnome.org>2023-05-02 10:27:31 +0200
commit63ea8f1a2a603c356ad770ae7567246e7520f298 (patch)
tree78463901e35500e52ea2b280a7462f1b88d5e682 /meson.build
parent0619c65273da0ca2644e43596fe3d61c1d8b0737 (diff)
downloadtracker-63ea8f1a2a603c356ad770ae7567246e7520f298.tar.gz
build: Detect appropriate strftime() year modifier at build time
Different libc implementations (or different platforms) have different bugs. Even though %Y is documented as a 4-digit number, and %C as year/100 in a [00-99] range, they both crap out with years under 1000, using respectively 3 and 1 digits. This would be typically task for a width modifier (e.g. %4Y, or %2C), but that was conversely found to break NixOS on Darwin. Since the existing libc bugs paint us to a corner, detect an appropriate modifier at build time to get a 4-digit year to get true ISO 8601 in our supported [0001-9999] year range. Closes: https://gitlab.gnome.org/GNOME/tracker/-/issues/402
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build35
1 files changed, 35 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index 3c147c8f3..6a7f8e133 100644
--- a/meson.build
+++ b/meson.build
@@ -199,6 +199,39 @@ else
endif
##################################################################
+# Get an appropriate 4-digit year modifier for strftime
+##################################################################
+result = cc.run('''
+ #include <stdio.h>
+ #include <string.h>
+ #include <time.h>
+
+ int main (int argc, char *argv[]) {
+ char *modifiers[] = { "%Y", "%C%y", "%4Y", "%2C%y", NULL };
+ time_t timestamp = -58979923200; /* 0101-01-01T01:01:01Z */
+ char *buf[100];
+ struct tm tm;
+ int i;
+ gmtime_r (&timestamp, &tm);
+ for (i = 0; modifiers[i]; i++) {
+ strftime (&buf, sizeof buf, modifiers[i], &tm);
+ if (strcmp (&buf, "0101") == 0) {
+ printf ("%s", modifiers[i]);
+ return 0;
+ }
+ }
+ return -1;
+ }
+ ''',
+ name: 'strftime 4-digit year modifier')
+
+if not result.compiled() or result.returncode() != 0
+ error('Libc implementation has broken 4-digit years implementation.')
+else
+ year_modifier = result.stdout()
+endif
+
+##################################################################
# Check for libtracker-data and libtracker-fts: Unicode support
#
# By default, AUTO with this order of preference:
@@ -306,6 +339,7 @@ conf.set('TRACKER_MINOR_VERSION', tracker_minor_version)
conf.set('TRACKER_MICRO_VERSION', tracker_micro_version)
conf.set('TRACKER_INTERFACE_AGE', 0)
conf.set('TRACKER_BINARY_AGE', 100 * tracker_minor_version + tracker_micro_version)
+conf.set('STRFTIME_YEAR_MODIFIER', '"@0@"'.format(year_modifier))
# Check for RTLD_NOLOAD
have_rtld_noload = cc.has_header_symbol('dlfcn.h', 'RTLD_NOLOAD')
@@ -399,6 +433,7 @@ summary = [
' Debug: ' + get_option('debug').to_string(),
' Optimization: ' + get_option('optimization'),
' Compiler: ' + cc.get_id(),
+ ' 4-digit strftime() year modifier: ' + year_modifier,
'\nFeature Support:',
' Unicode support library: ' + unicode_library_name,
' Build with Stemming support: ' + have_libstemmer.to_string(),