shithub: ft²

Download patch

ref: 9771bea8f50c7416fed2b380db92c00622c2faa3
parent: f0cc39bf0859cec692fbad1431b2c176fb14b4fb
author: Emanuel Haupt <ehaupt@critical.ch>
date: Tue Sep 9 04:23:41 EDT 2025

Fix build on FreeBSD by guarding <features.h> include

<features.h> is glibc-specific and not available on FreeBSD or other
non-Linux systems. The musl/glibc detection logic in ft2_unicode.c was
previously enabled for all non-Windows and non-Apple platforms, which
caused build failures on FreeBSD.

Restrict the probe to Linux only and use __has_include(<features.h>) to
safely include it. This preserves musl/glibc detection on Linux while
allowing FreeBSD and other non-Linux systems to build successfully.

--- a/src/ft2_unicode.c
+++ b/src/ft2_unicode.c
@@ -4,20 +4,21 @@
 #endif
 
 // for detecting if musl or glibc is used
-#if !defined _WIN32 && !defined __APPLE__
-	#ifndef _GNU_SOURCE
-		#define _GNU_SOURCE
-	  #include <features.h>
-	  #ifndef __USE_GNU
-	      #define __MUSL__
-	  #endif
-	  #undef _GNU_SOURCE /* don't contaminate other includes unnecessarily */
-	#else
-	  #include <features.h>
-	  #ifndef __USE_GNU
-	      #define __MUSL__
-	  #endif
-	#endif
+#if defined(__linux__)
+  /* Only Linux has glibc's <features.h>. On BSDs (including FreeBSD) and others,
+     skip this block to avoid a missing-header error. */
+  #ifdef __has_include
+    #if __has_include(<features.h>)
+      #include <features.h>
+    #endif
+  #else
+    /* If the compiler doesn't support __has_include, assume features.h exists on glibc. */
+    #include <features.h>
+  #endif
+  /* If <features.h> didn't define glibc's GNU extensions, assume musl. */
+  #ifndef __USE_GNU
+    #define __MUSL__
+  #endif
 #endif
 
 #include <stdlib.h>
--