4 #if defined(__linux__) && defined(__powerpc__)
8 #include <ctype.h> /* XXX for /etc/rpm/platform contents */
10 #if HAVE_SYS_SYSTEMCFG_H
11 #include <sys/systemcfg.h>
13 #define __power_pc() 0
16 #include <rpm/rpmlib.h> /* RPM_MACTABLE*, Rc-prototypes */
17 #include <rpm/rpmmacro.h>
18 #include <rpm/rpmfileutil.h>
19 #include <rpm/rpmstring.h>
20 #include <rpm/rpmlog.h>
22 #include "rpmio/rpmlua.h"
23 #include "rpmio/rpmio_internal.h" /* XXX for rpmioSlurp */
27 static const char * const defrcfiles =
29 ":" RPMCONFIGDIR "/" RPMCANONVENDOR "/rpmrc"
30 ":" SYSCONFDIR "/rpmrc"
33 const char * macrofiles =
35 RPMCONFIGDIR "/macros"
36 ":" RPMCONFIGDIR "/platform/%{_target}/macros"
37 ":" SYSCONFDIR "/rpm/macros.*"
38 ":" SYSCONFDIR "/rpm/macros"
39 ":" SYSCONFDIR "/rpm/%{_target}/macros"
45 static const char * const platform = SYSCONFDIR "/rpm/platform";
46 static char ** platpat = NULL;
47 static int nplatpat = 0;
49 typedef char * cptr_t;
51 typedef struct machCacheEntry_s {
58 typedef struct machCache_s {
63 typedef struct machEquivInfo_s {
68 typedef struct machEquivTable_s {
75 /* eventually, this arch will be replaced with a generic condition */
77 struct rpmvarValue * next;
87 struct rpmOptionValue * value;
90 typedef struct defaultEntry_s {
95 typedef struct canonEntry_s {
101 /* tags are 'key'canon, 'key'translate, 'key'compat
103 * for giggles, 'key'_canon, 'key'_compat, and 'key'_canon will also work
105 typedef struct tableType_s {
108 const int hasTranslate;
109 struct machEquivTable_s equiv;
110 struct machCache_s cache;
111 defaultEntry defaults;
117 static struct tableType_s tables[RPM_MACHTABLE_COUNT] = {
120 { "buildarch", 0, 1 },
124 /* XXX get rid of this stuff... */
125 /* Stuff for maintaining "variables" like SOURCEDIR, BUILDDIR, etc */
126 #define RPMVAR_OPTFLAGS 3
127 #define RPMVAR_INCLUDE 43
128 #define RPMVAR_MACROFILES 49
130 #define RPMVAR_NUM 55 /* number of RPMVAR entries */
132 /* this *must* be kept in alphabetical order */
133 /* The order of the flags is archSpecific, required, macroize, localize */
135 static const struct rpmOption const optionTable[] = {
136 { "include", RPMVAR_INCLUDE, 0, 1, 0, 2 },
137 { "macrofiles", RPMVAR_MACROFILES, 0, 0, 0, 1 },
138 { "optflags", RPMVAR_OPTFLAGS, 1, 0, 1, 0 },
141 static const size_t optionTableSize = sizeof(optionTable) / sizeof(*optionTable);
146 static cptr_t current[2];
148 static int currTables[2] = { RPM_MACHTABLE_INSTOS, RPM_MACHTABLE_INSTARCH };
150 static struct rpmvarValue values[RPMVAR_NUM];
152 static int defaultsInitialized = 0;
155 static rpmRC doReadRC( FD_t fd, const char * urlfn);
157 static void rpmSetVarArch(int var, const char * val,
160 static void rebuildCompatTables(int type, const char * name);
162 static void rpmRebuildTargetVars(const char **target, const char ** canontarget);
164 static int optionCompare(const void * a, const void * b)
166 return rstrcasecmp(((const struct rpmOption *) a)->name,
167 ((const struct rpmOption *) b)->name);
170 static machCacheEntry
171 machCacheFindEntry(const machCache cache, const char * key)
175 for (i = 0; i < cache->size; i++)
176 if (!strcmp(cache->cache[i].name, key)) return cache->cache + i;
181 static int machCompatCacheAdd(char * name, const char * fn, int linenum,
184 machCacheEntry entry = NULL;
190 while (*name && risspace(*name)) name++;
193 while (*chptr && *chptr != ':') chptr++;
195 rpmlog(RPMLOG_ERR, _("missing second ':' at %s:%d\n"), fn, linenum);
197 } else if (chptr == name) {
198 rpmlog(RPMLOG_ERR, _("missing architecture name at %s:%d\n"), fn,
203 while (*chptr == ':' || risspace(*chptr)) chptr--;
206 while (*equivs && risspace(*equivs)) equivs++;
212 entry = machCacheFindEntry(cache, name);
214 for (i = 0; i < entry->count; i++)
215 entry->equivs[i] = _free(entry->equivs[i]);
216 entry->equivs = _free(entry->equivs);
222 cache->cache = xrealloc(cache->cache,
223 (cache->size + 1) * sizeof(*cache->cache));
224 entry = cache->cache + cache->size++;
225 entry->name = xstrdup(name);
230 if (delEntry) return 0;
232 while ((chptr = strtok(equivs, " ")) != NULL) {
234 if (chptr[0] == '\0') /* does strtok() return "" ever?? */
237 entry->equivs = xrealloc(entry->equivs, sizeof(*entry->equivs)
238 * (entry->count + 1));
240 entry->equivs = xmalloc(sizeof(*entry->equivs));
242 entry->equivs[entry->count] = xstrdup(chptr);
250 machEquivSearch(const machEquivTable table, const char * name)
254 for (i = 0; i < table->count; i++)
255 if (!rstrcasecmp(table->list[i].name, name))
256 return table->list + i;
261 static void machAddEquiv(machEquivTable table, const char * name,
266 equiv = machEquivSearch(table, name);
269 table->list = xrealloc(table->list, (table->count + 1)
270 * sizeof(*table->list));
272 table->list = xmalloc(sizeof(*table->list));
274 table->list[table->count].name = xstrdup(name);
275 table->list[table->count++].score = distance;
279 static void machCacheEntryVisit(machCache cache,
280 machEquivTable table, const char * name, int distance)
282 machCacheEntry entry;
285 entry = machCacheFindEntry(cache, name);
286 if (!entry || entry->visited) return;
290 for (i = 0; i < entry->count; i++) {
291 machAddEquiv(table, entry->equivs[i], distance);
294 for (i = 0; i < entry->count; i++) {
295 machCacheEntryVisit(cache, table, entry->equivs[i], distance + 1);
299 static void machFindEquivs(machCache cache, machEquivTable table,
304 for (i = 0; i < cache->size; i++)
305 cache->cache[i].visited = 0;
307 while (table->count > 0) {
309 table->list[table->count].name = _free(table->list[table->count].name);
312 table->list = _free(table->list);
315 * We have a general graph built using strings instead of pointers.
316 * Yuck. We have to start at a point at traverse it, remembering how
317 * far away everything is.
319 /* FIX: table->list may be NULL. */
320 machAddEquiv(table, key, 1);
321 machCacheEntryVisit(cache, table, key, 2);
325 static rpmRC addCanon(canonEntry * table, int * tableLen, char * line,
326 const char * fn, int lineNum)
331 const char * tshort_name;
335 *table = xrealloc(*table, sizeof(**table) * (*tableLen));
337 t = & ((*table)[*tableLen - 2]);
339 tname = strtok(line, ": \t");
340 tshort_name = strtok(NULL, " \t");
341 s = strtok(NULL, " \t");
342 if (! (tname && tshort_name && s)) {
343 rpmlog(RPMLOG_ERR, _("Incomplete data line at %s:%d\n"),
347 if (strtok(NULL, " \t")) {
348 rpmlog(RPMLOG_ERR, _("Too many args in data line at %s:%d\n"),
353 /* LCL: s != NULL here. */
354 tnum = strtoul(s, &s1, 10);
355 if ((*s1) || (s1 == s) || (tnum == ULONG_MAX)) {
356 rpmlog(RPMLOG_ERR, _("Bad arch/os number: %s (%s:%d)\n"), s,
361 t[0].name = xstrdup(tname);
362 t[0].short_name = (tshort_name ? xstrdup(tshort_name) : xstrdup(""));
365 /* From A B C entry */
366 /* Add B B C entry */
367 t[1].name = (tshort_name ? xstrdup(tshort_name) : xstrdup(""));
368 t[1].short_name = (tshort_name ? xstrdup(tshort_name) : xstrdup(""));
374 static rpmRC addDefault(defaultEntry * table, int * tableLen, char * line,
375 const char * fn, int lineNum)
380 *table = xrealloc(*table, sizeof(**table) * (*tableLen));
382 t = & ((*table)[*tableLen - 1]);
384 t->name = strtok(line, ": \t");
385 t->defName = strtok(NULL, " \t");
386 if (! (t->name && t->defName)) {
387 rpmlog(RPMLOG_ERR, _("Incomplete default line at %s:%d\n"),
391 if (strtok(NULL, " \t")) {
392 rpmlog(RPMLOG_ERR, _("Too many args in default line at %s:%d\n"),
397 t->name = xstrdup(t->name);
398 t->defName = (t->defName ? xstrdup(t->defName) : NULL);
403 static canonEntry lookupInCanonTable(const char * name,
404 const canonEntry table, int tableLen)
408 if (strcmp(name, table[tableLen].name))
410 return &(table[tableLen]);
417 const char * lookupInDefaultTable(const char * name,
418 const defaultEntry table, int tableLen)
422 if (table[tableLen].name && !strcmp(name, table[tableLen].name))
423 return table[tableLen].defName;
429 static void addMacroDefault(const char * macroname, const char * val,
434 addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
437 static void setPathDefault(const char * macroname, const char * subdir)
440 if (macroname != NULL) {
441 #define _TOPDIRMACRO "%{_topdir}/"
442 char *body = alloca(sizeof(_TOPDIRMACRO) + strlen(subdir));
443 strcpy(body, _TOPDIRMACRO);
444 strcat(body, subdir);
445 addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
450 static const char * const prescriptenviron = "\n\
451 RPM_SOURCE_DIR=\"%{_sourcedir}\"\n\
452 RPM_BUILD_DIR=\"%{_builddir}\"\n\
453 RPM_OPT_FLAGS=\"%{optflags}\"\n\
454 RPM_ARCH=\"%{_arch}\"\n\
456 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\n\
457 RPM_DOC_DIR=\"%{_docdir}\"\n\
458 export RPM_DOC_DIR\n\
459 RPM_PACKAGE_NAME=\"%{name}\"\n\
460 RPM_PACKAGE_VERSION=\"%{version}\"\n\
461 RPM_PACKAGE_RELEASE=\"%{release}\"\n\
462 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\n\
463 %{?buildroot:RPM_BUILD_ROOT=\"%{buildroot}\"\n\
464 export RPM_BUILD_ROOT\n}\
467 static void setDefaults(void)
470 addMacro(NULL, "_usr", NULL, "/usr", RMIL_DEFAULT);
471 addMacro(NULL, "_var", NULL, LOCALSTATEDIR, RMIL_DEFAULT);
473 addMacro(NULL, "_preScriptEnvironment",NULL, prescriptenviron,RMIL_DEFAULT);
475 addMacroDefault("_topdir",
476 "/usr/src/packages", "%(echo $HOME)/rpmbuild");
477 addMacroDefault("_tmppath",
478 LOCALSTATEDIR "/tmp", "%{_var}/tmp");
479 addMacroDefault("_dbpath",
480 LOCALSTATEDIR "/lib/rpm", "%{_var}/lib/rpm");
481 addMacroDefault("_defaultdocdir",
482 "/usr/doc", "%{_usr}/doc");
484 addMacroDefault("_rpmfilename",
485 "%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm",NULL);
487 addMacroDefault("optflags",
489 addMacroDefault("sigtype",
491 addMacroDefault("_buildshell",
494 setPathDefault("_builddir", "BUILD");
495 setPathDefault("_rpmdir", "RPMS");
496 setPathDefault("_srcrpmdir", "SRPMS");
497 setPathDefault("_sourcedir", "SOURCES");
498 setPathDefault("_specdir", "SPECS");
502 /* FIX: se usage inconsistent, W2DO? */
503 static rpmRC doReadRC( FD_t fd, const char * urlfn)
508 struct rpmOption searchOption, * option;
511 /* XXX really need rc = Slurp(fd, const char * filename, char ** buf) */
512 { off_t size = fdSize(fd);
513 size_t nb = (size >= 0 ? size : (8*BUFSIZ - 2));
518 next = alloca(nb + 2);
520 rc = Fread(next, sizeof(*next), nb, fd);
521 if (Ferror(fd) || (size > 0 && rc != nb)) { /* XXX Feof(fd) */
522 rpmlog(RPMLOG_ERR, _("Failed to read %s: %s.\n"), urlfn,
533 while (*next != '\0') {
538 /* Find end-of-line. */
539 while (*se && *se != '\n') se++;
540 if (*se != '\0') *se++ = '\0';
543 /* Trim leading spaces */
544 while (*s && risspace(*s)) s++;
546 /* We used to allow comments to begin anywhere, but not anymore. */
547 if (*s == '#' || *s == '\0') continue;
549 /* Find end-of-keyword. */
551 while (*se && !risspace(*se) && *se != ':') se++;
555 while (*se && risspace(*se) && *se != ':') se++;
559 rpmlog(RPMLOG_ERR, _("missing ':' (found 0x%02x) at %s:%d\n"),
560 (unsigned)(0xff & *se), urlfn, linenum);
563 *se++ = '\0'; /* terminate keyword or option, point to value */
564 while (*se && risspace(*se)) se++;
566 /* Find keyword in table */
567 searchOption.name = s;
568 option = bsearch(&searchOption, optionTable, optionTableSize,
569 sizeof(optionTable[0]), optionCompare);
571 if (option) { /* For configuration variables ... */
572 const char *arch, *val;
575 arch = val = fn = NULL;
577 rpmlog(RPMLOG_ERR, _("missing argument for %s at %s:%d\n"),
578 option->name, urlfn, linenum);
582 switch (option->var) {
587 while (*se && !risspace(*se)) se++;
588 if (*se != '\0') *se++ = '\0';
590 #if 0 /* XXX doesn't seem to do anything useful, only break things... */
591 rpmRebuildTargetVars(NULL, NULL);
594 fn = rpmGetPath(s, NULL);
595 if (fn == NULL || *fn == '\0') {
596 rpmlog(RPMLOG_ERR, _("%s expansion failed at %s:%d \"%s\"\n"),
597 option->name, urlfn, linenum, s);
602 fdinc = Fopen(fn, "r.fpio");
603 if (fdinc == NULL || Ferror(fdinc)) {
604 rpmlog(RPMLOG_ERR, _("cannot open %s at %s:%d: %s\n"),
605 fn, urlfn, linenum, Fstrerror(fdinc));
608 rc = doReadRC(fdinc, fn);
612 continue; /* XXX don't save include value as var/macro */
618 if (option->archSpecific) {
620 while (*se && !risspace(*se)) se++;
623 _("missing architecture for %s at %s:%d\n"),
624 option->name, urlfn, linenum);
628 while (*se && risspace(*se)) se++;
631 _("missing argument for %s at %s:%d\n"),
632 option->name, urlfn, linenum);
639 /* Only add macros if appropriate for this arch */
640 if (option->macroize &&
641 (arch == NULL || !strcmp(arch, current[ARCH]))) {
643 n = name = xmalloc(strlen(option->name)+2);
644 if (option->localize)
646 strcpy(n, option->name);
647 addMacro(NULL, name, NULL, val, RMIL_RPMRC);
650 rpmSetVarArch(option->var, val, arch);
653 } else { /* For arch/os compatibilty tables ... */
659 for (i = 0; i < RPM_MACHTABLE_COUNT; i++) {
660 if (!strncmp(tables[i].key, s, strlen(tables[i].key)))
664 if (i < RPM_MACHTABLE_COUNT) {
665 const char *rest = s + strlen(tables[i].key);
666 if (*rest == '_') rest++;
668 if (!strcmp(rest, "compat")) {
669 if (machCompatCacheAdd(se, urlfn, linenum,
673 } else if (tables[i].hasTranslate &&
674 !strcmp(rest, "translate")) {
675 if (addDefault(&tables[i].defaults,
676 &tables[i].defaultsLength,
680 } else if (tables[i].hasCanon &&
681 !strcmp(rest, "canon")) {
682 if (addCanon(&tables[i].canons, &tables[i].canonsLength,
690 rpmlog(RPMLOG_ERR, _("bad option '%s' at %s:%d\n"),
702 static rpmRC rpmPlatform(const char * platform)
704 const char *cpu = NULL, *vendor = NULL, *os = NULL, *gnu = NULL;
707 int init_platform = 0;
711 rc = rpmioSlurp(platform, &b, &blen);
713 if (rc || b == NULL || blen <= 0) {
719 for (pe = p; p && *p; p = pe) {
720 pe = strchr(p, '\n');
724 while (*p && isspace(*p))
726 if (*p == '\0' || *p == '#')
730 char * t = p + strlen(p);
732 while (--t > p && isspace(*t))
735 platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat));
736 platpat[nplatpat] = xstrdup(p);
738 platpat[nplatpat] = NULL;
747 while (*p && !(*p == '-' || isspace(*p)))
749 if (*p != '\0') *p++ = '\0';
752 while (*p && !(*p == '-' || isspace(*p)))
755 if (*p != '\0') *p++ = '\0';
759 if (*p != '\0') *p++ = '\0';
762 while (*p && !(*p == '-' || isspace(*p)))
768 while (*p && !(*p == '-' || isspace(*p)))
771 if (*p != '\0') *p++ = '\0';
774 addMacro(NULL, "_host_cpu", NULL, cpu, -1);
775 addMacro(NULL, "_host_vendor", NULL, vendor, -1);
776 addMacro(NULL, "_host_os", NULL, os, -1);
778 platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat));
779 platpat[nplatpat] = rpmExpand("%{_host_cpu}-%{_host_vendor}-%{_host_os}", (gnu && *gnu ? "-" : NULL), gnu, NULL);
781 platpat[nplatpat] = NULL;
785 rc = (init_platform ? RPMRC_OK : RPMRC_FAIL);
793 # if defined(__linux__) && defined(__i386__)
798 * Generic CPUID function
800 static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
805 "movl %%ebx, %%esi \n"
807 : "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
812 * CPUID functions returning a single datum
814 static inline unsigned int cpuid_eax(unsigned int op)
816 unsigned int tmp, val;
817 cpuid(op, &val, &tmp, &tmp, &tmp);
821 static inline unsigned int cpuid_ebx(unsigned int op)
823 unsigned int tmp, val;
824 cpuid(op, &tmp, &val, &tmp, &tmp);
828 static inline unsigned int cpuid_ecx(unsigned int op)
830 unsigned int tmp, val;
831 cpuid(op, &tmp, &tmp, &val, &tmp);
835 static inline unsigned int cpuid_edx(unsigned int op)
837 unsigned int tmp, val;
838 cpuid(op, &tmp, &tmp, &tmp, &val);
842 static sigjmp_buf jenv;
844 static inline void model3(int _unused)
849 static inline int RPMClass(void)
852 unsigned int tfms, junk, cap, capamd;
853 struct sigaction oldsa;
855 sigaction(SIGILL, NULL, &oldsa);
856 signal(SIGILL, model3);
858 if (sigsetjmp(jenv, 1)) {
859 sigaction(SIGILL, &oldsa, NULL);
863 if (cpuid_eax(0x000000000)==0) {
864 sigaction(SIGILL, &oldsa, NULL);
868 cpuid(0x00000001, &tfms, &junk, &junk, &cap);
869 cpuid(0x80000001, &junk, &junk, &junk, &capamd);
873 sigaction(SIGILL, &oldsa, NULL);
879 /* CMOV supported? */
880 if (capamd & (1<<30))
881 return 7; /* 3DNOWEXT supported */
888 /* should only be called for model 6 CPU's */
889 static int is_athlon(void)
891 unsigned int eax, ebx, ecx, edx;
895 cpuid (0, &eax, &ebx, &ecx, &edx);
897 /* If you care about space, you can just check ebx, ecx and edx directly
898 instead of forming a string first and then doing a strcmp */
899 memset(vendor, 0, sizeof(vendor));
902 vendor[i] = (unsigned char) (ebx >>(8*i));
904 vendor[4+i] = (unsigned char) (edx >>(8*i));
906 vendor[8+i] = (unsigned char) (ecx >>(8*i));
908 if (strncmp(vendor, "AuthenticAMD", 12) != 0)
914 static int is_pentium3()
916 unsigned int eax, ebx, ecx, edx, family, model;
918 cpuid(0, &eax, &ebx, &ecx, &edx);
919 memset(vendor, 0, sizeof(vendor));
920 *((unsigned int *)&vendor[0]) = ebx;
921 *((unsigned int *)&vendor[4]) = edx;
922 *((unsigned int *)&vendor[8]) = ecx;
923 if (strncmp(vendor, "GenuineIntel", 12) != 0)
925 cpuid(1, &eax, &ebx, &ecx, &edx);
926 family = (eax >> 8) & 0x0f;
927 model = (eax >> 4) & 0x0f;
931 case 7: // Pentium III, Pentium III Xeon (model 7)
932 case 8: // Pentium III, Pentium III Xeon, Celeron (model 8)
935 Intel recently announced its new technology for mobile platforms,
936 named Centrino, and presents it as a big advance in mobile PCs.
937 One of the main part of Centrino consists in a brand new CPU,
938 the Pentium M, codenamed Banias, that we'll study in this review.
939 A particularity of this CPU is that it was designed for mobile platform
940 exclusively, unlike previous mobile CPU (Pentium III-M, Pentium 4-M)
941 that share the same micro-architecture as their desktop counterparts.
942 The Pentium M introduces a new micro-architecture, adapted for mobility
943 constraints, and that is halfway between the Pentium III and the Pentium 4.
944 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
946 case 10: // Pentium III Xeon (model A)
947 case 11: // Pentium III (model B)
953 static int is_pentium4()
955 unsigned int eax, ebx, ecx, edx, family, model;
957 cpuid(0, &eax, &ebx, &ecx, &edx);
958 memset(vendor, 0, sizeof(vendor));
959 *((unsigned int *)&vendor[0]) = ebx;
960 *((unsigned int *)&vendor[4]) = edx;
961 *((unsigned int *)&vendor[8]) = ecx;
962 if (strncmp(vendor, "GenuineIntel", 12) != 0)
964 cpuid(1, &eax, &ebx, &ecx, &edx);
965 family = (eax >> 8) & 0x0f;
966 model = (eax >> 4) & 0x0f;
970 case 0: // Pentium 4, Pentium 4 Xeon (0.18um)
971 case 1: // Pentium 4, Pentium 4 Xeon MP, Celeron (0.18um)
972 case 2: // Pentium 4, Mobile Pentium 4-M,
973 // Pentium 4 Xeon, Pentium 4 Xeon MP,
974 // Celeron, Mobile Celron (0.13um)
975 case 3: // Pentium 4, Celeron (0.09um)
981 static int is_geode()
983 unsigned int eax, ebx, ecx, edx, family, model;
985 /* If you care about space, you can just check ebx, ecx and edx directly
986 instead of forming a string first and then doing a strcmp */
987 memset(vendor, 0, sizeof(vendor));
989 cpuid(0, &eax, &ebx, &ecx, &edx);
990 memset(vendor, 0, sizeof(vendor));
991 *((unsigned int *)&vendor[0]) = ebx;
992 *((unsigned int *)&vendor[4]) = edx;
993 *((unsigned int *)&vendor[8]) = ecx;
994 if (strncmp(vendor, "AuthenticAMD", 12) != 0)
996 cpuid(1, &eax, &ebx, &ecx, &edx);
997 family = (eax >> 8) & 0x0f;
998 model = (eax >> 4) & 0x0f;
1009 #if defined(__linux__) && defined(__powerpc__)
1010 static jmp_buf mfspr_jmpbuf;
1012 static void mfspr_ill(int notused)
1014 longjmp(mfspr_jmpbuf, -1);
1020 static void defaultMachine(const char ** arch,
1023 static struct utsname un;
1024 static int gotDefaults = 0;
1029 while (!gotDefaults) {
1030 if (!rpmPlatform(platform)) {
1032 s = rpmExpand("%{_host_cpu}", NULL);
1034 rstrlcpy(un.machine, s, sizeof(un.machine));
1037 s = rpmExpand("%{_host_os}", NULL);
1039 rstrlcpy(un.sysname, s, sizeof(un.sysname));
1048 #if !defined(__linux__)
1050 /* USUALLY un.sysname on sinix does start with the word "SINIX"
1051 * let's be absolutely sure
1053 strncpy(un.sysname, "SINIX", sizeof(un.sysname));
1055 if (!strcmp(un.sysname, "AIX")) {
1056 strcpy(un.machine, __power_pc() ? "ppc" : "rs6000");
1057 sprintf(un.sysname,"aix%s.%s", un.version, un.release);
1059 else if(!strcmp(un.sysname, "Darwin")) {
1061 strcpy(un.machine, "ppc");
1062 #else ifdef __i386__
1063 strcpy(un.machine, "i386");
1066 else if (!strcmp(un.sysname, "SunOS")) {
1067 if (!strncmp(un.release,"4", 1)) /* SunOS 4.x */ {
1070 (un.release[fd] != 0 && (fd < sizeof(un.release)));
1072 if (!risdigit(un.release[fd]) && (un.release[fd] != '.')) {
1077 sprintf(un.sysname,"sunos%s",un.release);
1080 else /* Solaris 2.x: n.x.x becomes n-3.x.x */
1081 sprintf(un.sysname, "solaris%1d%s", atoi(un.release)-3,
1082 un.release+1+(atoi(un.release)/10));
1084 /* Solaris on Intel hardware reports i86pc instead of i386
1085 * (at least on 2.6 and 2.8)
1087 if (!strcmp(un.machine, "i86pc"))
1088 sprintf(un.machine, "i386");
1090 else if (!strcmp(un.sysname, "HP-UX"))
1091 /*make un.sysname look like hpux9.05 for example*/
1092 sprintf(un.sysname, "hpux%s", strpbrk(un.release, "123456789"));
1093 else if (!strcmp(un.sysname, "OSF1"))
1094 /*make un.sysname look like osf3.2 for example*/
1095 sprintf(un.sysname, "osf%s", strpbrk(un.release, "123456789"));
1096 else if (!strncmp(un.sysname, "IP", 2))
1097 un.sysname[2] = '\0';
1098 else if (!strncmp(un.sysname, "SINIX", 5)) {
1099 sprintf(un.sysname, "sinix%s",un.release);
1100 if (!strncmp(un.machine, "RM", 2))
1101 sprintf(un.machine, "mips");
1103 else if ((!strncmp(un.machine, "34", 2) ||
1104 !strncmp(un.machine, "33", 2)) && \
1105 !strncmp(un.release, "4.0", 3))
1107 /* we are on ncr-sysv4 */
1108 char * prelid = NULL;
1109 FD_t fd = Fopen("/etc/.relid", "r.fdio");
1111 if (fd != NULL && !Ferror(fd)) {
1112 chptr = xcalloc(1, 256);
1113 { int irelid = Fread(chptr, sizeof(*chptr), 256, fd);
1115 /* example: "112393 RELEASE 020200 Version 01 OS" */
1117 if ((prelid = strstr(chptr, "RELEASE "))){
1118 prelid += strlen("RELEASE ")+1;
1119 sprintf(un.sysname,"ncr-sysv4.%.*s",1,prelid);
1124 chptr = _free (chptr);
1126 if (!gotit) /* parsing /etc/.relid file failed? */
1127 strcpy(un.sysname,"ncr-sysv4");
1128 /* wrong, just for now, find out how to look for i586 later*/
1129 strcpy(un.machine,"i486");
1131 #endif /* __linux__ */
1133 /* get rid of the hyphens in the sysname */
1134 for (chptr = un.machine; *chptr != '\0'; chptr++)
1135 if (*chptr == '/') *chptr = '-';
1137 # if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
1139 strcpy(un.machine, "mipsel");
1140 # elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB)
1142 strcpy(un.machine, "mips");
1145 # if defined(__hpux) && defined(_SC_CPU_VERSION)
1147 # if !defined(CPU_PA_RISC1_2)
1148 # define CPU_PA_RISC1_2 0x211 /* HP PA-RISC1.2 */
1150 # if !defined(CPU_PA_RISC2_0)
1151 # define CPU_PA_RISC2_0 0x214 /* HP PA-RISC2.0 */
1153 int cpu_version = sysconf(_SC_CPU_VERSION);
1155 # if defined(CPU_HP_MC68020)
1156 if (cpu_version == CPU_HP_MC68020)
1157 strcpy(un.machine, "m68k");
1159 # if defined(CPU_HP_MC68030)
1160 if (cpu_version == CPU_HP_MC68030)
1161 strcpy(un.machine, "m68k");
1163 # if defined(CPU_HP_MC68040)
1164 if (cpu_version == CPU_HP_MC68040)
1165 strcpy(un.machine, "m68k");
1168 # if defined(CPU_PA_RISC1_0)
1169 if (cpu_version == CPU_PA_RISC1_0)
1170 strcpy(un.machine, "hppa1.0");
1172 # if defined(CPU_PA_RISC1_1)
1173 if (cpu_version == CPU_PA_RISC1_1)
1174 strcpy(un.machine, "hppa1.1");
1176 # if defined(CPU_PA_RISC1_2)
1177 if (cpu_version == CPU_PA_RISC1_2)
1178 strcpy(un.machine, "hppa1.2");
1180 # if defined(CPU_PA_RISC2_0)
1181 if (cpu_version == CPU_PA_RISC2_0)
1182 strcpy(un.machine, "hppa2.0");
1187 # if defined(__linux__) && defined(__sparc__)
1188 if (!strcmp(un.machine, "sparc")) {
1189 #define PERS_LINUX 0x00000000
1190 #define PERS_LINUX_32BIT 0x00800000
1191 #define PERS_LINUX32 0x00000008
1193 extern int personality(unsigned long);
1196 oldpers = personality(PERS_LINUX_32BIT);
1197 if (oldpers != -1) {
1198 if (personality(PERS_LINUX) != -1) {
1200 if (! strcmp(un.machine, "sparc64")) {
1201 strcpy(un.machine, "sparcv9");
1202 oldpers = PERS_LINUX32;
1205 personality(oldpers);
1208 # endif /* sparc*-linux */
1210 # if defined(__GNUC__) && defined(__alpha__)
1212 unsigned long amask, implver;
1213 register long v0 __asm__("$0") = -1;
1214 __asm__ (".long 0x47e00c20" : "=r"(v0) : "0"(v0));
1216 __asm__ (".long 0x47e03d80" : "=r"(v0));
1221 case 0: strcpy(un.machine, "alphaev5"); break;
1222 case 1: strcpy(un.machine, "alphaev56"); break;
1223 case 0x101: strcpy(un.machine, "alphapca56"); break;
1228 case 0x303: strcpy(un.machine, "alphaev6"); break;
1229 case 0x307: strcpy(un.machine, "alphaev67"); break;
1236 # if defined(__linux__) && defined(__i386__)
1238 char class = (char) (RPMClass() | '0');
1240 if ((class == '6' && is_athlon()) || class == '7')
1241 strcpy(un.machine, "athlon");
1242 else if (is_pentium4())
1243 strcpy(un.machine, "pentium4");
1244 else if (is_pentium3())
1245 strcpy(un.machine, "pentium3");
1246 else if (is_geode())
1247 strcpy(un.machine, "geode");
1248 else if (strchr("3456", un.machine[1]) && un.machine[1] != class)
1249 un.machine[1] = class;
1253 /* the uname() result goes through the arch_canon table */
1254 canon = lookupInCanonTable(un.machine,
1255 tables[RPM_MACHTABLE_INSTARCH].canons,
1256 tables[RPM_MACHTABLE_INSTARCH].canonsLength);
1258 rstrlcpy(un.machine, canon->short_name, sizeof(un.machine));
1260 canon = lookupInCanonTable(un.sysname,
1261 tables[RPM_MACHTABLE_INSTOS].canons,
1262 tables[RPM_MACHTABLE_INSTOS].canonsLength);
1264 rstrlcpy(un.sysname, canon->short_name, sizeof(un.sysname));
1269 if (arch) *arch = un.machine;
1270 if (os) *os = un.sysname;
1274 const char * rpmGetVarArch(int var, const char * arch)
1276 const struct rpmvarValue * next;
1278 if (arch == NULL) arch = current[ARCH];
1281 next = &values[var];
1283 if (next->arch && !strcmp(next->arch, arch)) return next->value;
1288 next = values + var;
1289 while (next && next->arch) next = next->next;
1291 return next ? next->value : NULL;
1294 static const char *rpmGetVar(int var)
1296 return rpmGetVarArch(var, NULL);
1299 static void rpmSetVarArch(int var, const char * val, const char * arch)
1301 struct rpmvarValue * next = values + var;
1305 while (next->next) {
1306 if (next->arch && !strcmp(next->arch, arch)) break;
1310 while (next->next) {
1311 if (!next->arch) break;
1316 if (next->arch && arch && !strcmp(next->arch, arch)) {
1317 next->value = _free(next->value);
1318 next->arch = _free(next->arch);
1319 } else if (next->arch || arch) {
1320 next->next = xmalloc(sizeof(*next->next));
1328 next->value = _free(next->value);
1329 next->value = xstrdup(val);
1330 next->arch = (arch ? xstrdup(arch) : NULL);
1333 void rpmSetTables(int archTable, int osTable)
1335 const char * arch, * os;
1337 defaultMachine(&arch, &os);
1339 if (currTables[ARCH] != archTable) {
1340 currTables[ARCH] = archTable;
1341 rebuildCompatTables(ARCH, arch);
1344 if (currTables[OS] != osTable) {
1345 currTables[OS] = osTable;
1346 rebuildCompatTables(OS, os);
1350 int rpmMachineScore(int type, const char * name)
1352 machEquivInfo info = machEquivSearch(&tables[type].equiv, name);
1353 return (info != NULL ? info->score : 0);
1357 * Set current arch/os names.
1358 * NULL as argument is set to the default value (munged uname())
1359 * pushed through a translation table (if appropriate).
1360 * @deprecated Use addMacro to set _target_* macros.
1363 * @param arch arch name (or NULL)
1364 * @param os os name (or NULL)
1367 static void rpmSetMachine(const char * arch, const char * os)
1369 const char * host_cpu, * host_os;
1371 defaultMachine(&host_cpu, &host_os);
1375 if (tables[currTables[ARCH]].hasTranslate)
1376 arch = lookupInDefaultTable(arch,
1377 tables[currTables[ARCH]].defaults,
1378 tables[currTables[ARCH]].defaultsLength);
1380 if (arch == NULL) return; /* XXX can't happen */
1384 if (tables[currTables[OS]].hasTranslate)
1385 os = lookupInDefaultTable(os,
1386 tables[currTables[OS]].defaults,
1387 tables[currTables[OS]].defaultsLength);
1389 if (os == NULL) return; /* XXX can't happen */
1391 if (!current[ARCH] || strcmp(arch, current[ARCH])) {
1392 current[ARCH] = _free(current[ARCH]);
1393 current[ARCH] = xstrdup(arch);
1394 rebuildCompatTables(ARCH, host_cpu);
1397 if (!current[OS] || strcmp(os, current[OS])) {
1398 char * t = xstrdup(os);
1399 current[OS] = _free(current[OS]);
1401 * XXX Capitalizing the 'L' is needed to insure that old
1402 * XXX os-from-uname (e.g. "Linux") is compatible with the new
1403 * XXX os-from-platform (e.g "linux" from "sparc-*-linux").
1404 * XXX A copy of this string is embedded in headers and is
1405 * XXX used by rpmInstallPackage->{os,arch}Okay->rpmMachineScore->
1406 * XXX to verify correct arch/os from headers.
1408 if (!strcmp(t, "linux"))
1412 rebuildCompatTables(OS, host_os);
1416 static void rebuildCompatTables(int type, const char * name)
1418 machFindEquivs(&tables[currTables[type]].cache,
1419 &tables[currTables[type]].equiv,
1423 static void getMachineInfo(int type, const char ** name,
1427 int which = currTables[type];
1429 /* use the normal canon tables, even if we're looking up build stuff */
1430 if (which >= 2) which -= 2;
1432 canon = lookupInCanonTable(current[type],
1433 tables[which].canons,
1434 tables[which].canonsLength);
1437 if (num) *num = canon->num;
1438 if (name) *name = canon->short_name;
1440 if (num) *num = 255;
1441 if (name) *name = current[type];
1443 if (tables[currTables[type]].hasCanon) {
1444 rpmlog(RPMLOG_WARNING, _("Unknown system: %s\n"), current[type]);
1445 rpmlog(RPMLOG_WARNING, _("Please contact %s\n"), PACKAGE_BUGREPORT);
1450 void rpmGetArchInfo(const char ** name, int * num)
1452 getMachineInfo(ARCH, name, num);
1455 void rpmGetOsInfo(const char ** name, int * num)
1457 getMachineInfo(OS, name, num);
1460 static void rpmRebuildTargetVars(const char ** target, const char ** canontarget)
1463 char *ca = NULL, *co = NULL, *ct = NULL;
1466 /* Rebuild the compat table to recalculate the current target arch. */
1468 rpmSetMachine(NULL, NULL);
1469 rpmSetTables(RPM_MACHTABLE_INSTARCH, RPM_MACHTABLE_INSTOS);
1470 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
1472 if (target && *target) {
1474 /* Set arch and os from specified build target */
1475 ca = xstrdup(*target);
1476 if ((c = strchr(ca, '-')) != NULL) {
1479 if ((co = strrchr(c, '-')) == NULL) {
1482 if (!rstrcasecmp(co, "-gnu"))
1484 if ((co = strrchr(c, '-')) == NULL)
1489 if (co != NULL) co = xstrdup(co);
1492 const char *a = NULL;
1493 const char *o = NULL;
1494 /* Set build target from rpm arch and os */
1495 rpmGetArchInfo(&a, NULL);
1496 ca = (a) ? xstrdup(a) : NULL;
1497 rpmGetOsInfo(&o, NULL);
1498 co = (o) ? xstrdup(o) : NULL;
1501 /* If still not set, Set target arch/os from default uname(2) values */
1503 const char *a = NULL;
1504 defaultMachine(&a, NULL);
1505 ca = (a) ? xstrdup(a) : NULL;
1507 for (x = 0; ca[x] != '\0'; x++)
1508 ca[x] = rtolower(ca[x]);
1511 const char *o = NULL;
1512 defaultMachine(NULL, &o);
1513 co = (o) ? xstrdup(o) : NULL;
1515 for (x = 0; co[x] != '\0'; x++)
1516 co[x] = rtolower(co[x]);
1518 /* XXX For now, set canonical target to arch-os */
1520 ct = xmalloc(strlen(ca) + sizeof("-") + strlen(co));
1521 sprintf(ct, "%s-%s", ca, co);
1525 * XXX All this macro pokery/jiggery could be achieved by doing a delayed
1526 * rpmInitMacros(NULL, PER-PLATFORM-MACRO-FILE-NAMES);
1528 delMacro(NULL, "_target");
1529 addMacro(NULL, "_target", NULL, ct, RMIL_RPMRC);
1530 delMacro(NULL, "_target_cpu");
1531 addMacro(NULL, "_target_cpu", NULL, ca, RMIL_RPMRC);
1532 delMacro(NULL, "_target_os");
1533 addMacro(NULL, "_target_os", NULL, co, RMIL_RPMRC);
1535 * XXX Make sure that per-arch optflags is initialized correctly.
1537 { const char *optflags = rpmGetVarArch(RPMVAR_OPTFLAGS, ca);
1538 if (optflags != NULL) {
1539 delMacro(NULL, "optflags");
1540 addMacro(NULL, "optflags", NULL, optflags, RMIL_RPMRC);
1552 void rpmFreeRpmrc(void)
1557 for (i = 0; i < nplatpat; i++)
1558 platpat[i] = _free(platpat[i]);
1559 platpat = _free(platpat);
1562 for (i = 0; i < RPM_MACHTABLE_COUNT; i++) {
1565 if (t->equiv.list) {
1566 for (j = 0; j < t->equiv.count; j++)
1567 t->equiv.list[j].name = _free(t->equiv.list[j].name);
1568 t->equiv.list = _free(t->equiv.list);
1571 if (t->cache.cache) {
1572 for (j = 0; j < t->cache.size; j++) {
1574 e = t->cache.cache + j;
1577 e->name = _free(e->name);
1579 for (k = 0; k < e->count; k++)
1580 e->equivs[k] = _free(e->equivs[k]);
1581 e->equivs = _free(e->equivs);
1584 t->cache.cache = _free(t->cache.cache);
1588 for (j = 0; j < t->defaultsLength; j++) {
1589 t->defaults[j].name = _free(t->defaults[j].name);
1590 t->defaults[j].defName = _free(t->defaults[j].defName);
1592 t->defaults = _free(t->defaults);
1593 t->defaultsLength = 0;
1596 for (j = 0; j < t->canonsLength; j++) {
1597 t->canons[j].name = _free(t->canons[j].name);
1598 t->canons[j].short_name = _free(t->canons[j].short_name);
1600 t->canons = _free(t->canons);
1601 t->canonsLength = 0;
1605 for (i = 0; i < RPMVAR_NUM; i++) {
1606 struct rpmvarValue * vp;
1607 while ((vp = values[i].next) != NULL) {
1608 values[i].next = vp->next;
1609 vp->value = _free(vp->value);
1610 vp->arch = _free(vp->arch);
1613 values[i].value = _free(values[i].value);
1614 values[i].arch = _free(values[i].arch);
1616 current[OS] = _free(current[OS]);
1617 current[ARCH] = _free(current[ARCH]);
1618 defaultsInitialized = 0;
1619 /* FIX: platpat/current may be NULL */
1621 /* XXX doesn't really belong here but... */
1628 * Read rpmrc (and macro) configuration file(s).
1629 * @param rcfiles colon separated files to read (NULL uses default)
1630 * @return RPMRC_OK on success
1632 static rpmRC rpmReadRC(const char * rcfiles)
1634 char *myrcfiles, *r, *re;
1637 if (!defaultsInitialized) {
1639 defaultsInitialized = 1;
1642 if (rcfiles == NULL)
1643 rcfiles = defrcfiles;
1645 /* Read each file in rcfiles. */
1647 for (r = myrcfiles = xstrdup(rcfiles); r && *r != '\0'; r = re) {
1651 /* Get pointer to rest of files */
1652 for (re = r; (re = strchr(re, ':')) != NULL; re++) {
1653 if (!(re[1] == '/' && re[2] == '/'))
1656 if (re && *re == ':')
1661 /* Expand ~/ to $HOME/ */
1663 if (r[0] == '~' && r[1] == '/') {
1664 const char * home = getenv("HOME");
1666 /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */
1667 if (rcfiles == defrcfiles && myrcfiles != r)
1669 rpmlog(RPMLOG_ERR, _("Cannot expand %s\n"), r);
1673 if (strlen(home) > (sizeof(fn) - strlen(r))) {
1674 rpmlog(RPMLOG_ERR, _("Cannot read %s, HOME is too large.\n"),
1682 strncat(fn, r, sizeof(fn) - (strlen(fn) + 1));
1683 fn[sizeof(fn)-1] = '\0';
1685 /* Read another rcfile */
1686 fd = Fopen(fn, "r.fpio");
1687 if (fd == NULL || Ferror(fd)) {
1688 /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */
1689 if (rcfiles == defrcfiles && myrcfiles != r)
1691 rpmlog(RPMLOG_ERR, _("Unable to open %s for reading: %s.\n"),
1696 rc = doReadRC(fd, fn);
1700 myrcfiles = _free(myrcfiles);
1704 rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */
1709 int rpmReadConfigFiles(const char * file, const char * target)
1712 /* Reset umask to its default umask(2) value. */
1715 /* Initialize crypto engine as early as possible */
1716 if (rpmInitCrypto() < 0) {
1719 /* Force preloading of name service libraries in case we go chrooting */
1720 (void) gethostbyname("localhost");
1722 /* Preset target macros */
1723 /* FIX: target can be NULL */
1724 rpmRebuildTargetVars(&target, NULL);
1726 /* Read the files */
1727 if (rpmReadRC(file)) return -1;
1729 if (macrofiles != NULL) {
1730 char *mf = rpmGetPath(macrofiles, NULL);
1731 rpmInitMacros(NULL, mf);
1735 /* Reset target macros */
1736 rpmRebuildTargetVars(&target, NULL);
1738 /* Finally set target platform */
1739 { char *cpu = rpmExpand("%{_target_cpu}", NULL);
1740 char *os = rpmExpand("%{_target_os}", NULL);
1741 rpmSetMachine(cpu, os);
1746 /* Force Lua state initialization */
1748 (void)rpmluaGetPrintBuffer(NULL);
1754 int rpmShowRC(FILE * fp)
1756 const struct rpmOption *opt;
1759 machEquivTable equivTable;
1761 /* the caller may set the build arch which should be printed here */
1762 fprintf(fp, "ARCHITECTURE AND OS:\n");
1763 fprintf(fp, "build arch : %s\n", current[ARCH]);
1765 fprintf(fp, "compatible build archs:");
1766 equivTable = &tables[RPM_MACHTABLE_BUILDARCH].equiv;
1767 for (i = 0; i < equivTable->count; i++)
1768 fprintf(fp," %s", equivTable->list[i].name);
1771 fprintf(fp, "build os : %s\n", current[OS]);
1773 fprintf(fp, "compatible build os's :");
1774 equivTable = &tables[RPM_MACHTABLE_BUILDOS].equiv;
1775 for (i = 0; i < equivTable->count; i++)
1776 fprintf(fp," %s", equivTable->list[i].name);
1779 rpmSetTables(RPM_MACHTABLE_INSTARCH, RPM_MACHTABLE_INSTOS);
1780 rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */
1782 fprintf(fp, "install arch : %s\n", current[ARCH]);
1783 fprintf(fp, "install os : %s\n", current[OS]);
1785 fprintf(fp, "compatible archs :");
1786 equivTable = &tables[RPM_MACHTABLE_INSTARCH].equiv;
1787 for (i = 0; i < equivTable->count; i++)
1788 fprintf(fp," %s", equivTable->list[i].name);
1791 fprintf(fp, "compatible os's :");
1792 equivTable = &tables[RPM_MACHTABLE_INSTOS].equiv;
1793 for (i = 0; i < equivTable->count; i++)
1794 fprintf(fp," %s", equivTable->list[i].name);
1797 fprintf(fp, "\nRPMRC VALUES:\n");
1798 for (i = 0, opt = optionTable; i < optionTableSize; i++, opt++) {
1799 const char *s = rpmGetVar(opt->var);
1800 if (s != NULL || rpmIsVerbose())
1801 fprintf(fp, "%-21s : %s\n", opt->name, s ? s : "(not set)");
1805 fprintf(fp, "Features supported by rpmlib:\n");
1806 xx = rpmdsRpmlib(&ds, NULL);
1808 while (rpmdsNext(ds) >= 0) {
1809 const char * DNEVR = rpmdsDNEVR(ds);
1811 fprintf(fp, " %s\n", DNEVR+2);
1816 rpmDumpMacroTable(NULL, fp);