Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 1 | /* |
| 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 Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 47 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 48 | #endif /* ATTRIBUTE_UNUSED */ |
| 49 | |
| 50 | #ifndef ATTRIBUTE_NORETURN |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 51 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 52 | #endif /* ATTRIBUTE_NORETURN */ |
| 53 | |
| 54 | #ifndef ATTRIBUTE_PACKED |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 55 | # define ATTRIBUTE_PACKED __attribute__ ((__packed__)) |
Mike Frysinger | 64bef2a | 2006-03-23 02:06:29 +0000 | [diff] [blame] | 56 | #endif /* ATTRIBUTE_PACKED */ |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 57 | |
Bernhard Reutner-Fischer | 9f4a1e1 | 2006-01-31 09:53:53 +0000 | [diff] [blame] | 58 | #ifndef ATTRIBUTE_ALIGNED |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 59 | # define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m))) |
Bernhard Reutner-Fischer | 9f4a1e1 | 2006-01-31 09:53:53 +0000 | [diff] [blame] | 60 | #endif /* ATTRIBUTE_ALIGNED */ |
| 61 | |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 62 | /* -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 Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 66 | # define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__)) |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 67 | # else |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 68 | # define ATTRIBUTE_EXTERNALLY_VISIBLE |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 69 | # 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 Landley | 5cf7c2d | 2006-02-21 06:44:43 +0000 | [diff] [blame] | 81 | /* ---- Endian Detection ------------------------------------ */ |
| 82 | #ifndef __APPLE__ |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 83 | # include <byteswap.h> |
| 84 | # include <endian.h> |
Rob Landley | 5cf7c2d | 2006-02-21 06:44:43 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
| 87 | #ifdef __BIG_ENDIAN__ |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 88 | # define BB_BIG_ENDIAN 1 |
| 89 | # define BB_LITTLE_ENDIAN 0 |
Rob Landley | 5cf7c2d | 2006-02-21 06:44:43 +0000 | [diff] [blame] | 90 | #elif __BYTE_ORDER == __BIG_ENDIAN |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 91 | # define BB_BIG_ENDIAN 1 |
| 92 | # define BB_LITTLE_ENDIAN 0 |
Bernhard Reutner-Fischer | ed7bb62 | 2006-02-23 14:25:15 +0000 | [diff] [blame] | 93 | #else |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 94 | # define BB_BIG_ENDIAN 0 |
| 95 | # define BB_LITTLE_ENDIAN 1 |
Rob Landley | 5cf7c2d | 2006-02-21 06:44:43 +0000 | [diff] [blame] | 96 | #endif |
| 97 | |
Rob Landley | dae6aa2 | 2006-03-09 22:39:08 +0000 | [diff] [blame] | 98 | /* ---- Networking ------------------------------------------ */ |
| 99 | #ifndef __APPLE__ |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 100 | # include <arpa/inet.h> |
Rob Landley | dae6aa2 | 2006-03-09 22:39:08 +0000 | [diff] [blame] | 101 | #else |
Mike Frysinger | f885513 | 2006-03-28 02:35:56 +0000 | [diff] [blame] | 102 | # include <netinet/in.h> |
Rob Landley | dae6aa2 | 2006-03-09 22:39:08 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
Bernhard Reutner-Fischer | ed7bb62 | 2006-02-23 14:25:15 +0000 | [diff] [blame] | 105 | /* ---- miscellaneous --------------------------------------- */ |
| 106 | /* NLS stuff */ |
Rob Landley | dae6aa2 | 2006-03-09 22:39:08 +0000 | [diff] [blame] | 107 | /* THIS SHOULD BE CLEANED OUT OF THE TREE ENTIRELY */ |
Bernhard Reutner-Fischer | ed7bb62 | 2006-02-23 14:25:15 +0000 | [diff] [blame] | 108 | #define _(Text) Text |
| 109 | #define N_(Text) (Text) |
Rob Landley | 5cf7c2d | 2006-02-21 06:44:43 +0000 | [diff] [blame] | 110 | |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 111 | #endif /* platform.h */ |