tron@2186: /* $Id$ */ tron@2186: truelight@157: #include truelight@157: truelight@157: // This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN truelight@157: // it does that by putting a 1 and a 0 in an array, and read it out as one truelight@200: // number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN truelight@157: // truelight@157: // After that it outputs the contents of an include files (endian.h) truelight@157: // that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes truelight@157: // care of the real writing to the file. truelight@157: TrueLight@1692: int main (int argc, char *argv[]) { bjarni@2713: unsigned char EndianTest[2] = { 1, 0 }; bjarni@2719: int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0; TrueLight@1692: bjarni@2713: if (argc > 1 && strcmp(argv[1], "BE") == 0) bjarni@2713: force_BE = 1; bjarni@2713: if (argc > 1 && strcmp(argv[1], "LE") == 0) bjarni@2713: force_LE = 1; bjarni@2719: if (argc > 1 && strcmp(argv[1], "PREPROCESSOR") == 0) bjarni@2719: force_PREPROCESSOR = 1; TrueLight@1692: bjarni@2713: printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n"); truelight@157: bjarni@2713: if (force_LE == 1) { bjarni@2713: printf("#define TTD_LITTLE_ENDIAN\n"); bjarni@2713: } else { bjarni@2713: if (force_BE == 1) { bjarni@2713: printf("#define TTD_BIG_ENDIAN\n"); bjarni@2713: } else { bjarni@2719: if (force_PREPROCESSOR == 1) { bjarni@2719: // adding support for universal binaries on OSX bjarni@2719: // Universal binaries supports both PPC and x86 bjarni@2719: // If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed bjarni@2719: printf("#ifdef __BIG_ENDIAN__\n"); bjarni@2719: printf("#define TTD_BIG_ENDIAN\n"); bjarni@2719: printf("#else\n"); bjarni@2713: printf("#define TTD_LITTLE_ENDIAN\n"); bjarni@2719: printf("#endif\n"); bjarni@2719: } else { bjarni@2719: if ( *(short *) EndianTest == 1 ) bjarni@2719: printf("#define TTD_LITTLE_ENDIAN\n"); bjarni@2719: else bjarni@2719: printf("#define TTD_BIG_ENDIAN\n"); bjarni@2719: } bjarni@2713: } bjarni@2713: } bjarni@2713: printf("#endif\n"); truelight@157: bjarni@2713: return 0; truelight@157: }