int set_arch(const char *pers, unsigned long options) { struct utsname un; int i; unsigned long pers_value; struct { int perval; const char *target_arch, *result_arch; } transitions[] = { {PER_LINUX32, "linux32", NULL}, {PER_LINUX, "linux64", NULL}, #if defined(__powerpc__) || defined(__powerpc64__) {PER_LINUX32, "ppc32", "ppc"}, {PER_LINUX32, "ppc", "ppc"}, {PER_LINUX, "ppc64", "ppc64"}, {PER_LINUX, "ppc64pseries", "ppc64"}, {PER_LINUX, "ppc64iseries", "ppc64"}, #endif #if defined(__x86_64__) || defined(__i386__) || defined(__ia64__) {PER_LINUX32, "i386", "i386"}, {PER_LINUX32, "i486", "i386"}, {PER_LINUX32, "i586", "i386"}, {PER_LINUX32, "i686", "i386"}, {PER_LINUX32, "athlon", "i386"}, #endif #if defined(__x86_64__) || defined(__i386__) {PER_LINUX, "x86_64", "x86_64"}, #endif #if defined(__ia64__) || defined(__i386__) {PER_LINUX, "ia64", "ia64"}, #endif #if defined(__hppa__) {PER_LINUX32, "parisc32", "parisc"}, {PER_LINUX32, "parisc", "parisc"}, {PER_LINUX, "parisc64", "parisc64"}, #endif #if defined(__s390x__) || defined(__s390__) {PER_LINUX32, "s390", "s390"}, {PER_LINUX, "s390x", "s390x"}, #endif #if defined(__sparc64__) || defined(__sparc__) {PER_LINUX32, "sparc", "sparc"}, {PER_LINUX32, "sparc32bash", "sparc"}, {PER_LINUX32, "sparc32", "sparc"}, {PER_LINUX, "sparc64", "sparc64"}, #endif #if defined(__mips64__) || defined(__mips__) {PER_LINUX32, "mips32", "mips"}, {PER_LINUX32, "mips", "mips"}, {PER_LINUX, "mips64", "mips64"}, #endif #if defined(__alpha__) {PER_LINUX, "alpha", "alpha"}, {PER_LINUX, "alphaev5", "alpha"}, {PER_LINUX, "alphaev56", "alpha"}, {PER_LINUX, "alphaev6", "alpha"}, {PER_LINUX, "alphaev67", "alpha"}, #endif {-1, NULL, NULL} }; for(i = 0; transitions[i].perval >= 0; i++) if(!strcmp(pers, transitions[i].target_arch)) break; if(transitions[i].perval < 0) errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers); pers_value = transitions[i].perval | options; if (set_pers(pers_value) == -EINVAL) return 1; uname(&un); if(transitions[i].result_arch && strcmp(un.machine, transitions[i].result_arch)) { if(strcmp(transitions[i].result_arch, "i386") || (strcmp(un.machine, "i486") && strcmp(un.machine, "i586") && strcmp(un.machine, "i686") && strcmp(un.machine, "athlon"))) errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers); } return 0; }
static int set_arch(const char *pers, unsigned long options, int list) { struct utsname un; int i; unsigned long pers_value; struct { int perval; const char *target_arch, *result_arch; } transitions[] = { {UNAME26, "uname26", NULL}, {PER_LINUX32, "linux32", NULL}, {PER_LINUX, "linux64", NULL}, #if defined(__powerpc__) || defined(__powerpc64__) #ifdef __BIG_ENDIAN__ {PER_LINUX32, "ppc32", "ppc"}, {PER_LINUX32, "ppc", "ppc"}, {PER_LINUX, "ppc64", "ppc64"}, {PER_LINUX, "ppc64pseries", "ppc64"}, {PER_LINUX, "ppc64iseries", "ppc64"}, #else {PER_LINUX32, "ppc32le", "ppcle"}, {PER_LINUX32, "ppcle", "ppcle"}, {PER_LINUX, "ppc64le", "ppc64le"}, #endif #endif #if defined(__x86_64__) || defined(__i386__) || defined(__ia64__) {PER_LINUX32, "i386", "i386"}, {PER_LINUX32, "i486", "i386"}, {PER_LINUX32, "i586", "i386"}, {PER_LINUX32, "i686", "i386"}, {PER_LINUX32, "athlon", "i386"}, #endif #if defined(__x86_64__) || defined(__i386__) {PER_LINUX, "x86_64", "x86_64"}, #endif #if defined(__ia64__) || defined(__i386__) {PER_LINUX, "ia64", "ia64"}, #endif #if defined(__hppa__) {PER_LINUX32, "parisc32", "parisc"}, {PER_LINUX32, "parisc", "parisc"}, {PER_LINUX, "parisc64", "parisc64"}, #endif #if defined(__s390x__) || defined(__s390__) {PER_LINUX32, "s390", "s390"}, {PER_LINUX, "s390x", "s390x"}, #endif #if defined(__sparc64__) || defined(__sparc__) {PER_LINUX32, "sparc", "sparc"}, {PER_LINUX32, "sparc32bash", "sparc"}, {PER_LINUX32, "sparc32", "sparc"}, {PER_LINUX, "sparc64", "sparc64"}, #endif #if defined(__mips64__) || defined(__mips__) {PER_LINUX32, "mips32", "mips"}, {PER_LINUX32, "mips", "mips"}, {PER_LINUX, "mips64", "mips64"}, #endif #if defined(__alpha__) {PER_LINUX, "alpha", "alpha"}, {PER_LINUX, "alphaev5", "alpha"}, {PER_LINUX, "alphaev56", "alpha"}, {PER_LINUX, "alphaev6", "alpha"}, {PER_LINUX, "alphaev67", "alpha"}, #endif {-1, NULL, NULL}, /* place holder, eventually filled up at runtime */ {-1, NULL, NULL} }; /* Add the trivial transition {PER_LINUX, machine, machine} if no such target_arch is hardcoded yet. */ uname(&un); for (i = 0; transitions[i].perval >= 0; i++) if(!strcmp(un.machine, transitions[i].target_arch)) break; if (transitions[i].perval < 0) { unsigned long wrdsz = CHAR_BIT * sizeof(void*); if (wrdsz == 32 || wrdsz == 64) { transitions[i].perval = wrdsz == 32 ? PER_LINUX32 : PER_LINUX; transitions[i].target_arch = un.machine; transitions[i].result_arch = un.machine; } } if (list) { for(i = 0; transitions[i].target_arch != NULL; i++) printf("%s\n", transitions[i].target_arch); return 0; } for(i = 0; transitions[i].perval >= 0; i++) if(!strcmp(pers, transitions[i].target_arch)) break; if(transitions[i].perval < 0) errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers); pers_value = transitions[i].perval | options; if (set_pers(pers_value) == -EINVAL) return 1; uname(&un); if(transitions[i].result_arch && strcmp(un.machine, transitions[i].result_arch)) { if(strcmp(transitions[i].result_arch, "i386") || (strcmp(un.machine, "i486") && strcmp(un.machine, "i586") && strcmp(un.machine, "i686") && strcmp(un.machine, "athlon"))) errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers); } return 0; }