tron@2186: /* $Id$ */ tron@2186: belugas@6451: /** @file endian_check.cpp belugas@6451: * This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN belugas@6451: * it does that by putting a 1 and a 0 in an array, and read it out as one belugas@6451: * number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN belugas@6451: * belugas@6451: * After that it outputs the contents of an include files (endian.h) belugas@6451: * that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes belugas@6451: * care of the real writing to the file. */ belugas@6451: truelight@157: #include rubidium@5838: #include truelight@157: celestar@9908: /** Main call of the endian_check program celestar@9908: * @param argc argument count celestar@9908: * @param argv arguments themselves celestar@9908: * @return exit code */ 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) { belugas@6451: /** adding support for universal binaries on OSX belugas@6451: * Universal binaries supports both PPC and x86 belugas@6451: * 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: }