I posted a patch to the RPM mailing list last week against rpm 3.0.5 to add a "preprocessor mode." Here is a patch for 4.0 (if netscape has destroyed it, please email me): diff -r -u rpm-4.0/build/parsePrep.c rpm-4.0-preprocess/build/parsePrep.c --- rpm-4.0/build/parsePrep.c Wed Jul 5 08:26:29 2000 +++ rpm-4.0-preprocess/build/parsePrep.c Mon Jul 31 12:30:46 2000 @@ -484,27 +484,28 @@ } } - lines = splitString(getStringBuf(buf), strlen(getStringBuf(buf)), '\n'); - saveLines = lines; - while (*lines) { - res = 0; - if (! strncmp(*lines, "%setup", sizeof("%setup")-1)) { - res = doSetupMacro(spec, *lines); - } else if (! strncmp(*lines, "%patch", sizeof("%patch")-1)) { - res = doPatchMacro(spec, *lines); - } else { - appendLineStringBuf(spec->prep, *lines); - } - if (res && !spec->force) { - freeSplitString(saveLines); - freeStringBuf(buf); - return res; - } - lines++; + if (!spec->preprocess_mode) { + lines = splitString(getStringBuf(buf), strlen(getStringBuf(buf)), '\n'); + saveLines = lines; + while (*lines) { + res = 0; + if (! strncmp(*lines, "%setup", sizeof("%setup")-1)) { + res = doSetupMacro(spec, *lines); + } else if (! strncmp(*lines, "%patch", sizeof("%patch")-1)) { + res = doPatchMacro(spec, *lines); + } else { + appendLineStringBuf(spec->prep, *lines); + } + if (res && !spec->force) { + freeSplitString(saveLines); + freeStringBuf(buf); + return res; + } + lines++; + } + + freeSplitString(saveLines); + freeStringBuf(buf); } - - freeSplitString(saveLines); - freeStringBuf(buf); - return nextPart; } diff -r -u rpm-4.0/build/parseSpec.c rpm-4.0-preprocess/build/parseSpec.c --- rpm-4.0/build/parseSpec.c Wed Jul 5 08:26:29 2000 +++ rpm-4.0-preprocess/build/parseSpec.c Mon Jul 31 14:49:44 2000 @@ -323,6 +323,17 @@ spec->line[0] = '\0'; } + if (spec->preprocess_mode) { + int len = strlen(spec->line); + char *chomped = xmalloc(len+1); + + strcpy(chomped, spec->line); + if (chomped[len-1]=='\n') + chomped[len-1]='\0'; + puts(chomped); + xfree(chomped); + } + return 0; } @@ -345,7 +356,7 @@ /** */ int parseSpec(Spec *specp, const char *specFile, const char *rootURL, const char *buildRootURL, int inBuildArch, const char *passPhrase, - char *cookie, int anyarch, int force) + char *cookie, int anyarch, int force, int preprocess) { int parsePart = PART_PREAMBLE; int initialPackage = 1; @@ -367,6 +378,7 @@ spec->specFile = rpmGetPath(specFile, NULL); spec->fileStack = newOpenFileInfo(); spec->fileStack->fileName = xstrdup(spec->specFile); + spec->preprocess_mode = preprocess; if (buildRootURL) { const char * buildRoot; (void) urlPath(buildRootURL, &buildRoot); @@ -455,7 +467,8 @@ rpmSetMachine(spec->buildArchitectures[x], NULL); if (parseSpec(&(spec->buildArchitectureSpecs[index]), specFile, spec->rootURL, buildRootURL, 1, - passPhrase, cookie, anyarch, force)) { + passPhrase, cookie, anyarch, force, + preprocess)) { spec->buildArchitectureCount = index; freeSpec(spec); return RPMERR_BADSPEC; diff -r -u rpm-4.0/build/rpmbuild.h rpm-4.0-preprocess/build/rpmbuild.h --- rpm-4.0/build/rpmbuild.h Mon Jul 10 17:22:32 2000 +++ rpm-4.0-preprocess/build/rpmbuild.h Mon Jul 31 12:33:57 2000 @@ -27,6 +27,7 @@ #define RPMBUILD_RMBUILD (1 << 8) #define RPMBUILD_STRINGBUF (1 << 9) /* only for doScript() */ #define RPMBUILD_RMSPEC (1 << 10) +#define RPMBUILD_PREPROCESS (1 << 11) /* from build/misc.h */ @@ -202,12 +203,12 @@ /** */ int parseSpec(Spec *specp, const char *specFile, const char *rootdir, const char *buildRoot, int inBuildArch, const char *passPhrase, - char *cookie, int anyarch, int force); + char *cookie, int anyarch, int force, int preprocess); /** */ extern int (*parseSpecVec) (Spec *specp, const char *specFile, const char *rootdir, const char *buildRoot, int inBuildArch, const char *passPhrase, - char *cookie, int anyarch, int force); /* XXX FIXME */ + char *cookie, int anyarch, int force, int preprocess);/* XXX FIXME */ /** */ int buildSpec(Spec spec, int what, int test); diff -r -u rpm-4.0/build/rpmspec.h rpm-4.0-preprocess/build/rpmspec.h --- rpm-4.0/build/rpmspec.h Tue Jun 13 14:59:50 2000 +++ rpm-4.0-preprocess/build/rpmspec.h Mon Jul 31 12:34:12 2000 @@ -122,6 +122,7 @@ int force; int anyarch; + int preprocess_mode; int gotBuildRootURL; /*@only@*/ const char *buildRootURL; diff -r -u rpm-4.0/build.c rpm-4.0-preprocess/build.c --- rpm-4.0/build.c Tue Jun 6 05:23:44 2000 +++ rpm-4.0-preprocess/build.c Mon Jul 31 12:35:19 2000 @@ -231,11 +231,15 @@ #define _anyarch(_f) \ (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0) if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase, - cookie, _anyarch(buildAmount), force)) { + cookie, _anyarch(buildAmount), force, + ba->buildAmount & RPMBUILD_PREPROCESS)) { rc = 1; goto exit; } #undef _anyarch + + if (ba->buildAmount & RPMBUILD_PREPROCESS) /* we're done */ + goto exit; /* Assemble source header from parsed components */ initSourceHeader(spec); diff -r -u rpm-4.0/doc/rpm.8 rpm-4.0-preprocess/doc/rpm.8 --- rpm-4.0/doc/rpm.8 Tue Jun 6 05:23:46 2000 +++ rpm-4.0-preprocess/doc/rpm.8 Mon Jul 31 12:36:09 2000 @@ -401,6 +401,9 @@ .IP "\fB\-ba\fP" Build binary and source packages (after doing the prep, build, and install stages). +.IP "\fB\-bE\fP" +Preprocess the spec file. The spec file is macro expanded to standard +output. .PP The following options may also be used: .IP "\fB\-\-short\-circuit\fP" diff -r -u rpm-4.0/lib/poptBT.c rpm-4.0-preprocess/lib/poptBT.c --- rpm-4.0/lib/poptBT.c Thu Jun 1 01:36:15 2000 +++ rpm-4.0-preprocess/lib/poptBT.c Mon Jul 31 14:43:15 2000 @@ -30,6 +30,7 @@ #define POPT_BL 0x626c #define POPT_BP 0x6270 #define POPT_BS 0x6273 +#define POPT_BE 0x6245 #define POPT_TA 0x7461 #define POPT_TB 0x7462 #define POPT_TC 0x7463 @@ -58,6 +59,7 @@ case POPT_BL: case POPT_BP: case POPT_BS: + case POPT_BE: case POPT_TA: case POPT_TB: case POPT_TC: @@ -118,6 +120,8 @@ N_("build binary package from spec file"), NULL}, { "bs", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BS, N_("build source package from spec file"), NULL}, + { "bE", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BE, + N_("preprocess spec file"), NULL}, { "tp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TP, N_("build through %%prep stage from tar ball"), NULL}, diff -r -u rpm-4.0/lib/query.c rpm-4.0-preprocess/lib/query.c --- rpm-4.0/lib/query.c Sun Jul 9 18:19:24 2000 +++ rpm-4.0-preprocess/lib/query.c Mon Jul 31 12:37:15 2000 @@ -461,7 +461,7 @@ */ int (*parseSpecVec) (Spec *specp, const char *specFile, const char *rootdir, const char *buildRoot, int inBuildArch, const char *passPhrase, - char *cookie, int anyarch, int force) = NULL; + char *cookie, int anyarch, int force, int preprocess) = NULL; /** */ void (*freeSpecVec) (Spec spec) = NULL; @@ -549,9 +549,10 @@ char *cookie = NULL; int anyarch = 1; int force = 1; + int preprocess = 0; rc = parseSpecVec(&spec, arg, "/", buildRoot, inBuildArch, passPhrase, - cookie, anyarch, force); + cookie, anyarch, force, preprocess); if (rc || spec == NULL) { fprintf(stderr, _("query of specfile %s failed, can't parse\n"), arg); diff -r -u rpm-4.0/rpmqv.c rpm-4.0-preprocess/rpmqv.c --- rpm-4.0/rpmqv.c Tue Jul 25 12:42:11 2000 +++ rpm-4.0-preprocess/rpmqv.c Mon Jul 31 14:33:01 2000 @@ -581,6 +581,8 @@ _("bin/src package (prep, compile, install, package)")); printHelpLine( " s ", _("package src rpm only")); + printHelpLine( " E ", + _("preprocess (show macro expansion)")); printHelpLine( " --short-circuit ", _("skip straight to specified stage (only for c,i)")); printHelpLine( " --clean ", @@ -1276,6 +1278,9 @@ rpmSetVerbosity(RPMMESS_VERBOSE); switch (ba->buildChar) { + case 'E': + ba->buildAmount |= RPMBUILD_PREPROCESS; + /*@fallthrough@*/ /* these fallthroughs are intentional */ case 'a': ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
Created attachment 1715 [details] patch file
While I see a need for displaying a completely macro expanded spec file, I don't think that this should be in rpm itself., but rather in a rpmbuild helper program. I'm willing to be convinced otherwise if there's consensus on rpm-list that something like this is needed. Marking DEFERRED for consideration in rpm-4.1.
Changing component.
Closing bugs on older, no longer supported, releases. Apologies for any lack of response. For RPM issues, please try a current release such as Fedora Core 4; if bugs persist, please open a new issue.