5 #if defined(HAVE_SYS_SYSTEMCFG_H)
6 #include <sys/systemcfg.h>
11 #define _RPMIOB_INTERNAL
14 #define _MIRE_INTERNAL
18 #include <rpmluaext.h>
23 #define _RPMEVR_INTERNAL
26 #define _RPMDS_INTERNAL
61 #define RPM_MACHTABLE_COUNT 4
63 typedef const char * cptr_t;
119 {
"buildarch", 0, 1 },
155 for (i = 0; i < cache->
size; i++)
169 for (i = 0; i < table->
count; i++) {
172 equiv = table->
list + i;
197 if (!entry || entry->
visited)
return;
201 for (i = 0; i < entry->
count; i++) {
205 for (i = 0; i < entry->
count; i++) {
219 for (i = 0; i < cache->
size; i++)
222 while (table->
count > 0) {
247 if (strcmp(name, table[tableLen].name))
250 return &(table[tableLen]);
264 if (table[tableLen].name && !strcmp(name, table[tableLen].name))
265 return table[tableLen].
defName;
272 const char * val,
const char * body)
285 if (macroname != NULL) {
286 #define _TOPDIRMACRO "%{_topdir}/"
289 strcat(body, subdir);
297 RPM_SOURCE_DIR=\"%{_sourcedir}\"\n\
298 RPM_BUILD_DIR=\"%{_builddir}\"\n\
299 RPM_OPT_FLAGS=\"%{optflags}\"\n\
300 RPM_ARCH=\"%{_arch}\"\n\
302 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\n\
303 RPM_DOC_DIR=\"%{_docdir}\"\n\
304 export RPM_DOC_DIR\n\
305 RPM_PACKAGE_NAME=\"%{name}\"\n\
306 RPM_PACKAGE_VERSION=\"%{version}\"\n\
307 RPM_PACKAGE_RELEASE=\"%{release}\"\n\
308 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\n\
309 %{?buildroot:RPM_BUILD_ROOT=\"%{buildroot}\"\n\
310 export RPM_BUILD_ROOT\n}\
313 #if defined(RPM_VENDOR_WINDRIVER)
315 extern const char * __usrlibrpm;
317 extern const char * __etcrpm;
325 #if defined(RPM_VENDOR_WINDRIVER)
338 "%{_usr}/src/rpm", NULL);
340 "%{_var}/tmp", NULL);
342 "%{_var}/lib/rpm", NULL);
344 "%{_usr}/share/doc", NULL);
347 "%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm",NULL);
391 while (pe-- > p && isspace(*pe))
396 cvog->
os =
"unknown";
398 while (*p && !(*p ==
'-' || isspace(*p)))
400 if (*p !=
'\0') *p++ =
'\0';
403 while (*p && !(*p ==
'-' || isspace(*p)))
406 if (*p !=
'\0') *p++ =
'\0';
410 if (*p !=
'\0') *p++ =
'\0';
413 while (*p && !(*p ==
'-' || isspace(*p)))
419 while (*p && !(*p ==
'-' || isspace(*p)))
422 if (*p !=
'\0') *p++ =
'\0';
448 int init_platform = 0;
457 if (rc || iob == NULL) {
463 for (pe = p; p && *p; p = pe) {
464 pe = strchr(p,
'\n');
470 if (*p ==
'\0' || *p ==
'#')
474 char * t = p + strlen(p);
483 if (!
parseCVOG(p, &cvog) && cvog != NULL) {
486 addMacro(NULL,
"_host_os", NULL, cvog->
os, -1);
489 #if defined(RPM_VENDOR_OPENPKG)
491 p =
rpmExpand(
"%{_host_cpu}-%{_host_os}", NULL);
493 p =
rpmExpand(
"%{_host_cpu}-%{_host_vendor}-%{_host_os}",
494 (cvog && *cvog->
gnu ?
"-" : NULL),
495 (cvog ? cvog->
gnu : NULL), NULL);
519 #if defined(WITH_CPUINFO) && defined(WITH_SYCK)
520 static inline int rpmCpuinfoMatch(
const char * feature,
const char * EVR,
rpmds cpuinfo)
530 static rpmRC rpmCpuinfo(
void)
535 int mi_nre = 0, xx, i;
539 rpmsyck_node *tmp, node;
544 if(
Stat(_cpuinfo_path, &st))
547 fd =
Fopen(_cpuinfo_path,
"r");
548 _cpuinfo_path =
_free(_cpuinfo_path);
549 yaml = (
char *)
xcalloc(st.st_size+1, 1);
550 Fread(yaml, 1, st.st_size, fd);
554 cpuinfoYaml = rpmSyckLoad(yaml);
556 htGetEntry(cpuinfoYaml->firstNode->value.map,
"cpuinfo", &tmp, NULL, NULL);
557 node = tmp[0]->value.seq;
560 for(i = 0; node[i].type != T_END; i++) {
561 if(node[i].type == T_MAP) {
564 htGetEntry(node[i].value.map,
"Family", &tmp, NULL, NULL);
565 const char *family = tmp[0]->value.key;
568 if(rpmCpuinfoMatch(family,
"",
cpuinfoP)) {
570 htGetEntry(node[i].value.map,
"Arch", &tmp, NULL, NULL);
571 rpmsyck_node arch = tmp[0]->value.seq;
572 for(j = 0; arch[j].type != T_END; j++);
573 cpus =
htCreate(j*2, 0, 0, NULL, NULL);
574 for(j = 0; arch[j].type != T_END; j++) {
575 if(
htHasEntry(arch[j].value.map,
"Extends")) {
576 if(
htGetEntry(arch[j].value.map,
"Extends", &tmp, NULL, NULL) &&
577 tmp[0]->type == T_STR && !
htHasEntry(cpus, tmp[0]->value.key))
580 if(
htHasEntry(arch[j].value.map,
"Features")) {
581 htGetEntry(arch[j].value.map,
"Features", &tmp, NULL, NULL);
582 rpmsyck_node features = tmp[0]->value.seq;
584 for(k = 0; features[k].type != T_END; k++)
585 if(features[k].type == T_STR && !(match = rpmCpuinfoMatch(features[k].value.key,
"",
cpuinfoP)))
break;
589 htGetEntry(arch[j].value.map,
"Name", &tmp, NULL, NULL);
590 if(tmp[0]->type != T_STR)
continue;
591 const char *
name = tmp[0]->value.key;
592 rpmsyck_node alias = NULL;
594 htGetEntry(arch[j].value.map,
"Alias", &tmp, NULL, NULL);
595 alias = tmp[0]->value.seq;
601 if(
htHasEntry(node[i].value.map,
"Priority")) {
602 htGetEntry(node[i].value.map,
"Priority", &tmp, NULL, NULL);
603 rpmsyck_node priority = tmp[0]->value.seq;
605 for(j = 0; priority[j].type != T_END; j++)
608 htGetEntry(cpus, priority[j].value.key, &tmp, NULL, NULL);
610 rpmsyck_node alias = tmp[0];
612 for(k = 0; alias[k].type != T_END; k++)
618 if(cpus) cpus =
htFree(cpus);
623 cpuinfoYaml = rpmSyckFree(cpuinfoYaml);
627 cpu = mi_re[0].pattern;
630 if (!
parseCVOG(cpu, &cvog) && cvog != NULL) {
633 addMacro(NULL,
"_host_os", NULL, cvog->
os, -1);
663 if ((mire = (
miRE) mi_re) != NULL)
664 for (i = 0; i < mi_nre; i++) {
679 #if defined(RPM_VENDOR_OPENPKG)
682 static struct utsname un_real;
691 static struct utsname un;
693 static int gotDefaults = 0;
696 while (!gotDefaults) {
697 #if defined(RPM_VENDOR_WINDRIVER)
698 const char * _platform =
rpmGetPath(__etcrpm,
"/platform", NULL);
703 #if defined(RPM_VENDOR_OPENPKG)
706 #if defined(RPM_VENDOR_OPENPKG)
709 rc = uname(&un_real);
710 strncpy(un.sysname, un_real.sysname,
sizeof(un.sysname)); un.sysname [
sizeof(un.sysname) -1] =
'\0';
711 strncpy(un.nodename, un_real.nodename,
sizeof(un.nodename)); un.nodename[
sizeof(un.nodename)-1] =
'\0';
712 strncpy(un.release, un_real.release,
sizeof(un.release)); un.release [
sizeof(un.release) -1] =
'\0';
713 strncpy(un.version, un_real.version,
sizeof(un.version)); un.version [
sizeof(un.version) -1] =
'\0';
714 strncpy(un.machine, un_real.machine,
sizeof(un.machine)); un.machine [
sizeof(un.machine) -1] =
'\0';
720 #if defined(RPM_VENDOR_OPENPKG)
727 if ((n = strcspn(cpR,
"0123456789")) > 0)
729 if ((n = strspn(cpR,
"0123456789.")) > 0) {
733 if ((cp = strchr(cpR,
'.')) != NULL) {
734 if ((cp = strchr(cp+1,
'.')) != NULL)
737 strcat(un.sysname, cpR);
741 if (!strncmp(un.machine,
"Power Macintosh", 15))
742 sprintf(un.machine,
"powerpc");
746 if (!strncmp(un.machine,
"Power Macintosh", 15)) {
747 sprintf(un.machine,
"ppc");
750 #if defined(RPM_VENDOR_OPENPKG)
753 if (cp == NULL || cp[0] ==
'\0')
756 #elif defined(WITH_CPUINFO) && defined(WITH_SYCK)
765 if (s && *s !=
'\0') {
766 strncpy(un.machine, s,
sizeof(un.machine));
767 un.machine[
sizeof(un.machine)-1] =
'\0';
771 if (s && *s !=
'\0') {
772 strncpy(un.sysname, s,
sizeof(un.sysname));
773 un.sysname[
sizeof(un.sysname)-1] =
'\0';
778 #if defined(RPM_VENDOR_OPENPKG)
780 if (cp != NULL && cp != _platform)
783 #if defined(RPM_VENDOR_WINDRIVER)
784 _platform =
_free(_platform);
789 if (cvog->
cpu && cvog->
cpu[0] !=
'\0') {
790 strncpy(un.machine, cvog->
cpu,
sizeof(un.machine));
791 un.machine[
sizeof(un.machine)-1] =
'\0';
793 if (cvog->
os && cvog->
os[0] !=
'\0') {
794 strncpy(un.sysname, cvog->
os,
sizeof(un.sysname));
795 un.sysname[
sizeof(un.sysname)-1] =
'\0';
806 if (arch) *arch = un.machine;
807 if (os) *os = un.sysname;
823 const char * arch, * os;
851 assert(arch != NULL);
872 if (!strcmp(t,
"linux"))
887 if (which >= 2) which -= 2;
890 tables[which].canons,
891 tables[which].canonsLength);
894 if (num) *num = canon->
num;
898 #if defined(WITH_CPUINFO)
903 char *pref =
rpmExpand(
"%{?_prefer_target_cpu}", NULL);
913 if(!*name) *name =
current[type];
916 if (name) *name =
current[type];
924 char *ca = NULL, *co = NULL, *ct = NULL;
933 if (target && *target) {
937 if ((c = strchr(ca,
'-')) != NULL) {
940 if ((co = strrchr(c,
'-')) == NULL) {
945 if ((co = strrchr(c,
'-')) == NULL)
950 if (co != NULL) co =
xstrdup(co);
953 const char *a = NULL;
954 const char *o = NULL;
964 const char *a = NULL;
969 for (x = 0; ca[x] !=
'\0'; x++)
973 const char *o = NULL;
978 for (x = 0; co[x] !=
'\0'; x++)
983 ct = (
char *)
xmalloc(strlen(ca) +
sizeof(
"-") + strlen(co));
984 sprintf(ct,
"%s-%s", ca, co);
1035 for (k = 0; k < e->
count; k++)
1088 {
const char *mfpath =
rpmExpand(macrofiles, NULL);
1090 if (mfpath != NULL) {
1092 mfpath =
_free(mfpath);
1100 const char * target)
1106 #ifdef PREMACROFILES
1129 {
const char *cpu =
rpmExpand(
"%{_target_cpu}", NULL);
1130 const char *os =
rpmExpand(
"%{_target_os}", NULL);
1141 #if defined(RPM_VENDOR_OPENPKG)
1158 fprintf(fp,
"ARCHITECTURE AND OS:\n");
1161 fprintf(fp,
"compatible build archs:");
1163 for (i = 0; i < equivTable->
count; i++)
1164 fprintf(fp,
" %s", equivTable->
list[i].
name);
1167 fprintf(fp,
"build os : %s\n",
current[
OS]);
1169 fprintf(fp,
"compatible build os's :");
1171 for (i = 0; i < equivTable->
count; i++)
1172 fprintf(fp,
" %s", equivTable->
list[i].
name);
1175 fprintf(fp,
"install arch : %s\n",
current[ARCH]);
1176 fprintf(fp,
"install os : %s\n",
current[OS]);
1178 fprintf(fp,
"compatible archs :");
1180 fprintf(fp,
" %s", mire[i].pattern);
1183 fprintf(fp,
"compatible os's :");
1185 for (i = 0; i < equivTable->
count; i++)
1186 fprintf(fp,
" %s", equivTable->
list[i].
name);
1189 {
const char * s =
rpmExpand(
"%{?optflags}", NULL);
1190 fprintf(fp,
"%-21s : %s\n",
"optflags", ((s && *s) ? s :
"(not set)"));
1194 fprintf(fp,
"\nLUA MODULES:\n");
1198 fprintf(fp,
"%-21s : %s\n",
"luafiles", ((s && *s) ? s :
"(not set)"));
1203 fprintf(fp,
"%-21s : %s\n",
"luapath", ((s && *s) ? s :
"(not set)"));
1207 fprintf(fp,
"\nMACRO DEFINITIONS:\n");
1211 fprintf(fp,
"%-21s : %s\n",
"macrofiles", ((s && *s) ? s :
"(not set)"));
1221 fprintf(fp,
_(
"Configured system provides (from %s):\n"), fn);
1226 fprintf(fp,
" %s\n", DNEVR+2);
1236 fprintf(fp,
_(
"Features provided by rpmlib installer:\n"));
1242 fprintf(fp,
" %s\n", DNEVR+2);
1251 #if defined(WITH_CPUINFO)
1252 const char * fn =
"libcpuinfo";
1254 const char * fn = (_cpuinfo_path ? _cpuinfo_path :
"/proc/cpuinfo");
1257 _(
"Features provided by current cpuinfo (from %s):\n"), fn);
1263 fprintf(fp,
" %s\n", DNEVR+2);
1277 _(
"Features provided by current getconf:\n"));
1282 fprintf(fp,
" %s\n", DNEVR+2);
1292 _(
"Features provided by current uname:\n"));
1297 fprintf(fp,
" %s\n", DNEVR+2);