blob: ea2983d30f859b00bd12125311c0cc769455084f [file] [log] [blame]
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +00001/*
2 Copyright 2006, Bernhard Fischer
3
4 Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
5*/
6#ifndef __PLATFORM_H
7#define __PLATFORM_H 1
8
9/* Convenience macros to test the version of gcc. */
10#undef __GNUC_PREREQ
11#if defined __GNUC__ && defined __GNUC_MINOR__
12# define __GNUC_PREREQ(maj, min) \
13 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
14#else
15# define __GNUC_PREREQ(maj, min) 0
16#endif
17
18/* __restrict is known in EGCS 1.2 and above. */
19#if !__GNUC_PREREQ (2,92)
20# ifndef __restrict
21# define __restrict /* Ignore */
22# endif
23#endif
24
25/* Define macros for some gcc attributes. This permits us to use the
26 macros freely, and know that they will come into play for the
27 version of gcc in which they are supported. */
28
29#if !__GNUC_PREREQ (2,7)
30# ifndef __attribute__
31# define __attribute__(x)
32# endif
33#endif
34
35#if 0
36/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
37#ifndef ATTRIBUTE_MALLOC
38# if __GNUC_PREREQ (2,96)
39# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
40# else
41# define ATTRIBUTE_MALLOC
42# endif /* GNUC >= 2.96 */
43#endif /* ATTRIBUTE_MALLOC */
44#endif
45
46#ifndef ATTRIBUTE_UNUSED
Mike Frysingerf8855132006-03-28 02:35:56 +000047# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000048#endif /* ATTRIBUTE_UNUSED */
49
50#ifndef ATTRIBUTE_NORETURN
Mike Frysingerf8855132006-03-28 02:35:56 +000051# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000052#endif /* ATTRIBUTE_NORETURN */
53
54#ifndef ATTRIBUTE_PACKED
Mike Frysingerf8855132006-03-28 02:35:56 +000055# define ATTRIBUTE_PACKED __attribute__ ((__packed__))
Mike Frysinger64bef2a2006-03-23 02:06:29 +000056#endif /* ATTRIBUTE_PACKED */
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000057
Bernhard Reutner-Fischer9f4a1e12006-01-31 09:53:53 +000058#ifndef ATTRIBUTE_ALIGNED
Mike Frysingerf8855132006-03-28 02:35:56 +000059# define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m)))
Bernhard Reutner-Fischer9f4a1e12006-01-31 09:53:53 +000060#endif /* ATTRIBUTE_ALIGNED */
61
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000062/* -fwhole-program makes all symbols local. The attribute externally_visible
63 forces a symbol global. */
64#ifndef ATTRIBUTE_EXTERNALLY_VISIBLE
65# if __GNUC_PREREQ (4,1)
Mike Frysingerf8855132006-03-28 02:35:56 +000066# define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__))
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000067# else
Mike Frysingerf8855132006-03-28 02:35:56 +000068# define ATTRIBUTE_EXTERNALLY_VISIBLE
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000069# endif /* GNUC >= 4.1 */
70#endif /* ATTRIBUTE_EXTERNALLY_VISIBLE */
71
72/* We use __extension__ in some places to suppress -pedantic warnings
73 about GCC extensions. This feature didn't work properly before
74 gcc 2.8. */
75#if !__GNUC_PREREQ (2,8)
76# ifndef __extension__
77# define __extension__
78# endif
79#endif
80
Rob Landley5cf7c2d2006-02-21 06:44:43 +000081/* ---- Endian Detection ------------------------------------ */
82#ifndef __APPLE__
Mike Frysingerf8855132006-03-28 02:35:56 +000083# include <byteswap.h>
84# include <endian.h>
Rob Landley5cf7c2d2006-02-21 06:44:43 +000085#endif
86
87#ifdef __BIG_ENDIAN__
Mike Frysingerf8855132006-03-28 02:35:56 +000088# define BB_BIG_ENDIAN 1
89# define BB_LITTLE_ENDIAN 0
Rob Landley5cf7c2d2006-02-21 06:44:43 +000090#elif __BYTE_ORDER == __BIG_ENDIAN
Mike Frysingerf8855132006-03-28 02:35:56 +000091# define BB_BIG_ENDIAN 1
92# define BB_LITTLE_ENDIAN 0
Bernhard Reutner-Fischered7bb622006-02-23 14:25:15 +000093#else
Mike Frysingerf8855132006-03-28 02:35:56 +000094# define BB_BIG_ENDIAN 0
95# define BB_LITTLE_ENDIAN 1
Rob Landley5cf7c2d2006-02-21 06:44:43 +000096#endif
97
Rob Landleydae6aa22006-03-09 22:39:08 +000098/* ---- Networking ------------------------------------------ */
99#ifndef __APPLE__
Mike Frysingerf8855132006-03-28 02:35:56 +0000100# include <arpa/inet.h>
Rob Landleydae6aa22006-03-09 22:39:08 +0000101#else
Mike Frysingerf8855132006-03-28 02:35:56 +0000102# include <netinet/in.h>
Rob Landleydae6aa22006-03-09 22:39:08 +0000103#endif
104
Bernhard Reutner-Fischered7bb622006-02-23 14:25:15 +0000105/* ---- miscellaneous --------------------------------------- */
106/* NLS stuff */
Rob Landleydae6aa22006-03-09 22:39:08 +0000107/* THIS SHOULD BE CLEANED OUT OF THE TREE ENTIRELY */
Bernhard Reutner-Fischered7bb622006-02-23 14:25:15 +0000108#define _(Text) Text
109#define N_(Text) (Text)
Rob Landley5cf7c2d2006-02-21 06:44:43 +0000110
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +0000111#endif /* platform.h */