This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] GNU/k*BSD support (with ChangeLog) for gcc


On Fri, Mar 19, 2004 at 08:14:52AM -0800, David O'Brien wrote:
> On Tue, Mar 16, 2004 at 10:06:58PM +0100, Robert Millan wrote:
> > Yes. __FreeBSD__ implies a FreeBSD kernel, but it does also imply FreeBSD
> > userland and, most importantly, FreeBSD linker and FreeBSD C library.
> > Thus, it is reasonable that many programs use __FreeBSD__ to check for
> > FreeBSD C library or FreeBSD dynamic linker.
> > 
> > Our system, however, uses GNU libc and not FreeBSD libc. The only component
> > it shares with FreeBSD is the kernel. Therefore, we need a new macro for
> > the kernel, that can be shared with pure FreeBSD systems, but is not tied
> > to other userland components like __FreeBSD__ is.
> 
> Hi Robert,
> 
> I'm sorry, but I still don't see the need for an additional symbol to
> __FreeBSD__.  Can you show a small example of why it is needed?

Yes. __FreeBSD__ is used to check for any particular component of the FreeBSD
system. Sometimes, programs use __FreeBSD__ to check for the kernel of FreeBSD:

  #ifdef __FreeBSD__
  [ code specific to kernel of FreeBSD ]
  #endif

Our system, known as "GNU/kFreeBSD", is not FreeBSD. It does, however, use
the kernel of FreeBSD. So if we want the code to work on both systems, it'd
have to look like:

  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
  [ code specific to kernel of FreeBSD ]
  #endif

If FreeBSD systems defined __FreeBSD_kernel__, the check would become simpler
and more readable. That's why in some situations I added this kludge:

  #if defined(__FreeBSD__) && ! defined(__FreeBSD_kernel__)
  #define __FreeBSD_kernel__ __FreeBSD__
  #endif

So that later checks are simplified to:

  #ifdef __FreeBSD_kernel__
  [ code specific to kernel of FreeBSD ]
  #endif

But that kludge is sub-optimal. The correct place to define such macro is
GCC. When GCC defines __FreeBSD_kernel__ on FreeBSD systems too, then
eventualy the kludge will become unnecessary.

I hope my explanation satisfies you. If you need some real examples I can
provide them to you, but that'll take some research.

-- 
Robert Millan

"[..] but the delight and pride of Aule is in the deed of making, and in the
thing made, and neither in possession nor in his own mastery; wherefore he
gives and hoards not, and is free from care, passing ever on to some new work."

 -- J.R.R.T., Ainulindale (Silmarillion)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]