Skip to contentSkip to conversation

fix _GNU_SOURCE handling & header inclusion

PATCH Applied Mike Frysinger 2 participants 2 messages Oct 9, 2015 – Oct 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix _GNU_SOURCE handling & header inclusion

From: Mike Frysinger <[email protected]>

The configure script blindly adds -D_GNU_SOURCE to all build settings, even on non-GNU systems. This isn't too much of a big deal (even if
it uses the wrong variable -- CFLAGS instead of CPPFLAGS), except that the alsa-lib source itself determines whether to use GNU features when this is defined (such as versionsort). So when we build on non-glibc systems, we get build failures like:
src/ucm/parser.c:1268:18: error: 'versionsort' undeclared (first use in this function)

 #define SORTFUNC versionsort
                  ^
src/ucm/parser.c:1272:54: note: in expansion of macro 'SORTFUNC'
  err = scandir(filename, &namelist, filename_filter, SORTFUNC);
                                                      ^

The correct way to add these flags is to use the autoconf helper AC_USE_SYSTEM_EXTENSIONS. Unfortunately, that triggers some more bugs in the alsa build. This macro adds defines to config.h and not directly to CPPFLAGS, so it relies on files correctly including config.h before anything else. A number of alsa files do not do this leading to build failures. The fix there is to shuffle the includes around so that the local ones come first.

---
 configure.ac               | 4 +---
 src/conf.c                 | 2 +-
 src/timer/timer.c          | 9 ++-------
 src/timer/timer_hw.c       | 6 ------
 src/timer/timer_local.h    | 5 ++---
 src/timer/timer_query.c    | 6 ------
 src/timer/timer_query_hw.c | 6 ------
 src/ucm/ucm_local.h        | 2 +-
 8 files changed, 7 insertions(+), 33 deletions(-)
configure.ac +1 -3
index a14e52d..9cb8614 100644
@@ -27,11 +27,9 @@ AC_PREFIX_DEFAULT(/usr)
 
 dnl Checks for programs.
 
-CFLAGS="$CFLAGS -D_GNU_SOURCE"
-
-
 AC_PROG_CC
 AC_PROG_CPP
+AC_USE_SYSTEM_EXTENSIONS
 AC_PROG_INSTALL
 AC_PROG_LN_S 
 AC_DISABLE_STATIC
src/conf.c +1 -1
index c6a83ee..91fca25 100644
@@ -414,12 +414,12 @@ beginning:</P>
 */
 
 
+#include "local.h"
 #include <stdarg.h>
 #include <limits.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <locale.h>
-#include "local.h"
 #ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
 #endif
src/timer/timer.c +2 -7
index b71a9f8..a25e4f7 100644
@@ -67,15 +67,10 @@ This example shows opening a timer device and reading of timer events.
  * \anchor example_test_timer
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
+#include <signal.h>
+
 static int snd_timer_open_conf(snd_timer_t **timer,
 			       const char *name, snd_config_t *timer_root,
 			       snd_config_t *timer_conf, int mode)
src/timer/timer_hw.c +0 -6
index e833fc8..e61b994 100644
@@ -19,12 +19,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 #ifndef PIC
src/timer/timer_local.h +2 -3
index 8040b05..eef3b06 100644
@@ -19,10 +19,9 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
 #include "local.h"
+#include <limits.h>
+#include <sys/ioctl.h>
 
 #ifndef DOC_HIDDEN
 typedef struct {
src/timer/timer_query.c +0 -6
index 50b098a..93d2455 100644
@@ -26,12 +26,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 static int snd_timer_query_open_conf(snd_timer_query_t **timer,
src/timer/timer_query_hw.c +0 -6
index 289ca52..d0c4391 100644
@@ -19,12 +19,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 #ifndef PIC
src/ucm/ucm_local.h +1 -1
index c1655c7..3a5d2c2 100644
@@ -36,8 +36,8 @@
 #define UC_MGR_DEBUG
 #endif
 
-#include <pthread.h>
 #include "local.h"
+#include <pthread.h>
 #include "use-case.h"
 
 #define MAX_FILE		256
Signature · 1 line
2.5.2
Applied
#1 lore raw
Quoted 24 lines · Mike Frysinger

From: Mike Frysinger <[email protected]>

The configure script blindly adds -D_GNU_SOURCE to all build settings, even on non-GNU systems. This isn't too much of a big deal (even if
it uses the wrong variable -- CFLAGS instead of CPPFLAGS), except that the alsa-lib source itself determines whether to use GNU features when this is defined (such as versionsort). So when we build on non-glibc systems, we get build failures like:
src/ucm/parser.c:1268:18: error: 'versionsort' undeclared (first use in this function)

 #define SORTFUNC versionsort
                  ^
src/ucm/parser.c:1272:54: note: in expansion of macro 'SORTFUNC'
  err = scandir(filename, &namelist, filename_filter, SORTFUNC);
                                                      ^

The correct way to add these flags is to use the autoconf helper AC_USE_SYSTEM_EXTENSIONS. Unfortunately, that triggers some more bugs in the alsa build. This macro adds defines to config.h and not directly to CPPFLAGS, so it relies on files correctly including config.h before anything else. A number of alsa files do not do this leading to build failures. The fix there is to shuffle the includes around so that the local ones come first.

Quoted 1 line

Thanks, applied now.

Takashi

Quoted 158 lines
---
 configure.ac               | 4 +---
 src/conf.c                 | 2 +-
 src/timer/timer.c          | 9 ++-------
 src/timer/timer_hw.c       | 6 ------
 src/timer/timer_local.h    | 5 ++---
 src/timer/timer_query.c    | 6 ------
 src/timer/timer_query_hw.c | 6 ------
 src/ucm/ucm_local.h        | 2 +-
 8 files changed, 7 insertions(+), 33 deletions(-)
configure.ac +1 -3
index a14e52d..9cb8614 100644
@@ -27,11 +27,9 @@ AC_PREFIX_DEFAULT(/usr)
 
 dnl Checks for programs.
 
-CFLAGS="$CFLAGS -D_GNU_SOURCE"
-
-
 AC_PROG_CC
 AC_PROG_CPP
+AC_USE_SYSTEM_EXTENSIONS
 AC_PROG_INSTALL
 AC_PROG_LN_S 
 AC_DISABLE_STATIC
src/conf.c +1 -1
index c6a83ee..91fca25 100644
@@ -414,12 +414,12 @@ beginning:</P>
 */
 
 
+#include "local.h"
 #include <stdarg.h>
 #include <limits.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <locale.h>
-#include "local.h"
 #ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
 #endif
src/timer/timer.c +2 -7
index b71a9f8..a25e4f7 100644
@@ -67,15 +67,10 @@ This example shows opening a timer device and reading of timer events.
  * \anchor example_test_timer
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
+#include <signal.h>
+
 static int snd_timer_open_conf(snd_timer_t **timer,
 			       const char *name, snd_config_t *timer_root,
 			       snd_config_t *timer_conf, int mode)
src/timer/timer_hw.c +0 -6
index e833fc8..e61b994 100644
@@ -19,12 +19,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 #ifndef PIC
src/timer/timer_local.h +2 -3
index 8040b05..eef3b06 100644
@@ -19,10 +19,9 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
 #include "local.h"
+#include <limits.h>
+#include <sys/ioctl.h>
 
 #ifndef DOC_HIDDEN
 typedef struct {
src/timer/timer_query.c +0 -6
index 50b098a..93d2455 100644
@@ -26,12 +26,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 static int snd_timer_query_open_conf(snd_timer_query_t **timer,
src/timer/timer_query_hw.c +0 -6
index 289ca52..d0c4391 100644
@@ -19,12 +19,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include "timer_local.h"
 
 #ifndef PIC
src/ucm/ucm_local.h +1 -1
index c1655c7..3a5d2c2 100644
@@ -36,8 +36,8 @@
 #define UC_MGR_DEBUG
 #endif
 
-#include <pthread.h>
 #include "local.h"
+#include <pthread.h>
 #include "use-case.h"
 
 #define MAX_FILE		256
Signature · 6 lines
2.5.2

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel