From: jbj Date: Sat, 5 Sep 1998 20:02:08 +0000 (+0000) Subject: Start converting variables into macro expansions. X-Git-Tag: rpm-4.4-release~3517 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8b7b65b28000640df90a72d920eca7daa3db0aa;p=platform%2Fupstream%2Frpm.git Start converting variables into macro expansions. RPMVAR_SOURCEDIR -> %{_sourcedir} RPMVAR_BUILDDIR -> %{_builddir} CVS patchset: 2279 CVS date: 1998/09/05 20:02:08 --- diff --git a/autogen.sh b/autogen.sh index 88a2073..afb52bb 100755 --- a/autogen.sh +++ b/autogen.sh @@ -8,7 +8,7 @@ if [ "$1" = "--noconfigure" ]; then exit 0; fi -if [ X"$@" = X ]; then +if [ X"$@" = X -a "X`uname -s`" = "XLinux" ]; then ./configure --prefix=/usr else ./configure "$@" diff --git a/build.c b/build.c index ec36986..97fa829 100644 --- a/build.c +++ b/build.c @@ -91,7 +91,7 @@ int buildplatform(char *arg, int buildAmount, char *passPhrase, while (*cmd != '/') cmd--; *cmd = '\0'; - rpmSetVar(RPMVAR_SOURCEDIR, buf); + addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL); } else if (arg[0] == '/') { specfile = arg; } else { diff --git a/build/build.c b/build/build.c index d103014..b8578c2 100644 --- a/build/build.c +++ b/build/build.c @@ -18,7 +18,9 @@ static void doRmSource(Spec spec) p = spec->sources; while (p) { if (! (p->flags & RPMBUILD_ISNO)) { - sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), p->source); + strcpy(buf, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + strcat(buf, p->source); unlink(buf); } p = p->next; @@ -29,7 +31,9 @@ static void doRmSource(Spec spec) p = pkg->icon; while (p) { if (! (p->flags & RPMBUILD_ISNO)) { - sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), p->source); + strcpy(buf, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + strcat(buf, p->source); unlink(buf); } p = p->next; @@ -38,21 +42,34 @@ static void doRmSource(Spec spec) } } +/* + * The _preScript string is expanded to export values to a script environment. + */ + +static char *_preScriptEnvironment = + "RPM_SOURCE_DIR=\"%{_sourcedir}\"\n" + "RPM_BUILD_DIR=\"%{_builddir}\"\n" + "RPM_OPT_FLAGS=\"%{_optflags}\"\n" + "export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS\n" +; + static int writeVars(Spec spec, FILE *f) { char *arch, *os, *s; + char buf[BUFSIZ]; + + strcpy(buf, _preScriptEnvironment); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + fprintf(f, "%s\n", buf); rpmGetArchInfo(&arch, NULL); rpmGetOsInfo(&os, NULL); - fprintf(f, "RPM_SOURCE_DIR=\"%s\"\n", rpmGetVar(RPMVAR_SOURCEDIR)); - fprintf(f, "RPM_BUILD_DIR=\"%s\"\n", rpmGetVar(RPMVAR_BUILDDIR)); fprintf(f, "RPM_DOC_DIR=\"%s\"\n", spec->docDir); - fprintf(f, "RPM_OPT_FLAGS=\"%s\"\n", rpmGetVar(RPMVAR_OPTFLAGS)); fprintf(f, "RPM_ARCH=\"%s\"\n", arch); fprintf(f, "RPM_OS=\"%s\"\n", os); - fprintf(f, "export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_DOC_DIR " - "RPM_OPT_FLAGS RPM_ARCH RPM_OS\n"); + + fprintf(f, "export RPM_DOC_DIR RPM_ARCH RPM_OS\n"); if (spec->buildRoot) { fprintf(f, "RPM_BUILD_ROOT=\"%s\"\n", spec->buildRoot); @@ -79,6 +96,11 @@ static int writeVars(Spec spec, FILE *f) return 0; } +static char *_preScriptChdir = + "umask 022\n" + "cd %{_builddir}\n" +; + int doScript(Spec spec, int what, char *name, StringBuf sb, int test) { int fd; @@ -129,8 +151,14 @@ int doScript(Spec spec, int what, char *name, StringBuf sb, int test) } fprintf(f, rpmIsVerbose() ? "set -x\n\n" : "exec > /dev/null\n\n"); - fprintf(f, "umask 022\n"); - fprintf(f, "cd %s\n", rpmGetVar(RPMVAR_BUILDDIR)); + +/* XXX umask 022; cd %{_builddir} */ + { char buf[BUFSIZ]; + strcpy(buf, _preScriptChdir); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + fputs(buf, f); + } + if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD) { if (spec->buildSubdir) { fprintf(f, "cd %s\n", spec->buildSubdir); diff --git a/build/files.c b/build/files.c index 5be8f7d..51c0b82 100644 --- a/build/files.c +++ b/build/files.c @@ -1065,12 +1065,14 @@ static int processPackageFiles(Spec spec, Package pkg, pkg->cpioCount = 0; if (pkg->fileFile) { + strcpy(buf, "%{_builddir}/"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); if (spec->buildSubdir) { - sprintf(buf, "%s/%s/%s", rpmGetVar(RPMVAR_BUILDDIR), - spec->buildSubdir, pkg->fileFile); - } else { - sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_BUILDDIR), pkg->fileFile); + strcat(buf, spec->buildSubdir); + strcat(buf, "/"); } + strcat(buf, pkg->fileFile); + if ((f = fopen(buf, "r")) == NULL) { rpmError(RPMERR_BADFILENAME, "Could not open %%files file: %s", pkg->fileFile); @@ -1327,17 +1329,25 @@ int processSourceFiles(Spec spec) RPM_INT32_TYPE, &srcPtr->num, 1); } } - sprintf(buf, "%s%s/%s", - srcPtr->flags & RPMBUILD_ISNO ? "!" : "", - rpmGetVar(RPMVAR_SOURCEDIR), srcPtr->source); + + { char *s = buf; + if (srcPtr->flags & RPMBUILD_ISNO) + *s++ = '!'; + strcpy(s, "%{_sourcedir}/"); + } + expandMacros(spec, spec->macros, buf, sizeof(buf)); + strcat(buf, srcPtr->source); appendLineStringBuf(sourceFiles, buf); } for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { for (srcPtr = pkg->icon; srcPtr != NULL; srcPtr = srcPtr->next) { - sprintf(buf, "%s%s/%s", - srcPtr->flags & RPMBUILD_ISNO ? "!" : "", - rpmGetVar(RPMVAR_SOURCEDIR), srcPtr->source); + char *s = buf; + if (srcPtr->flags & RPMBUILD_ISNO) + *s++ = '!'; + strcpy(s, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + strcat(buf, srcPtr->source); appendLineStringBuf(sourceFiles, buf); } } diff --git a/build/pack.c b/build/pack.c index 1f7206a..b471e6c 100644 --- a/build/pack.c +++ b/build/pack.c @@ -362,8 +362,12 @@ static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb) char buf[BUFSIZ]; FILE *f; - sprintf(buf, "%s/%s/%s", rpmGetVar(RPMVAR_BUILDDIR), - spec->buildSubdir, file); + strcpy(buf, "%{_builddir}/"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); + strcat(buf, spec->buildSubdir); + strcat(buf, "/"); + strcat(buf, file); + if ((f = fopen(buf, "r")) == NULL) { freeStringBuf(sb); return NULL; diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 9b942c9..3dd07c1 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -278,7 +278,10 @@ static int readIcon(Header h, char *file) struct stat statbuf; int fd; - sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), file); + strcpy(buf, "%{_sourcedir}/"); + expandMacros(NULL, &globalMacroContext, buf, sizeof(buf)); + strcat(buf, file); + if (stat(buf, &statbuf)) { rpmError(RPMERR_BADSPEC, "Unable to read icon: %s", file); return RPMERR_BADSPEC; diff --git a/build/parsePrep.c b/build/parsePrep.c index a5b0141..bb165fc 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -50,25 +50,22 @@ static char *doPatch(Spec spec, int c, int strip, char *db, static char buf[BUFSIZ]; char file[BUFSIZ]; char args[BUFSIZ]; - char *s; struct Source *sp; int compressed; - s = NULL; - sp = spec->sources; - while (sp) { + for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMBUILD_ISPATCH) && (sp->num == c)) { - s = sp->source; break; } - sp = sp->next; } - if (! s) { + if (sp == NULL) { rpmError(RPMERR_BADSPEC, "No patch number %d", c); return NULL; } - sprintf(file, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), s); + strcpy(file, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, file, sizeof(file)); + strcat(file, sp->source); args[0] = '\0'; if (db) { @@ -120,21 +117,20 @@ static char *doUntar(Spec spec, int c, int quietly) struct Source *sp; int compressed; - s = NULL; - sp = spec->sources; - while (sp) { + for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMBUILD_ISSOURCE) && (sp->num == c)) { - s = sp->source; break; } - sp = sp->next; } - if (! s) { + if (sp == NULL) { rpmError(RPMERR_BADSPEC, "No source number %d", c); return NULL; } - sprintf(file, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), s); + strcpy(file, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, file, sizeof(file)); + strcat(file, sp->source); + taropts = (rpmIsVerbose() && !quietly ? "-xvvf" : "-xf"); if (isCompressed(file, &compressed)) { @@ -242,7 +238,8 @@ static int doSetupMacro(Spec spec, char *line) poptFreeContext(optCon); /* cd to the build dir */ - sprintf(buf, "cd %s", rpmGetVar(RPMVAR_BUILDDIR)); + strcpy(buf, "cd %{_builddir}"); + expandMacros(spec, spec->macros, buf, sizeof(buf)); appendLineStringBuf(spec->prep, buf); /* delete any old sources */ @@ -259,7 +256,7 @@ static int doSetupMacro(Spec spec, char *line) } /* do the default action */ - if (!createDir && !skipDefaultAction) { + if (!createDir && !skipDefaultAction) { chptr = doUntar(spec, 0, quietly); if (!chptr) { return RPMERR_BADSPEC; diff --git a/build/parseSpec.c b/build/parseSpec.c index 9aaa6b7..85036f6 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -2,39 +2,6 @@ #include "rpmbuild.h" -#ifdef DEAD -#ifdef DYING -static void setStandardMacros(Spec spec, char *arch, char *os); -#endif - -static void setStandardMacros(Spec spec, char *arch, char *os) -{ - char buf[BUFSIZ]; - int x; - - addMacro(spec->macros, "sourcedir", NULL, rpmGetVar(RPMVAR_SOURCEDIR), RMIL_SPEC); - addMacro(spec->macros, "builddir", NULL, rpmGetVar(RPMVAR_BUILDDIR), RMIL_SPEC); - addMacro(spec->macros, "optflags", NULL, rpmGetVar(RPMVAR_OPTFLAGS), RMIL_SPEC); - addMacro(spec->macros, "buildarch", NULL, arch, RMIL_SPEC); - addMacro(spec->macros, "buildos", NULL, os, RMIL_SPEC); - - x = 0; - while (arch[x]) { - buf[x] = tolower(arch[x]); - x++; - } - buf[x] = '\0'; - addMacro(spec->macros, "buildarch_lc", NULL, buf, RMIL_SPEC); - x = 0; - while (os[x]) { - buf[x] = tolower(os[x]); - x++; - } - buf[x] = '\0'; - addMacro(spec->macros, "buildos_lc", NULL, buf, RMIL_SPEC); -} -#endif /* DEAD */ - static struct PartRec { int part; int len; diff --git a/build/spec.c b/build/spec.c index 64afbbf..27ebe3f 100644 --- a/build/spec.c +++ b/build/spec.c @@ -308,7 +308,10 @@ int addSource(Spec spec, Package pkg, char *field, int tag) spec->numSources++; if (tag != RPMTAG_ICON) { - sprintf(body, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), p->source); + strcpy(body, "%{_sourcedir}/"); + expandMacros(spec, spec->macros, body, sizeof(body)); /* W2DO? */ + strcat(body, p->source); + sprintf(buf, "%s%d", (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); addMacro(spec->macros, buf, NULL, body, RMIL_SPEC); diff --git a/lib/rpmmacro.h b/lib/rpmmacro.h index 6d3725b..eedcf2e 100644 --- a/lib/rpmmacro.h +++ b/lib/rpmmacro.h @@ -16,11 +16,14 @@ typedef struct MacroContext { int firstFree; } MacroContext; +extern MacroContext globalMacroContext; + /* * Markers for types of macros added throughout rpm. */ #define RMIL_MACROFILES -9 #define RMIL_RPMRC -7 +#define RMIL_TARBALL -5 #define RMIL_SPEC -1 #define RMIL_OLDSPEC -1 #define RMIL_GLOBAL 0 diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h index 6d3725b..eedcf2e 100644 --- a/rpmio/rpmmacro.h +++ b/rpmio/rpmmacro.h @@ -16,11 +16,14 @@ typedef struct MacroContext { int firstFree; } MacroContext; +extern MacroContext globalMacroContext; + /* * Markers for types of macros added throughout rpm. */ #define RMIL_MACROFILES -9 #define RMIL_RPMRC -7 +#define RMIL_TARBALL -5 #define RMIL_SPEC -1 #define RMIL_OLDSPEC -1 #define RMIL_GLOBAL 0