5 #if defined(HAVE_SYS_SYSTEMCFG_H)
6 #include <sys/systemcfg.h>
11 #define _RPMIOB_INTERNAL
14 #define _MIRE_INTERNAL
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);
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;
968 for (x = 0; ca[x] !=
'\0'; x++)
972 const char *o = NULL;
976 for (x = 0; co[x] !=
'\0'; x++)
981 ct = (
char *)
xmalloc(strlen(ca) +
sizeof(
"-") + strlen(co));
982 sprintf(ct,
"%s-%s", ca, co);
1031 for (k = 0; k < e->
count; k++)
1084 {
const char *mfpath =
rpmExpand(macrofiles, NULL);
1086 if (mfpath != NULL) {
1088 mfpath =
_free(mfpath);
1096 const char * target)
1102 #ifdef PREMACROFILES
1103 if (
rpmReadRC(PREMACROFILES))
return -1;
1125 {
const char *cpu =
rpmExpand(
"%{_target_cpu}", NULL);
1126 const char *os =
rpmExpand(
"%{_target_os}", NULL);
1137 #if defined(RPM_VENDOR_OPENPKG)
1154 fprintf(fp,
"ARCHITECTURE AND OS:\n");
1157 fprintf(fp,
"compatible build archs:");
1159 for (i = 0; i < equivTable->
count; i++)
1160 fprintf(fp,
" %s", equivTable->
list[i].
name);
1163 fprintf(fp,
"build os : %s\n",
current[
OS]);
1165 fprintf(fp,
"compatible build os's :");
1167 for (i = 0; i < equivTable->
count; i++)
1168 fprintf(fp,
" %s", equivTable->
list[i].
name);
1171 fprintf(fp,
"install arch : %s\n",
current[ARCH]);
1172 fprintf(fp,
"install os : %s\n",
current[OS]);
1174 fprintf(fp,
"compatible archs :");
1176 fprintf(fp,
" %s", mire[i].
pattern);
1179 fprintf(fp,
"compatible os's :");
1181 for (i = 0; i < equivTable->
count; i++)
1182 fprintf(fp,
" %s", equivTable->
list[i].
name);
1185 {
const char * s =
rpmExpand(
"%{?optflags}", NULL);
1186 fprintf(fp,
"%-21s : %s\n",
"optflags", ((s && *s) ? s :
"(not set)"));
1190 fprintf(fp,
"\nLUA MODULES:\n");
1194 fprintf(fp,
"%-21s : %s\n",
"luafiles", ((s && *s) ? s :
"(not set)"));
1199 fprintf(fp,
"%-21s : %s\n",
"luapath", ((s && *s) ? s :
"(not set)"));
1203 fprintf(fp,
"\nMACRO DEFINITIONS:\n");
1207 fprintf(fp,
"%-21s : %s\n",
"macrofiles", ((s && *s) ? s :
"(not set)"));
1217 fprintf(fp,
_(
"Configured system provides (from %s):\n"), fn);
1222 fprintf(fp,
" %s\n", DNEVR+2);
1232 fprintf(fp,
_(
"Features provided by rpmlib installer:\n"));
1238 fprintf(fp,
" %s\n", DNEVR+2);
1247 #if defined(WITH_CPUINFO)
1248 const char * fn =
"libcpuinfo";
1250 const char * fn = (_cpuinfo_path ? _cpuinfo_path :
"/proc/cpuinfo");
1253 _(
"Features provided by current cpuinfo (from %s):\n"), fn);
1259 fprintf(fp,
" %s\n", DNEVR+2);
1273 _(
"Features provided by current getconf:\n"));
1278 fprintf(fp,
" %s\n", DNEVR+2);
1288 _(
"Features provided by current uname:\n"));
1293 fprintf(fp,
" %s\n", DNEVR+2);
rpmds rpmdsSingle(rpmTag tagN, const char *N, const char *EVR, evrFlags Flags)
Create, load and initialize a dependency set of size 1.
void rpmInitMacros(MacroContext mc, const char *macrofiles)
Initialize macro context from set of macrofile(s).
rpm_machtable_e
Build and install arch/os table identifiers.
rpmds rpmdsInit(rpmds ds)
Initialize dependency set iterator.
rpmPRCO rpmdsFreePRCO(rpmPRCO PRCO)
Free dependency set(s) container.
static void defaultMachine(const char **arch, const char **os)
int htHasEntry(hashTable ht, const void *key)
Check for key in hash table.
void * mireFreeAll(miRE mire, int nmire)
Destroy compiled patterns.
struct cpu_vendor_os_gnu * CVOG_t
char * xstrdup(const char *str)
static const char * ___build_pre
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
int rpmdsGetconf(rpmds *dsp, const char *path)
Load getconf provides into a dependency set.
struct machEquivTable_s equiv
int rpmPlatformScore(const char *platform, void *mi_re, int mi_nre)
Return score of a platform string.
rpmlua rpmluaGetGlobalState(void)
int Stat(const char *path, struct stat *st)
stat(2) clone.
static const char * configTarget
void addMacro(MacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
const char * rpmdsDNEVR(const rpmds ds)
Return current formatted dependency string.
struct rpmds_s * rpmds
Dependency tag sets from a header, so that a header can be discarded early.
static void rebuildCompatTables(int type, const char *name)
struct rpmPRCO_s * rpmPRCO
Container for commonly extracted dependency set(s).
rpmds rpmdsFree(rpmds ds)
Destroy a dependency set.
static machCacheEntry machCacheFindEntry(const machCache cache, const char *key)
int rpmiobSlurp(const char *fn, rpmiob *iobp)
int htGetEntry(hashTable ht, const void *key, const void *data, int *dataCount, const void *tableKey)
Retrieve item from hash table.
static int xtolower(int c)
rpmPRCO rpmdsNewPRCO(Header h)
Create dependency set(s) container.
static void rpmRebuildTargetVars(const char **target, const char **canontarget)
void delMacro(MacroContext mc, const char *n)
Delete macro from context.
void * xcalloc(size_t nmemb, size_t size)
int rpmdsSysinfo(rpmPRCO PRCO, const char *fn)
Load sysinfo dependencies into a dependency set.
static void rpmSetMachine(const char *arch, const char *os)
static void machCacheEntryVisit(machCache cache, machEquivTable table, const char *name, int distance)
int rpmdsRpmlib(rpmds *dsp, void *tblp)
Load rpmlib provides into a dependency set.
int argvCount(const ARGV_t argv)
Return no.
static int xisspace(int c)
hashTable htFree(hashTable ht)
Destroy hash table.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
const char * rpmluaGetPrintBuffer(rpmlua _lua)
static void setPathDefault(const char *macroname, const char *subdir)
static void getMachineInfo(int type, const char **name, int *num)
struct machEquivInfo_s * machEquivInfo
int rpmdsNext(rpmds ds)
Return next dependency set iterator index.
Structure(s) used for dependency tag sets.
struct machCache_s * machCache
The FD_t File Handle data structure.
const char * rpmMacrofiles
List of macro files to read when configuring rpm.
void rpmDumpMacroTable(MacroContext mc, FILE *fp)
Print macros to file stream.
int mireRegexec(miRE mire, const char *val, size_t vallen)
Execute pattern match.
struct machCacheEntry_s * machCacheEntry
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
static void addMacroDefault(const char *macroname, const char *val, const char *body)
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
static int parseCVOG(const char *str, CVOG_t *cvogp)
static canonEntry lookupInCanonTable(const char *name, const canonEntry table, int tableLen)
static void rpmSetTables(int archTable, int osTable)
int Fclose(FD_t fd)
fclose(3) clone.
struct defaultEntry_s * defaultEntry
const char * _sysinfo_path
enum rpmRC_e rpmRC
RPM return codes.
const char * _cpuinfo_path
void htAddEntry(hashTable ht, const void *key, const void *data)
Add item to hash table.
static const char * lookupInDefaultTable(const char *name, const defaultEntry table, int tableLen)
const char const bson * key
rpmds rpmdsLink(rpmds ds, const char *msg)
Reference a dependency set instance.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int rpmShowRC(FILE *fp)
Display current rpmrc (and macro) configuration.
void rpmluaextActivate(rpmlua lua)
Add RPM library based Lua extension.
int rpmdsCpuinfo(rpmds *dsp, const char *fn)
Load /proc/cpuinfo provides into a dependency set.
Structure(s) and routine(s) used for EVR parsing and comparison.
int rpmdsUname(rpmds *dsp, const struct utsname *un)
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
static void setDefaults(void)
int rpmdsMatch(const rpmds A, rpmds B)
Compare A against every member of B, looking for 1st match.
static int defaultsInitialized
#define RMIL_DEFAULT
Markers for sources of macros added throughout rpm.
struct machEquivTable_s * machEquivTable
int mireAppend(rpmMireMode mode, int tag, const char *pattern, const unsigned char *table, miRE *mirep, int *nmirep)
Append pattern to array.
const char const char * pattern
static int rpmReadRC(const char *macrofiles)
Read macro configuration file(s).
hashTable htCreate(int numBuckets, size_t keySize, int freeData, hashFunctionType fn, hashEqualityType eq)
Create hash table.
struct canonEntry_s * canonEntry
static const char * platform
static struct tableType_s tables[4]
static void machAddEquiv(machEquivTable table, const char *name, int distance)
static rpmRC rpmPlatform(const char *platform)
Read and configure /etc/rpm/platform patterns.
struct tableType_s * tableType
#define RPM_MACHTABLE_COUNT
const char const bson int num
rpmds rpmdsFromPRCO(rpmPRCO PRCO, rpmTag tagN)
Retrieve a dependency set from container.