X-Git-Url: http://git.onelab.eu/?p=build.git;a=blobdiff_plain;f=spec2make.c;h=60004ef6448d360b1862ed5bee696737ed8bec6e;hp=94c93068c3f7f9f71bf2a75600e92674ebbaa26e;hb=1f4f80e0c7dc71ef79614227c195139a56d1421e;hpb=d7a099685023698f0ca9168d419b0a00867d47e2 diff --git a/spec2make.c b/spec2make.c index 94c93068..60004ef6 100644 --- a/spec2make.c +++ b/spec2make.c @@ -6,7 +6,6 @@ * Mark Huang * Copyright (C) 2006 The Trustees of Princeton University * - * $Id$ */ #include @@ -20,10 +19,24 @@ #include #include +/* from f10 and up, Spec is renamed rpmSpec */ +#ifndef _RPMTYPES_H +#define rpmSpec Spec +#endif + +#define MAX_WHITELIST_SIZE 16 + +#ifndef PATH_MAX +#include +#endif extern size_t strnlen(const char *s, size_t maxlen); /* the structure describing the options we take and the defaults */ static struct poptOption optionsTable[] = { + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0, + "Build options with [ | | ]:", + NULL }, + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0, "Common options for all rpm modes and executables:", NULL }, @@ -34,7 +47,7 @@ static struct poptOption optionsTable[] = { }; /* Stolen from rpm/build/spec.c:rpmspecQuery() */ -Spec +rpmSpec rpmspecGet(rpmts ts, const char * arg) { char * buildRoot = NULL; @@ -59,42 +72,69 @@ main(int argc, char *argv[]) poptContext context; rpmts ts = NULL; int ec = 0; - Spec spec; + rpmSpec spec; struct Source *source; Package pkg; const char *name, *version, *release, *arch, *unused; const char *package_name; + char **package_whitelist; + /* BEGIN: support to pull out --target from the args list */ int alen, i; char *target = NULL; int args = 1; - int tlen = strlen("--target"); + int whitelist_size=0; + package_whitelist = (char **) malloc(MAX_WHITELIST_SIZE * sizeof(char *)); + if (!package_whitelist) { + perror("Could not allocate package whitelist\n"); + exit(1); + } - /* walk argv list looking for --target */ + /* walk argv list looking for options */ while ((args+1) from argv */ - /* get arch component of the --target option */ - dash = (char**)strchr(argv[args+1],'-'); - if (dash != NULL) *dash=NULL; + int option_offset = 1; + char *whitelist_str = argv[args+1]; + if (whitelist_str != NULL) { + char *saveptr = NULL, *str; + option_offset = 2; + for (str = whitelist_str; ; str = NULL) { + char *token; + token = strtok_r(str, "," , &saveptr); + if (token == NULL) break; + package_whitelist[whitelist_size++] = token; + } + } + for (i=args;ifullSource, sizeof(fullSource)); - printf("%s-TARBALL += SOURCES/%s\n", package_name, basename(fullSource)); + printf("%s.tarballs += SOURCES/%s\n", package_name, basename(fullSource)); /* computes the SOURCEDIR variable by removing .tar.gz or .tar.bz2 */ { char *suffixes[] = {".tar.gz",".tgz",".tar.bz2", NULL}; @@ -131,14 +171,14 @@ main(int argc, char *argv[]) char *suffix_index; for (suffix=suffixes ; *suffix ; suffix++) { - printf("# trying %s\n",*suffix); + /*printf("# trying %s\n",*suffix);*/ suffix_index=strstr(fullSource,*suffix); if (suffix_index) { char sourcename[PATH_MAX]; - strncpy(sourcename,fullSource,suffix_index-fullSource); - *suffix_index='\0'; - printf ("%s-SOURCE := SOURCES/%s\n",package_name,basename(sourcename)); - printf ("%s-CODEBASE := CODEBASES/%s\n",package_name,package_name); + size_t len = (size_t)(suffix_index-fullSource); + strncpy(sourcename,fullSource,len); + sourcename[len]='\0'; + printf ("%s.source := SOURCES/%s\n",package_name,basename(sourcename)); break; } } @@ -151,39 +191,64 @@ main(int argc, char *argv[]) name = version = release = NULL; (void) headerNVR(pkg->header, &name, &version, &release); if (name && version && release) - printf("%s-SRPM := SRPMS/%s-%s-%s.src.rpm\n", + printf("%s.srpm := SRPMS/%s-%s-%s.src.rpm\n", package_name, name, version, release); /* Print non-empty packages */ for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { + int force = 0; 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("%s-RPM += RPMS/%s/%s-%s-%s.%s.rpm\n", - package_name, arch, name, version, release, arch); + /* skip empty packages + * + * Unfortunately, f8 + the RHEL kernel break this bit of cleverness. The following + * line returns false for the kernel-devel package even though it is not empty thereby breaking the build. + * Rather than unfolding the kernel package macros in the current specfile, + * this hack should work till f8 dies its natural death. + * To add rpms that are exempted in this way, add a "-WHITELIST-RPMS" tag in the tags file. + */ + + for (i=0;ifileList || force) { + /* attach (add) rpm path to package */ + printf("%s.rpms += RPMS/%s/%s-%s-%s.%s.rpm\n", + package_name, arch, name, version, release, arch); + /* convenience */ + printf("%s.rpmnames += %s\n", + package_name, name); + /* attach path to rpm name */ + printf("%s.rpm-path := RPMS/%s/%s-%s-%s.%s.rpm\n", + name,arch, name, version, release, arch); + /* attach package to rpm name for backward resolution - should be unique */ + printf("%s.package := %s\n", + name,package_name); + } } } /* export some macros to make */ + /* note : this relies on pl-specific conventions and might be wrong */ { - char *macros[] = { "release" , "name" , "version" , "subversion" , NULL } ; + char *macros[] = { "release" , "name" , "version" , "taglevel" , NULL } ; char **nav; char *macro=malloc(32); for (nav=macros; *nav; nav++) { sprintf(macro,"%%{%s}",*nav); char *value = rpmExpand(macro,NULL); - printf ("%s-rpm-%s := %s\n",package_name,*nav,value); + printf ("%s.rpm-%s := %s\n",package_name,*nav,value); } } + /* export arch */ + printf ("%s.rpm-arch := %s\n",package_name,target); + spec = freeSpec(spec); done: