[PATCH] __FreeBSD_kernel__

Alexander Kabaev kabaev at gmail.com
Sun Jul 3 14:35:40 UTC 2011


On Sat, 2 Jul 2011 20:05:12 -0700
Garrett Cooper <yanegomi at gmail.com> wrote:

> On Sat, Jul 2, 2011 at 7:08 PM, Ed Maste <emaste at freebsd.org> wrote:
> > On Sat, Jul 02, 2011 at 07:37:24PM -0400, Alexander Kabaev wrote:
> >
> >> On Sat, 2 Jul 2011 17:41:03 +0200
> >> Robert Millan <rmh at debian.org> wrote:
> >>
> >> > 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].
> >
> > I think this is a good idea, especially if it means that a single
> > change can make it into upstream projects to support both FreeBSD
> > and Debian kFreeBSD.
> >
> >> I do not think this belongs in GCC at all. You should already have
> >> a defined symbol to identify your OS and that should be used in
> >> cases where it matters.
> >
> > I suspect the proposed patch put it in GCC based on the fact that we
> > already have __FreeBSD__ in contrib/gcc/config/freebsd-spec.h:
> >        builtin_define_with_int_value ("__FreeBSD__", FBSD_MAJOR);
> >    \
> >
> >> Alternatively, you should provide the symbol in
> >> similar way in which we provide __FreeBSD_version, through
> >> well-known header like sys/param.h and not pollute GCC.
> >
> > I suspect this is probably a reasonable alternative, but may mean
> > software will have to pick up an additional #include.
> >
> > Out of curiosity, what is the canonical way for software to
> > identify a Linux kernel -- __linux__ or some variant?  Where is it
> > defined?
> 
> linux is most often reliably defined value based on my personal
> experience and it's defined in gcc [look for
> `builtin_define.*("linux");' (note: this is a regexp..)]. Example:
> 
> $ echo '' | gcc -E -xc -dM -c - 2>&1 | grep linux
> #define __linux 1
> #define __linux__ 1
> #define __gnu_linux__ 1
> #define linux 1
> 
> HTH,
> -Garrett

__linux__ is exactly what __FreeBSD__ is and dies not identify kernel
but rather Linux as whole OS, whatever that might be these days.

There does not appear to be an universal macro that identifies
environment as using Linux kernel regardless of the rest of components
used (say, to identify Android and Ubuntu or something embedded with
ucLibc as running Linux kernel with different userland
implementations).
-- 
Alexander Kabaev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20110703/e2c7e594/signature.pgp


More information about the freebsd-hackers mailing list