* Mark Huang <mlhuang@cs.princeton.edu>
* Copyright (C) 2006 The Trustees of Princeton University
*
- * $Id: parseSpec.c,v 1.1 2006/03/08 21:19:16 mlhuang Exp $
+ * $Id: parseSpec.c,v 1.7 2007/07/23 15:12:44 mef Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
+#include <errno.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmts.h>
#include <rpm/rpmcli.h>
}
int
-main(int argc, char *const argv[])
+main(int argc, char *argv[])
{
poptContext context;
rpmts ts = NULL;
- QVA_t qva = &rpmQVKArgs;
int ec = 0;
Spec spec;
struct Source *source;
+ Package pkg;
+ const char *name, *version, *release, *arch, *unused;
+
+ /* BEGIN: support to pull out --target from the args list */
+ int alen, i;
+ char *target = NULL;
+ int args = 1;
+ int tlen = strlen("--target");
+
+ /* walk argv list looking for --target */
+ while ((args+1)<argc) {
+ if(strncmp(argv[args],"--target",tlen)==0){
+ char **dash;
+
+ /* get arch component of the --target option */
+ dash = (char**)strchr(argv[args+1],'-');
+ if (dash != NULL) *dash=NULL;
+
+ /* copy arch component of --target option to target */
+ alen = strnlen(argv[args+1],32);
+ target = (char*)malloc(alen+1);
+ if (target == NULL) return errno;
+ strncpy(target,argv[args+1],alen);
+ target[alen]='\0';
+
+ /* change argc, argv to take out the "--target xxx" */
+ for (i=args;i<argc;i++) argv[i]=argv[i+2];
+ argc-=2;
+
+ break;
+ }
+ args++;
+ }
+ argv[1]=argv[argc-1];
+ argv[2]=0;
+ argc=2;
+ /* END: support to pull out --target from the args list */
/* Parse common options for all rpm modes and executables */
context = rpmcliInit(argc, argv, optionsTable);
* access the Spec structure directly, so we call our own
* version of rpmSpecQuery() directly. */
spec = rpmspecGet(ts, argv[1]);
- if (spec && spec->sources) {
- for (source = spec->sources; source; source = source->next) {
- char fullSource[PATH_MAX];
- strncpy(fullSource, source->fullSource, sizeof(fullSource));
- printf("SOURCES += SOURCES/%s\n", basename(fullSource));
- }
+ if (!spec)
+ goto done;
+
+ /* Print sources */
+ for (source = spec->sources; source; source = source->next) {
+ char fullSource[PATH_MAX];
+
+ strncpy(fullSource, source->fullSource, sizeof(fullSource));
+ printf("SOURCES += SOURCES/%s\n", basename(fullSource));
}
-
- /* This is what would popt would do if --specfile were
- * specified. */
- qva->qva_source |= RPMQV_SPECFILE;
- qva->qva_sourceCount++;
- qva->qva_mode = 'q';
- qva->qva_specQuery = rpmspecQuery;
/* Get SRPM name from name of first package */
- qva->qva_queryFormat = "SRPM := SRPMS/%{name}-%{version}-%{release}.src.rpm\n";
- if (spec && spec->packages)
- showQueryPackage(qva, ts, spec->packages->header);
+ pkg = spec->packages;
+ name = version = release = NULL;
+ (void) headerNVR(pkg->header, &name, &version, &release);
+ if (name && version && release)
+ printf("SRPM := SRPMS/%s-%s-%s.src.rpm\n",
+ name, version, release);
+
+ /* Print non-empty packages */
+ for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
+ name = version = release = arch = NULL;
+ (void) headerNEVRA(pkg->header, &name, &unused, &version, &release, &arch);
+ if (name && version && release && arch) {
+ if (!pkg->fileList)
+ printf("# Empty\n# ");
+
+ if (target != NULL) {
+ if (strcmp(arch,target)!=0) {
+ arch=target;
+ }
+ }
+ printf("RPMS += RPMS/%s/%s-%s-%s.%s.rpm\n",
+ arch, name, version, release, arch);
+ }
+ }
- /* Print all packages */
- qva->qva_queryFormat = "RPMS += RPMS/%{ARCH}/%{name}-%{version}-%{release}.%{ARCH}.rpm\n";
- ec = rpmcliQuery(ts, qva, (const char **) &argv[1]);
+ spec = freeSpec(spec);
+ done:
ts = rpmtsFree(ts);
context = rpmcliFini(context);
return ec;