Skip to contentSkip to conversation

Define -D__BSD_VISIBLE for FreeBSD

PATCH In review Rocco Rutte 2 participants 4 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Define -D__BSD_VISIBLE for FreeBSD

FreeBSD (6-STABLE) "hides" many declarations (like fchmod(), IPPROTO_IPV6, etc.) within '#ifdef __BSD_VISIBLE' blocks. Without this flag, compilation will produce lots of warnings and will even fail to compile daemon.c since IPPROTO_IPV6 isn't available without it.

Quoted 1 line

From looking at some include files of OpenBSD and NetBSD (via cvsweb)

they don't seem to need this flag.

---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index 7651104..46c49e0 100644
@@ -366,7 +366,7 @@ ifeq ($(uname_O),Cygwin)
 endif
 ifeq ($(uname_S),FreeBSD)
 	NEEDS_LIBICONV = YesPlease
-	BASIC_CFLAGS += -I/usr/local/include
+	BASIC_CFLAGS += -I/usr/local/include -D__BSD_VISIBLE
 	BASIC_LDFLAGS += -L/usr/local/lib
 endif
 ifeq ($(uname_S),OpenBSD)
Signature · 1 line
1.4.4.2.g9474f
#1 lore raw
Quoted 4 lines · Rocco Rutte

FreeBSD (6-STABLE) "hides" many declarations (like fchmod(), IPPROTO_IPV6, etc.) within '#ifdef __BSD_VISIBLE' blocks. Without this flag, compilation will produce lots of warnings and will even fail to compile daemon.c since IPPROTO_IPV6 isn't available without it.

I've looked at OpenBSD header files and my impression was that the symbol __BSD_VISIBLE was pretty much internal to the implementation, and the programs are not expected to set it except by defining more public feature macros, such as _BSD_SOURCE. So I feel a bit uneasy about your approach.

We've changed this exact area quite heavily during the last 24-hours (not in Makefile but in git-compat-util.h). Do you see the problem with the latest 'master'?

#2 lore raw

PATCH 1/1 Don't define _XOPEN_SOURCE to unbreak compilation on FreeBSD

FreeBSD 6 requires the __BSD_VISIBLE flag for fchmod(), IPPROTO_IPV6 and more which is only properly set by <sys/cdefs.h> if _POSIX_C_SOURCE isn't present. However, _POSIX_C_SOURCE is defined if _XOPEN_SOURCE is defined and >=500.

As a solution, simply don't define _XOPEN_SOURCE for FreeBSD and continue with its defaults.

---
 git-compat-util.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
git-compat-util.h +6 -1
index bc296b3..27d3b89 100644
@@ -11,7 +11,12 @@
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
-#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
+#if !defined(__FreeBSD__)
+#define _XOPEN_SOURCE 600        /* glibc2 and AIX 5.3L need 500,
+                                  * OpenBSD needs 600 for S_ISLNK(),
+                                  * FreeBSD 6 doesn't like it
+                                  */
+#endif
 #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
 #define _GNU_SOURCE
 #define _BSD_SOURCE
Signature · 1 line
1.4.4.2.g9474f
#3 lore raw
In reply to Junio C Hamano

Hi,

Quoted 3 lines · Junio C Hamano

We've changed this exact area quite heavily during the last 24-hours (not in Makefile but in git-compat-util.h). Do you see the problem with the latest 'master'?

Now when looking at sys/cdefs.h, the 85023577a8f4b540aa64aa37f6f44578c0c305a3 commit seems to have broken things. So the patch should be ignored and I'll try to come up with a better one not using implementation-defined __-macros...

bye, Rocco

Signature · 1 line
:wq!