[PATCH] __FreeBSD_kernel__

Robert Millan rmh at debian.org
Sat Jul 2 15:41:04 UTC 2011


Since their inception, GNU/kFreeBSD systems had defined
"__FreeBSD_kernel__" as builtin macro to indicate this is a system
that uses the kernel of FreeBSD.  We couldn't define "__FreeBSD__"
because this implies a full FreeBSD system, and a lot of software
checks for this macro when it is concerned with userland (usually
libc).

As a result of this, and of the considerable porting effort that
followed, many 3rd party programs with kernel-specific extensions have
been ported to recognize __FreeBSD_kernel__ as well. E.g.:

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
// code for FreeBSD kernel
#endif

My request is that FreeBSD also defines __FreeBSD_kernel__.  If this
happens, life would be made a bit easier on both sides, as it'd be
more natural for porters of either system to support both using a
single macro [1].

[1] When porting software to support FreeBSD and systems with kernel
of FreeBSD myself (as I did with e.g. GRUB), I generally took care to
ensure both macros are checked for, but this isn't always the case.
Having a unified macro would make it easier for developers of both
systems to cooperate.

-- 
Robert Millan
-------------- next part --------------
Index: contrib/gcc/config/freebsd-spec.h
===================================================================
--- contrib/gcc/config/freebsd-spec.h	(revision 223721)
+++ contrib/gcc/config/freebsd-spec.h	(working copy)
@@ -54,6 +54,7 @@
   do									\
     {									\
 	builtin_define_with_int_value ("__FreeBSD__", FBSD_MAJOR);	\
+	builtin_define ("__FreeBSD_kernel__");				\
 	builtin_define_std ("unix");					\
 	builtin_define_std ("__unix__");				\
 	builtin_define ("__KPRINTF_ATTRIBUTE__");			\


More information about the freebsd-hackers mailing list