summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-04-01 22:26:44 +0000
committerjbj <devnull@localhost>1999-04-01 22:26:44 +0000
commit6266b08a66354fc2ec731bc642e2cbbd8bc2de84 (patch)
tree4f71fcb45ed8c84d29a9170fa00f29746eebf74b /lib
parent9bcdba42f2849957f59d93a5fd2aa861742f115b (diff)
downloadrpm-6266b08a66354fc2ec731bc642e2cbbd8bc2de84.tar.gz
rpm-6266b08a66354fc2ec731bc642e2cbbd8bc2de84.tar.bz2
rpm-6266b08a66354fc2ec731bc642e2cbbd8bc2de84.zip
add per-target macrofiles to search path.
take globalMacroContext out of macro api. fix: flush all macros between builds. CVS patchset: 2936 CVS date: 1999/04/01 22:26:44
Diffstat (limited to 'lib')
-rw-r--r--lib/macro.c32
-rw-r--r--lib/rpmmacro.h2
-rw-r--r--lib/rpmrc.c110
3 files changed, 81 insertions, 63 deletions
diff --git a/lib/macro.c b/lib/macro.c
index d545d0dab..008ccfe56 100644
--- a/lib/macro.c
+++ b/lib/macro.c
@@ -18,6 +18,8 @@
#include "rpmmacro.h"
+struct MacroContext globalMacroContext;
+
typedef struct MacroBuf {
const char *s; /* text to expand */
char *t; /* expansion buffer */
@@ -97,6 +99,8 @@ dumpMacroTable(MacroContext *mc, FILE *f)
int nempty = 0;
int nactive = 0;
+ if (mc == NULL)
+ mc = &globalMacroContext;
if (f == NULL)
f = stderr;
@@ -126,6 +130,8 @@ findEntry(MacroContext *mc, const char *name, size_t namelen)
MacroEntry keybuf, *key, **ret;
char namebuf[1024];
+ if (mc == NULL)
+ mc = &globalMacroContext;
if (! mc->firstFree)
return NULL;
@@ -1077,6 +1083,8 @@ expandMacros(void *spec, MacroContext *mc, char *s, size_t slen)
if (s == NULL || slen <= 0)
return 0;
+ if (mc == NULL)
+ mc = &globalMacroContext;
tbuf = alloca(slen + 1);
memset(tbuf, 0, (slen + 1));
@@ -1107,6 +1115,9 @@ addMacro(MacroContext *mc, const char *n, const char *o, const char *b, int leve
{
MacroEntry **mep;
+ if (mc == NULL)
+ mc = &globalMacroContext;
+
/* If new name, expand macro table */
if ((mep = findEntry(mc, n, 0)) == NULL) {
if (mc->firstFree == mc->macrosAllocated)
@@ -1127,6 +1138,8 @@ delMacro(MacroContext *mc, const char *name)
{
MacroEntry **mep = findEntry(mc, name, 0);
+ if (mc == NULL)
+ mc = &globalMacroContext;
/* If name exists, pop entry */
if ((mep = findEntry(mc, name, 0)) != NULL)
popMacro(mep);
@@ -1147,18 +1160,11 @@ void
initMacros(MacroContext *mc, const char *macrofiles)
{
char *m, *mfile, *me;
- static int first = 1;
-
- /* XXX initialization should be per macro context, not per execution */
- if (first) {
- mc->macroTable = NULL;
- expandMacroTable(mc);
- max_macro_depth = MAX_MACRO_DEPTH; /* XXX Assume good ol' macro expansion */
- first = 0;
- }
if (macrofiles == NULL)
return;
+ if (mc == NULL)
+ mc = &globalMacroContext;
for (mfile = m = strdup(macrofiles); *mfile; mfile = me) {
FILE *fp;
@@ -1210,6 +1216,9 @@ freeMacros(MacroContext *mc)
{
int i;
+ if (mc == NULL)
+ mc = &globalMacroContext;
+
for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me;
while ((me = mc->macroTable[i]) != NULL) {
@@ -1222,6 +1231,7 @@ freeMacros(MacroContext *mc)
}
}
FREE(mc->macroTable);
+ memset(mc, 0, sizeof(*mc));
}
/* =============================================================== */
@@ -1291,7 +1301,7 @@ rpmExpand(const char *arg, ...)
*pe = '\0';
}
va_end(ap);
- expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
+ expandMacros(NULL, NULL, buf, sizeof(buf));
return strdup(buf);
}
@@ -1350,7 +1360,7 @@ rpmGetPath(const char *path, ...)
}
}
va_end(ap);
- expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
+ expandMacros(NULL, NULL, buf, sizeof(buf));
return strdup(buf);
}
diff --git a/lib/rpmmacro.h b/lib/rpmmacro.h
index 5c3883eda..86be34fb4 100644
--- a/lib/rpmmacro.h
+++ b/lib/rpmmacro.h
@@ -16,8 +16,6 @@ typedef /*@abstract@*/ struct MacroContext {
int firstFree;
} MacroContext;
-extern MacroContext globalMacroContext;
-
/*
* Markers for types of macros added throughout rpm.
*/
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
index fafc957c3..eff06e1e2 100644
--- a/lib/rpmrc.c
+++ b/lib/rpmrc.c
@@ -15,12 +15,6 @@
static const char *defrcfiles = LIBRPMRC_FILENAME ":/etc/rpmrc:~/.rpmrc";
-#if UNUSED
-static const char *macrofiles = MACROFILES;
-#endif
-
-struct MacroContext globalMacroContext;
-
struct machCacheEntry {
char * name;
int count;
@@ -94,10 +88,10 @@ static struct tableType tables[RPM_MACHTABLE_COUNT] = {
/* The order of the flags is archSpecific, required, macroize, localize */
static struct rpmOption optionTable[] = {
- { "include", RPMVAR_INCLUDE, 0, 1, 1, 2 },
- { "macrofiles", RPMVAR_MACROFILES, 0, 0, 1, 1 },
+ { "include", RPMVAR_INCLUDE, 0, 1, 0, 2 },
+ { "macrofiles", RPMVAR_MACROFILES, 0, 0, 0, 1 },
{ "optflags", RPMVAR_OPTFLAGS, 1, 0, 1, 0 },
- { "provides", RPMVAR_PROVIDES, 0, 0, 1, 0 },
+ { "provides", RPMVAR_PROVIDES, 0, 0, 0, 0 },
};
/*@=fullinitblock@*/
static int optionTableSize = sizeof(optionTable) / sizeof(*optionTable);
@@ -449,7 +443,7 @@ static void setVarDefault(int var, const char *macroname, const char *val, const
}
if (body == NULL)
body = val;
- addMacro(&globalMacroContext, macroname, NULL, body, RMIL_DEFAULT);
+ addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
}
static void setPathDefault(int var, const char *macroname, const char *subdir)
@@ -478,7 +472,7 @@ static void setPathDefault(int var, const char *macroname, const char *subdir)
char *body = alloca(sizeof(_TOPDIRMACRO) + strlen(subdir));
strcpy(body, _TOPDIRMACRO);
strcat(body, subdir);
- addMacro(&globalMacroContext, macroname, NULL, body, RMIL_DEFAULT);
+ addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
#undef _TOPDIRMACRO
}
}
@@ -491,7 +485,7 @@ RPM_ARCH=\"%{_arch}\"\n\
RPM_OS=\"%{_os}\"\n\
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\n\
RPM_DOC_DIR=\"%{_docdir}\"\n\
-export RPM_DOC_DIR\
+export RPM_DOC_DIR\n\
RPM_PACKAGE_NAME=\"%{name}\"\n\
RPM_PACKAGE_VERSION=\"%{version}\"\n\
RPM_PACKAGE_RELEASE=\"%{release}\"\n\
@@ -502,15 +496,11 @@ export RPM_BUILD_ROOT\n}\
static void setDefaults(void) {
- initMacros(&globalMacroContext, NULL); /* XXX initialize data structures */
- addMacro(&globalMacroContext, "_usr", NULL, "/usr", RMIL_DEFAULT);
- addMacro(&globalMacroContext, "_var", NULL, "/var", RMIL_DEFAULT);
+ addMacro(NULL, "_usr", NULL, "/usr", RMIL_DEFAULT);
+ addMacro(NULL, "_var", NULL, "/var", RMIL_DEFAULT);
- addMacro(&globalMacroContext, "_preScriptEnvironment", NULL,
- prescriptenviron, RMIL_DEFAULT);
+ addMacro(NULL, "_preScriptEnvironment",NULL, prescriptenviron,RMIL_DEFAULT);
- setVarDefault(RPMVAR_MACROFILES, "_macrofiles",
- "/usr/lib/rpm/macros", "%{_usr}/lib/rpm/macros");
setVarDefault(-1, "_topdir",
"/usr/src/redhat", "%{_usr}/src/redhat");
setVarDefault(-1, "_tmppath",
@@ -520,7 +510,11 @@ static void setDefaults(void) {
setVarDefault(-1, "_defaultdocdir",
"/usr/doc", "%{_usr}/doc");
- setVarDefault(RPMVAR_OPTFLAGS, "optflags", "-O2", NULL);
+ setVarDefault(-1, "_rpmfilename",
+ "%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm",NULL);
+
+ setVarDefault(RPMVAR_OPTFLAGS, "optflags",
+ "-O2", NULL);
setVarDefault(-1, "sigtype",
"none", NULL);
setVarDefault(-1, "_buildshell",
@@ -573,7 +567,7 @@ int rpmReadRC(const char * rcfiles)
r++;
}
strcat(fn, r);
-
+
/* Read another rcfile */
fd = fdOpen(fn, O_RDONLY, 0);
if (fdFileno(fd) < 0) {
@@ -596,7 +590,7 @@ int rpmReadRC(const char * rcfiles)
rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */
if ((r = rpmGetVar(RPMVAR_MACROFILES)) != NULL)
- initMacros(&globalMacroContext, r);
+ initMacros(NULL, r);
return rc;
}
@@ -674,9 +668,9 @@ static int doReadRC(FD_t fd, const char * filename) {
rpmRebuildTargetVars(NULL, NULL);
strcpy(buf, start);
- if (expandMacros(NULL, &globalMacroContext, buf, sizeof(buf))) {
- rpmError(RPMERR_RPMRC, _("expansion failed at %s:%d \"%s\""),
- filename, linenum, start);
+ if (expandMacros(NULL, NULL, buf, sizeof(buf))) {
+ rpmError(RPMERR_RPMRC, _("%s expansion failed at %s:%d \"%s\""),
+ option->name, filename, linenum, start);
return 1;
}
@@ -689,6 +683,16 @@ static int doReadRC(FD_t fd, const char * filename) {
fdClose(fdinc);
if (rc) return rc;
} break;
+ case RPMVAR_MACROFILES:
+ buf[0] = '\0';
+ strncat(buf, start, sizeof(buf) - strlen(buf));
+ if (expandMacros(NULL, NULL, buf, sizeof(buf))) {
+ rpmError(RPMERR_RPMRC, _("%s expansion failed at %s:%d \"%s\""),
+ option->name, filename, linenum, start);
+ return 1;
+ }
+ start = buf;
+ break;
default:
break;
}
@@ -718,7 +722,7 @@ static int doReadRC(FD_t fd, const char * filename) {
if (option->localize)
*s++ = '_';
strcpy(s, option->name);
- addMacro(&globalMacroContext, buf, NULL, chptr, RMIL_RPMRC);
+ addMacro(NULL, buf, NULL, chptr, RMIL_RPMRC);
}
} else {
start = NULL; /* no arch */
@@ -728,7 +732,7 @@ static int doReadRC(FD_t fd, const char * filename) {
if (option->localize)
*s++ = '_';
strcpy(s, option->name);
- addMacro(&globalMacroContext, buf, NULL, chptr, RMIL_RPMRC);
+ addMacro(NULL, buf, NULL, chptr, RMIL_RPMRC);
}
}
rpmSetVarArch(option->var, chptr, start);
@@ -805,7 +809,7 @@ static void defaultMachine(char ** arch, char ** os) {
}
sprintf(un.sysname,"sunos%s",un.release);
}
-
+
else /* Solaris 2.x: n.x.x becomes n-3.x.x */
sprintf(un.sysname,"solaris%1d%s",atoi(un.release)-3,un.release+1+(atoi(un.release)/10));
}
@@ -842,7 +846,7 @@ static void defaultMachine(char ** arch, char ** os) {
}
free (chptr);
}
- }
+ }
if (!prelid)
/* parsing /etc/.relid file failed */
strcpy(un.sysname,"ncr-sysv4");
@@ -850,7 +854,7 @@ static void defaultMachine(char ** arch, char ** os) {
strcpy(un.machine,"i486");
}
#endif /* __linux__ */
-
+
/* get rid of the hyphens in the sysname */
for (chptr = un.machine; *chptr; chptr++)
if (*chptr == '/') *chptr = '-';
@@ -1120,7 +1124,6 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget)
{
char *ca = NULL, *co = NULL, *ct;
- const char * target = NULL;
int x;
/* Rebuild the compat table to recalculate the current target arch. */
@@ -1130,15 +1133,20 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget)
rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
if (buildtarget && *buildtarget) {
+ char *c;
/* Set arch and os from specified build target */
- ca = ct = strdup(*buildtarget);
- if ((co = strrchr(ct, '-')) != NULL) {
- *co++ = '\0';
- if (!strcmp(co, "gnu") && (co = strrchr(ct, '-')) != NULL)
- *co++ = '\0';
+ ca = strdup(*buildtarget);
+ if ((c = strchr(ca, '-')) != NULL)
+ *c++ = '\0';
+
+ if ((co = strrchr(c, '-')) == NULL) {
+ co = c;
+ } else {
+ if (!strcmp(co, "-gnu"))
+ *co = '\0';
+ co = strrchr(c, '-');
}
- if (co == NULL)
- co = "linux";
+ ct = strdup(*buildtarget);
} else {
/* Set build target from default arch and os */
rpmGetArchInfo(&ca,NULL);
@@ -1146,32 +1154,34 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget)
if (ca == NULL) defaultMachine(&ca, NULL);
if (co == NULL) defaultMachine(NULL, &co);
-
+ ca = strdup(ca);
for (x = 0; ca[x]; x++)
ca[x] = tolower(ca[x]);
+ co = strdup(co);
for (x = 0; co[x]; x++)
co[x] = tolower(co[x]);
ct = malloc(strlen(co)+strlen(ca)+2);
sprintf(ct, "%s-%s", ca, co);
- target = ct;
}
/*
* XXX All this macro pokery/jiggery could be achieved by doing a delayed
- * initMacros(&globalMacroContext, PER-PLATFORM-MACRO-FILE-NAMES);
+ * initMacros(NULL, PER-PLATFORM-MACRO-FILE-NAMES);
*/
- delMacro(&globalMacroContext, "_target");
- addMacro(&globalMacroContext, "_target", NULL, target, RMIL_RPMRC);
- delMacro(&globalMacroContext, "_target_cpu");
- addMacro(&globalMacroContext, "_target_cpu", NULL, ca, RMIL_RPMRC);
- delMacro(&globalMacroContext, "_target_os");
- addMacro(&globalMacroContext, "_target_os", NULL, co, RMIL_RPMRC);
+ delMacro(NULL, "_target");
+ addMacro(NULL, "_target", NULL, ct, RMIL_RPMRC);
+ delMacro(NULL, "_target_cpu");
+ addMacro(NULL, "_target_cpu", NULL, ca, RMIL_RPMRC);
+ delMacro(NULL, "_target_os");
+ addMacro(NULL, "_target_os", NULL, co, RMIL_RPMRC);
if (canontarget)
- *canontarget = target;
- if (ct != NULL && ct != target)
+ *canontarget = ct;
+ else
free(ct);
+ free(ca);
+ free(co);
}
int rpmShowRC(FILE *f)
@@ -1223,7 +1233,7 @@ int rpmShowRC(FILE *f)
fprintf(f, "%-21s : %s\n", opt->name, s ? s : "(not set)");
}
- dumpMacroTable(&globalMacroContext, f);
+ dumpMacroTable(NULL, f);
return 0;
}