2 #include "build/rpmbuild.h"
6 int buildplatform(char *arg, int buildAmount, char *passPhrase,
7 char *buildRoot, int fromTarball, int test, char *cookie,
11 int buildplatform(char *arg, int buildAmount, char *passPhrase,
12 char *buildRoot, int fromTarball, int test, char *cookie,
28 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
31 specDir = alloca(BUFSIZ);
32 strcpy(specDir, "%{_specdir}");
33 /* XXX can't use spec->macros yet */
34 expandMacros(NULL, &globalMacroContext, specDir, BUFSIZ);
36 tmpSpecFile = alloca(BUFSIZ);
37 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
39 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
40 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
42 if (!(f = popen(cmd, "r"))) {
43 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
47 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
51 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
53 if (!(f = popen(cmd, "r"))) {
54 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
58 if (!fgets(buf, sizeof(buf) - 1, f)) {
60 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
69 if (*cmd == '/') specfile = cmd + 1;
75 /* remove trailing \n */
76 specfile = cmd + strlen(cmd) - 1;
79 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
80 sprintf(specfile, "%s/%s", specDir, cmd);
82 if (rename(tmpSpecFile, specfile)) {
83 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
84 tmpSpecFile, specfile, strerror(errno));
89 /* Make the directory which contains the tarball the source
90 directory for this run */
93 (void)getcwd(buf, BUFSIZ);
99 cmd = buf + strlen(buf) - 1;
100 while (*cmd != '/') cmd--;
103 addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
104 } else if (arg[0] == '/') {
107 specfile = alloca(BUFSIZ);
108 (void)getcwd(specfile, BUFSIZ);
109 strcat(specfile, "/");
110 strcat(specfile, arg);
113 stat(specfile, &statbuf);
114 if (! S_ISREG(statbuf.st_mode)) {
115 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
119 if ((fd = open(specfile, O_RDONLY)) < 0) {
120 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
123 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
127 if (! (isprint(*s) || isspace(*s))) {
128 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
135 #define _anyarch(_f) \
136 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
137 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
138 _anyarch(buildAmount), force)) {
143 if (buildSpec(spec, buildAmount, test)) {
148 if (fromTarball) unlink(specfile);
155 int build(char *arg, int buildAmount, char *passPhrase,
156 char *buildRoot, int fromTarball, int test, char *cookie,
157 char * rcfile, char * arch, char * os,
158 char *buildplatforms, int force)
163 if (buildplatforms == NULL) {
164 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
165 fromTarball, test, cookie, force);
169 /* parse up the build operators */
171 printf("building these platforms: %s\n", buildplatforms);
174 while((platform = strtok(t, ",")) != NULL) {
176 printf("building %s\n", platform);
178 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
179 rpmReadConfigFiles(rcfile, arch, os, 1, platform);
180 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
181 fromTarball, test, cookie, force);