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
63 #define RPM_MACHTABLE_COUNT 4
65 typedef const char * cptr_t;
121 {
"buildarch", 0, 1 },
150 for (i = 0; i < cache->
size; i++)
164 for (i = 0; i < table->
count; i++) {
167 equiv = table->
list + i;
175 *
sizeof(*table->
list));
192 if (!entry || entry->
visited)
return;
196 for (i = 0; i < entry->
count; i++) {
200 for (i = 0; i < entry->
count; i++) {
214 for (i = 0; i < cache->
size; i++)
217 while (table->
count > 0) {
242 if (strcmp(name, table[tableLen].name))
245 return &(table[tableLen]);
259 if (table[tableLen].name && !strcmp(name, table[tableLen].name))
260 return table[tableLen].
defName;
267 const char * val,
const char * body)
280 if (macroname != NULL) {
281 #define _TOPDIRMACRO "%{_topdir}/"
284 strcat(body, subdir);
292 RPM_SOURCE_DIR=\"%{_sourcedir}\"\n\
293 RPM_BUILD_DIR=\"%{_builddir}\"\n\
294 RPM_OPT_FLAGS=\"%{optflags}\"\n\
295 RPM_ARCH=\"%{_arch}\"\n\
297 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\n\
298 RPM_DOC_DIR=\"%{_docdir}\"\n\
299 export RPM_DOC_DIR\n\
300 RPM_PACKAGE_NAME=\"%{name}\"\n\
301 RPM_PACKAGE_VERSION=\"%{version}\"\n\
302 RPM_PACKAGE_RELEASE=\"%{release}\"\n\
303 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\n\
304 %{?buildroot:RPM_BUILD_ROOT=\"%{buildroot}\"\n\
305 export RPM_BUILD_ROOT\n}\
308 #if defined(RPM_VENDOR_WINDRIVER)
310 extern const char * __usrlibrpm;
312 extern const char * __etcrpm;
320 #if defined(RPM_VENDOR_WINDRIVER)
333 "%{_usr}/src/rpm", NULL);
335 "%{_var}/tmp", NULL);
337 "%{_var}/lib/rpm", NULL);
339 "%{_usr}/share/doc", NULL);
342 "%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm",NULL);
382 while (pe-- > p && isspace(*pe))
387 cvog->
os =
"unknown";
389 while (*p && !(*p ==
'-' || isspace(*p)))
391 if (*p !=
'\0') *p++ =
'\0';
394 while (*p && !(*p ==
'-' || isspace(*p)))
397 if (*p !=
'\0') *p++ =
'\0';
401 if (*p !=
'\0') *p++ =
'\0';
404 while (*p && !(*p ==
'-' || isspace(*p)))
410 while (*p && !(*p ==
'-' || isspace(*p)))
413 if (*p !=
'\0') *p++ =
'\0';
439 int init_platform = 0;
448 if (rc || iob == NULL) {
454 for (pe = p; p && *p; p = pe) {
455 pe = strchr(p,
'\n');
461 if (*p ==
'\0' || *p ==
'#')
465 char * t = p + strlen(p);
474 if (!
parseCVOG(p, &cvog) && cvog != NULL) {
477 addMacro(NULL,
"_host_os", NULL, cvog->
os, -1);
480 #if defined(RPM_VENDOR_OPENPKG)
482 p =
rpmExpand(
"%{_host_cpu}-%{_host_os}", NULL);
484 p =
rpmExpand(
"%{_host_cpu}-%{_host_vendor}-%{_host_os}",
485 (cvog && *cvog->
gnu ?
"-" : NULL),
486 (cvog ? cvog->
gnu : NULL), NULL);
510 #if defined(WITH_CPUINFO) && defined(WITH_SYCK)
511 static inline int rpmCpuinfoMatch(
const char * feature,
const char * EVR,
rpmds cpuinfo)
521 static rpmRC rpmCpuinfo(
void)
526 int mi_nre = 0, xx, i;
530 rpmsyck_node *tmp, node;
535 if(
Stat(_cpuinfo_path, &st))
538 fd =
Fopen(_cpuinfo_path,
"r");
539 _cpuinfo_path =
_free(_cpuinfo_path);
540 yaml =
xcalloc(st.st_size+1, 1);
541 Fread(yaml, 1, st.st_size, fd);
545 cpuinfoYaml = rpmSyckLoad(yaml);
547 htGetEntry(cpuinfoYaml->firstNode->value.map,
"cpuinfo", &tmp, NULL, NULL);
548 node = tmp[0]->value.seq;
551 for(i = 0; node[i].type != T_END; i++) {
552 if(node[i].type == T_MAP) {
555 htGetEntry(node[i].value.map,
"Family", &tmp, NULL, NULL);
556 const char *family = tmp[0]->value.key;
559 if(rpmCpuinfoMatch(family,
"",
cpuinfoP)) {
561 htGetEntry(node[i].value.map,
"Arch", &tmp, NULL, NULL);
562 rpmsyck_node arch = tmp[0]->value.seq;
563 for(j = 0; arch[j].type != T_END; j++);
564 cpus =
htCreate(j*2, 0, 0, NULL, NULL);
565 for(j = 0; arch[j].type != T_END; j++) {
566 if(
htHasEntry(arch[j].value.map,
"Extends")) {
567 if(
htGetEntry(arch[j].value.map,
"Extends", &tmp, NULL, NULL) &&
568 tmp[0]->type == T_STR && !
htHasEntry(cpus, tmp[0]->value.key))
571 if(
htHasEntry(arch[j].value.map,
"Features")) {
572 htGetEntry(arch[j].value.map,
"Features", &tmp, NULL, NULL);
573 rpmsyck_node features = tmp[0]->value.seq;
575 for(k = 0; features[k].type != T_END; k++)
576 if(features[k].type == T_STR && !(match = rpmCpuinfoMatch(features[k].value.key,
"",
cpuinfoP)))
break;
580 htGetEntry(arch[j].value.map,
"Name", &tmp, NULL, NULL);
581 if(tmp[0]->type != T_STR)
continue;
582 const char *
name = tmp[0]->value.key;
583 rpmsyck_node alias = NULL;
585 htGetEntry(arch[j].value.map,
"Alias", &tmp, NULL, NULL);
586 alias = tmp[0]->value.seq;
592 if(
htHasEntry(node[i].value.map,
"Priority")) {
593 htGetEntry(node[i].value.map,
"Priority", &tmp, NULL, NULL);
594 rpmsyck_node priority = tmp[0]->value.seq;
596 for(j = 0; priority[j].type != T_END; j++)
599 htGetEntry(cpus, priority[j].value.key, &tmp, NULL, NULL);
601 rpmsyck_node alias = tmp[0];
603 for(k = 0; alias[k].type != T_END; k++)
609 if(cpus) cpus =
htFree(cpus);
614 cpuinfoYaml = rpmSyckFree(cpuinfoYaml);
618 cpu = mi_re[0].pattern;
621 if (!
parseCVOG(cpu, &cvog) && cvog != NULL) {
624 addMacro(NULL,
"_host_os", NULL, cvog->
os, -1);
654 if ((mire = mi_re) != NULL)
655 for (i = 0; i < mi_nre; i++) {
670 #if defined(RPM_VENDOR_OPENPKG)
673 static struct utsname un_real;
682 static struct utsname un;
684 static int gotDefaults = 0;
687 while (!gotDefaults) {
688 #if defined(RPM_VENDOR_WINDRIVER)
689 const char * _platform =
rpmGetPath(__etcrpm,
"/platform", NULL);
694 #if defined(RPM_VENDOR_OPENPKG)
697 #if defined(RPM_VENDOR_OPENPKG)
700 rc = uname(&un_real);
701 strncpy(un.sysname, un_real.sysname,
sizeof(un.sysname)); un.sysname [
sizeof(un.sysname) -1] =
'\0';
702 strncpy(un.nodename, un_real.nodename,
sizeof(un.nodename)); un.nodename[
sizeof(un.nodename)-1] =
'\0';
703 strncpy(un.release, un_real.release,
sizeof(un.release)); un.release [
sizeof(un.release) -1] =
'\0';
704 strncpy(un.version, un_real.version,
sizeof(un.version)); un.version [
sizeof(un.version) -1] =
'\0';
705 strncpy(un.machine, un_real.machine,
sizeof(un.machine)); un.machine [
sizeof(un.machine) -1] =
'\0';
711 #if defined(RPM_VENDOR_OPENPKG)
718 if ((n = strcspn(cpR,
"0123456789")) > 0)
720 if ((n = strspn(cpR,
"0123456789.")) > 0) {
724 if ((cp = strchr(cpR,
'.')) != NULL) {
725 if ((cp = strchr(cp+1,
'.')) != NULL)
728 strcat(un.sysname, cpR);
732 if (!strncmp(un.machine,
"Power Macintosh", 15))
733 sprintf(un.machine,
"powerpc");
737 if (!strncmp(un.machine,
"Power Macintosh", 15)) {
738 sprintf(un.machine,
"ppc");
741 #if defined(RPM_VENDOR_OPENPKG)
744 if (cp == NULL || cp[0] ==
'\0')
747 #elif defined(WITH_CPUINFO) && defined(WITH_SYCK)
755 if (s && *s !=
'\0') {
756 strncpy(un.machine, s,
sizeof(un.machine));
757 un.machine[
sizeof(un.machine)-1] =
'\0';
761 if (s && *s !=
'\0') {
762 strncpy(un.sysname, s,
sizeof(un.sysname));
763 un.sysname[
sizeof(un.sysname)-1] =
'\0';
768 #if defined(RPM_VENDOR_OPENPKG)
770 if (cp != NULL && cp != _platform)
773 #if defined(RPM_VENDOR_WINDRIVER)
774 _platform =
_free(_platform);
779 if (cvog->
cpu && cvog->
cpu[0] !=
'\0') {
780 strncpy(un.machine, cvog->
cpu,
sizeof(un.machine));
781 un.machine[
sizeof(un.machine)-1] =
'\0';
783 if (cvog->
os && cvog->
os[0] !=
'\0') {
784 strncpy(un.sysname, cvog->
os,
sizeof(un.sysname));
785 un.sysname[
sizeof(un.sysname)-1] =
'\0';
796 if (arch) *arch = un.machine;
797 if (os) *os = un.sysname;
813 const char * arch, * os;
841 assert(arch != NULL);
862 if (!strcmp(t,
"linux"))
877 if (which >= 2) which -= 2;
880 tables[which].canons,
881 tables[which].canonsLength);
884 if (num) *num = canon->
num;
888 #if defined(WITH_CPUINFO)
895 char *pref =
rpmExpand(
"%{?_prefer_target_cpu}", NULL);
905 if(!*name) *name =
current[type];
908 if (name) *name =
current[type];
916 char *ca = NULL, *co = NULL, *ct = NULL;
925 if (target && *target) {
929 if ((c = strchr(ca,
'-')) != NULL) {
932 if ((co = strrchr(c,
'-')) == NULL) {
937 if ((co = strrchr(c,
'-')) == NULL)
942 if (co != NULL) co =
xstrdup(co);
945 const char *a = NULL;
946 const char *o = NULL;
956 const char *a = NULL;
961 for (x = 0; ca[x] !=
'\0'; x++)
965 const char *o = NULL;
970 for (x = 0; co[x] !=
'\0'; x++)
975 ct =
xmalloc(strlen(ca) +
sizeof(
"-") + strlen(co));
976 sprintf(ct,
"%s-%s", ca, co);
1027 for (k = 0; k < e->
count; k++)
1080 {
const char *mfpath =
rpmExpand(macrofiles, NULL);
1082 if (mfpath != NULL) {
1084 mfpath =
_free(mfpath);
1092 const char * target)
1098 #ifdef PREMACROFILES
1099 if (
rpmReadRC(PREMACROFILES))
return -1;
1121 {
const char *cpu =
rpmExpand(
"%{_target_cpu}", NULL);
1122 const char *os =
rpmExpand(
"%{_target_os}", NULL);
1133 #if defined(RPM_VENDOR_OPENPKG)
1150 fprintf(fp,
"ARCHITECTURE AND OS:\n");
1153 fprintf(fp,
"compatible build archs:");
1155 for (i = 0; i < equivTable->
count; i++)
1156 fprintf(fp,
" %s", equivTable->
list[i].
name);
1159 fprintf(fp,
"build os : %s\n",
current[
OS]);
1161 fprintf(fp,
"compatible build os's :");
1163 for (i = 0; i < equivTable->
count; i++)
1164 fprintf(fp,
" %s", equivTable->
list[i].
name);
1167 fprintf(fp,
"install arch : %s\n",
current[ARCH]);
1168 fprintf(fp,
"install os : %s\n",
current[OS]);
1170 fprintf(fp,
"compatible archs :");
1172 fprintf(fp,
" %s", mire[i].pattern);
1175 fprintf(fp,
"compatible os's :");
1177 for (i = 0; i < equivTable->
count; i++)
1178 fprintf(fp,
" %s", equivTable->
list[i].
name);
1181 {
const char * s =
rpmExpand(
"%{?optflags}", NULL);
1182 fprintf(fp,
"%-21s : %s\n",
"optflags", ((s && *s) ? s :
"(not set)"));
1186 fprintf(fp,
"\nLUA MODULES:\n");
1190 fprintf(fp,
"%-21s : %s\n",
"luafiles", ((s && *s) ? s :
"(not set)"));
1195 fprintf(fp,
"%-21s : %s\n",
"luapath", ((s && *s) ? s :
"(not set)"));
1199 fprintf(fp,
"\nMACRO DEFINITIONS:\n");
1203 fprintf(fp,
"%-21s : %s\n",
"macrofiles", ((s && *s) ? s :
"(not set)"));
1213 fprintf(fp,
_(
"Configured system provides (from %s):\n"), fn);
1218 fprintf(fp,
" %s\n", DNEVR+2);
1228 fprintf(fp,
_(
"Features provided by rpmlib installer:\n"));
1234 fprintf(fp,
" %s\n", DNEVR+2);
1243 #if defined(WITH_CPUINFO)
1244 const char * fn =
"libcpuinfo";
1246 const char * fn = (_cpuinfo_path ? _cpuinfo_path :
"/proc/cpuinfo");
1249 _(
"Features provided by current cpuinfo (from %s):\n"), fn);
1254 fprintf(fp,
" %s\n", DNEVR+2);
1267 _(
"Features provided by current getconf:\n"));
1272 fprintf(fp,
" %s\n", DNEVR+2);
1282 _(
"Features provided by current uname:\n"));
1287 fprintf(fp,
" %s\n", DNEVR+2);