I have started a new project with agar 1.7.1 as a meson subproject. I installed sdl2 from the official wrabDB, and agar from the source tarball downloaded from the website.
├── src
│ └── main.c
└── subprojects
├── agar-1.7.1
├── packagecache
├── packagefiles
├── SDL2-2.32.8
├── sdl2.wrap
├── sdl2_image.wrap
└── sdl2_ttf.wrap
I used Claude code to get my build started, and I needed these patches that - unfortunately - have some GNU-isms
meson: add _GNU_SOURCE to feature detection checks for glibc
Several has_function() checks fail on glibc/Linux because the tested
functions (asprintf, vasprintf, getpwnam_r, nanosleep, strsep,
clock_gettime, drand48) are gated behind _GNU_SOURCE in glibc headers.
Without _GNU_SOURCE, these checks report NO even though the functions
are available. The most critical consequence is HAVE_VASPRINTF being
unset, which causes the fallback in vasprintf.c to be used. That
fallback reuses a va_list across two calls (vsnprintf + vsprintf)
without va_copy, resulting in a segfault on x86_64 Linux when
AG_ConfigAddPath is called during AG_InitTextSubsystem.
Fix by defining _GNU_SOURCE in the prefix for all affected checks.
--- a/meson.build
+++ b/meson.build
@@ -104,10 +104,11 @@
have_unistd_h = cc.has_header('unistd.h')
# Check for functions
-have_asprintf = cc.has_function('asprintf', prefix: '#include <stdio.h>')
+gnu_source_prefix = '#define _GNU_SOURCE\n'
+have_asprintf = cc.has_function('asprintf', prefix: gnu_source_prefix + '#include <stdio.h>')
have_execvp = cc.has_function('execvp', prefix: '#include <unistd.h>')
have_getenv = cc.has_function('getenv')
-have_getpwnam_r = cc.has_function('getpwnam_r', prefix: '#include <pwd.h>')
+have_getpwnam_r = cc.has_function('getpwnam_r', prefix: gnu_source_prefix + '#include <pwd.h>')
have_getpwuid = cc.has_function('getpwuid', prefix: '#include <pwd.h>')
have_getopt = cc.has_function('getopt', prefix: '#include <getopt.h>')
have_gettimeofday = cc.has_function('gettimeofday', prefix: '#include <sys/time.h>')
@@ -115,13 +116,13 @@
have_glob = cc.has_function('glob', prefix: '#include <glob.h>')
have_kqueue = cc.has_function('kqueue', prefix: '#include <sys/event.h>')
have_mprotect = cc.has_function('mprotect', prefix: '#include <sys/mman.h>')
-have_nanosleep = cc.has_function('nanosleep', prefix: '#include <time.h>')
+have_nanosleep = cc.has_function('nanosleep', prefix: gnu_source_prefix + '#include <time.h>')
have_select = cc.has_function('select', prefix: '#include <sys/select.h>')
have_snprintf = cc.has_function('snprintf', prefix: '#include <stdio.h>')
-have_strsep = cc.has_function('strsep', prefix: '#include <string.h>')
+have_strsep = cc.has_function('strsep', prefix: gnu_source_prefix + '#include <string.h>')
have_strtold = cc.has_function('strtold', prefix: '#include <stdlib.h>')
have_strtoll = cc.has_function('strtoll', prefix: '#include <stdlib.h>')
-have_vasprintf = cc.has_function('vasprintf', prefix: '#include <stdio.h>')
+have_vasprintf = cc.has_function('vasprintf', prefix: gnu_source_prefix + '#include <stdio.h>')
have_vsnprintf = cc.has_function('vsnprintf', prefix: '#include <stdio.h>')
# Check for the SO_ACCEPTFILTER socket option
@@ -215,7 +216,7 @@
# Check for clock_gettime (may need librt)
librt = cc.find_library('rt', required: false)
-have_clock_gettime = cc.has_function('clock_gettime', prefix: '#include <time.h>', dependencies: librt)
+have_clock_gettime = cc.has_function('clock_gettime', prefix: gnu_source_prefix + '#include <time.h>', dependencies: librt)
# Check for dlopen function (may need libdl)
libdl = cc.find_library('dl', required: false)
@@ -315,7 +316,7 @@
have_long_double = cc.has_type('long double', prefix: '#include <stdlib.h>')
# Check for rand48 functions (drand48, lrand48)
-have_rand48 = cc.has_function('drand48', prefix: '#include <stdlib.h>')
+have_rand48 = cc.has_function('drand48', prefix: gnu_source_prefix + '#include <stdlib.h>')
# Check for getaddrinfo (networking)
have_getaddrinfo = cc.has_function('getaddrinfo', prefix: '#include <netdb.h>')
I have started a new project with agar 1.7.1 as a meson subproject. I installed sdl2 from the official wrabDB, and agar from the source tarball downloaded from the website.
I used Claude code to get my build started, and I needed these patches that - unfortunately - have some GNU-isms