From be7c392673e97b6b3fe7e6b9561afe919c22610b Mon Sep 17 00:00:00 2001 From: jbj Date: Fri, 12 Mar 1999 06:01:36 +0000 Subject: [PATCH] Resurrect --target. CVS patchset: 2884 CVS date: 1999/03/12 06:01:36 --- lib/rpmlib.h | 1 + lib/rpmrc.c | 115 +++++++++++++++++++++++++++++++++++------------------------ po/rpm.pot | 42 +++++++++++----------- 3 files changed, 90 insertions(+), 68 deletions(-) diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 854ed59..38dc61d 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -243,6 +243,7 @@ extern const struct headerSprintfExtension rpmHeaderFormats[]; #define RPMVAR_NUM 55 /* number of RPMVAR entries */ #define xfree(_p) free((void *)_p) +char *rpmExpand(const char *arg, ...); const char *rpmGetPath(const char *path, ...); char * rpmGetVar(int var); int rpmGetBooleanVar(int var); diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 7726b07..7ff2508 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -191,7 +191,7 @@ static int optionCompare(const void * a, const void * b) { ((struct rpmOption *) b)->name); } -static void rpmRebuildTargetVars(const char ** canontarget); +static void rpmRebuildTargetVars(const char **target, const char ** canontarget); static struct machCacheEntry * machCacheFindEntry(struct machCache * cache, @@ -458,22 +458,22 @@ static const char *lookupInDefaultTable(const char *name, struct defaultEntry *t int rpmReadConfigFiles(const char * file, const char * target) { - rpmSetMachine(NULL, NULL); - - if (target == NULL) { - rpmRebuildTargetVars(&target); - } else { - addMacro(&globalMacroContext, "_target", NULL, target, RMIL_RPMRC); - } + /* Preset target macros */ + rpmRebuildTargetVars(&target, NULL); + /* Read the files */ if (rpmReadRC(file)) return -1; - rpmRebuildTargetVars(&target); + /* Reset target macros */ + rpmRebuildTargetVars(&target, NULL); - { const char *cpu = getMacroBody(&globalMacroContext, "_target_cpu"); - const char *os = getMacroBody(&globalMacroContext, "_target_os"); + /* Finally set target platform */ + { const char *cpu = rpmExpand("%{_target_cpu}", NULL); + const char *os = rpmExpand("%{_target_os}", NULL); rpmSetMachine(cpu, os); - } + xfree(cpu); + xfree(os); + } return 0; } @@ -564,7 +564,35 @@ static void setDefaults(void) { } -const char * rpmGetPath(const char *path, ...) { +/* Return concatenated and expanded macro list */ +char * rpmExpand(const char *arg, ...) +{ + char buf[BUFSIZ], *p, *pe; + const char *s; + va_list ap; + + if (arg == NULL) + return strdup(""); + + p = buf; + strcpy(p, arg); + pe = p + strlen(p); + *pe = '\0'; + + va_start(ap, arg); + while ((s = va_arg(ap, const char *)) != NULL) { + strcpy(pe, s); + pe += strlen(pe); + *pe = '\0'; + } + va_end(ap); + expandMacros(NULL, &globalMacroContext, buf, sizeof(buf)); + return strdup(buf); +} + +/* Return concatenated and expanded path with multiple /'s removed */ +const char * rpmGetPath(const char *path, ...) +{ char buf[BUFSIZ], *p, *pe; const char *s; va_list ap; @@ -730,7 +758,7 @@ static int doReadRC(FD_t fd, const char * filename) { case RPMVAR_INCLUDE: { FD_t fdinc; - rpmRebuildTargetVars(NULL); + rpmRebuildTargetVars(NULL, NULL); strcpy(buf, start); if (expandMacros(NULL, &globalMacroContext, buf, sizeof(buf))) { @@ -1197,59 +1225,50 @@ void rpmGetOsInfo(char ** name, int * num) { getMachineInfo(OS, name, num); } -void rpmRebuildTargetVars(const char ** canontarget) +void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget) { - char * ca = NULL, * co = NULL; + char *ca = NULL, *co = NULL, *ct; const char * target = NULL; int x; -/* - * XXX getMacroBody() may be nuked -- I originally added it for tdyas and it's - * kinda half-baked (remember, each macro is actually a stack so it's not - * clear which body is intended). - * - * You can, however, always do - * char buf[BUFSIZ]; - * strcpy(buf, "%_target") - * expandMacros(NULL, &globalMacroContext, buf, sizeof(buf))) - * target = strdup(buf); - * - */ - if ((target = getMacroBody(&globalMacroContext, "_target")) != NULL) - target = strdup(target); - /* Rebuild the compat table to recalculate the current target arch. */ rpmSetMachine(NULL, NULL); rpmSetTables(RPM_MACHTABLE_INSTARCH, RPM_MACHTABLE_INSTOS); rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS); - rpmGetArchInfo(&ca,NULL); - rpmGetOsInfo(&co,NULL); + if (buildtarget && *buildtarget) { + /* 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'; + } + if (co == NULL) + co = "linux"; + } else { + /* Set build target from default arch and os */ + rpmGetArchInfo(&ca,NULL); + rpmGetOsInfo(&co,NULL); - if (ca == NULL) defaultMachine(&ca, NULL); - if (co == NULL) defaultMachine(NULL, &co); + if (ca == NULL) defaultMachine(&ca, NULL); + if (co == NULL) defaultMachine(NULL, &co); - for (x = 0; ca[x]; x++) - ca[x] = tolower(ca[x]); - for (x = 0; co[x]; x++) - co[x] = tolower(co[x]); + for (x = 0; ca[x]; x++) + ca[x] = tolower(ca[x]); + for (x = 0; co[x]; x++) + co[x] = tolower(co[x]); - if (target == NULL) { - char *ct = malloc(strlen(co)+strlen(ca)+2); + ct = malloc(strlen(co)+strlen(ca)+2); sprintf(ct, "%s-%s", ca, co); target = ct; } /* - * XXX All this macro pokery/jiggery could be achieved (I think) - * by doing a delayed + * XXX All this macro pokery/jiggery could be achieved by doing a delayed * initMacros(&globalMacroContext, PER-PLATFORM-MACRO-FILE-NAMES); - * (I haven't looked at the code :-) - * - * In fact, if you want to get really sophisticated, you could encapsulate - * within per-platform MacroContexts (but I'm not quite ready for that yet). */ delMacro(&globalMacroContext, "_target"); addMacro(&globalMacroContext, "_target", NULL, target, RMIL_RPMRC); @@ -1260,6 +1279,8 @@ void rpmRebuildTargetVars(const char ** canontarget) if (canontarget) *canontarget = target; + if (ct != NULL && ct != target) + free(ct); } int rpmShowRC(FILE *f) diff --git a/po/rpm.pot b/po/rpm.pot index 064bd7c..d0ae1bf 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-03-08 22:28-0500\n" +"POT-Creation-Date: 1999-03-12 00:43-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1422,31 +1422,31 @@ msgstr "" msgid "error reading header from package\n" msgstr "" -#: ../url.c:127 +#: ../url.c:138 #, c-format msgid "Password for %s@%s: " msgstr "" -#: ../url.c:146 ../url.c:168 +#: ../url.c:157 ../url.c:179 #, c-format msgid "error: %sport must be a number\n" msgstr "" -#: ../url.c:250 +#: ../url.c:261 msgid "url port must be a number\n" msgstr "" -#: ../url.c:286 +#: ../url.c:297 #, c-format msgid "logging into %s as %s, pw %s\n" msgstr "" -#: ../lib/rpmdb.c:168 ../url.c:397 +#: ../lib/rpmdb.c:168 ../url.c:408 #, c-format msgid "failed to open %s\n" msgstr "" -#: ../url.c:412 +#: ../url.c:423 #, c-format msgid "failed to create %s\n" msgstr "" @@ -2961,57 +2961,57 @@ msgstr "" msgid "Too many args in default line at %s:%d" msgstr "" -#: ../lib/rpmrc.c:627 +#: ../lib/rpmrc.c:671 #, c-format msgid "Cannot expand %s" msgstr "" -#: ../lib/rpmrc.c:642 +#: ../lib/rpmrc.c:686 #, c-format msgid "Unable to open %s for reading: %s." msgstr "" -#: ../lib/rpmrc.c:676 +#: ../lib/rpmrc.c:720 #, c-format msgid "Failed to read %s: %s." msgstr "" -#: ../lib/rpmrc.c:707 +#: ../lib/rpmrc.c:751 #, c-format msgid "missing ':' at %s:%d" msgstr "" -#: ../lib/rpmrc.c:723 ../lib/rpmrc.c:771 +#: ../lib/rpmrc.c:767 ../lib/rpmrc.c:815 #, c-format msgid "missing argument for %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:737 +#: ../lib/rpmrc.c:781 #, c-format msgid "expansion failed at %s:d \"%s\"" msgstr "" -#: ../lib/rpmrc.c:743 +#: ../lib/rpmrc.c:787 #, c-format msgid "cannot open %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:761 +#: ../lib/rpmrc.c:805 #, c-format msgid "missing architecture for %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:828 +#: ../lib/rpmrc.c:872 #, c-format msgid "bad option '%s' at %s:%d" msgstr "" -#: ../lib/rpmrc.c:1186 +#: ../lib/rpmrc.c:1230 #, c-format msgid "Unknown system: %s\n" msgstr "" -#: ../lib/rpmrc.c:1187 +#: ../lib/rpmrc.c:1231 msgid "Please contact rpm-list@redhat.com\n" msgstr "" @@ -3137,17 +3137,17 @@ msgstr "" msgid "Invalid signature spec in rc file" msgstr "" -#: ../lib/transaction.c:705 +#: ../lib/transaction.c:721 #, c-format msgid "relocating %s to %s\n" msgstr "" -#: ../lib/transaction.c:711 +#: ../lib/transaction.c:727 #, c-format msgid "excluding %s\n" msgstr "" -#: ../lib/transaction.c:799 +#: ../lib/transaction.c:815 #, c-format msgid "%s skipped due to missingok flag\n" msgstr "" -- 2.7.4