2 #include "build/rpmbuild.h"
5 int buildplatform(char *arg, int buildAmount, char *passPhrase,
6 char *buildRoot, int fromTarball, int test, char *cookie);
8 int buildplatform(char *arg, int buildAmount, char *passPhrase,
9 char *buildRoot, int fromTarball, int test, char *cookie)
24 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
27 specDir = alloca(BUFSIZ);
28 strcpy(specDir, "%{_specdir}");
29 /* XXX can't use spec->macros yet */
30 expandMacros(NULL, &globalMacroContext, specDir, BUFSIZ);
32 tmpSpecFile = alloca(BUFSIZ);
33 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
35 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
36 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
38 if (!(f = popen(cmd, "r"))) {
39 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
43 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
47 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
49 if (!(f = popen(cmd, "r"))) {
50 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
54 if (!fgets(buf, sizeof(buf) - 1, f)) {
56 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
65 if (*cmd == '/') specfile = cmd + 1;
71 /* remove trailing \n */
72 specfile = cmd + strlen(cmd) - 1;
75 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
76 sprintf(specfile, "%s/%s", specDir, cmd);
78 if (rename(tmpSpecFile, specfile)) {
79 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
80 tmpSpecFile, specfile, strerror(errno));
85 /* Make the directory which contains the tarball the source
86 directory for this run */
95 cmd = buf + strlen(buf) - 1;
96 while (*cmd != '/') cmd--;
99 addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
100 } else if (arg[0] == '/') {
103 specfile = alloca(BUFSIZ);
104 getcwd(specfile, BUFSIZ);
105 strcat(specfile, "/");
106 strcat(specfile, arg);
109 stat(specfile, &statbuf);
110 if (! S_ISREG(statbuf.st_mode)) {
111 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
115 if ((fd = open(specfile, O_RDONLY)) < 0) {
116 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
119 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
123 if (! (isprint(*s) || isspace(*s))) {
124 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
131 #define _anyarch(_f) \
132 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
133 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
134 _anyarch(buildAmount))) {
139 if (buildSpec(spec, buildAmount, test)) {
144 if (fromTarball) unlink(specfile);
151 int build(char *arg, int buildAmount, char *passPhrase,
152 char *buildRoot, int fromTarball, int test, char *cookie,
153 char * rcfile, char * arch, char * os,
154 char *buildplatforms)
159 if (buildplatforms == NULL) {
160 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
161 fromTarball, test, cookie);
165 /* parse up the build operators */
167 printf("building these platforms: %s\n", buildplatforms);
170 while((platform = strtok(t, ",")) != NULL) {
172 printf("building %s\n", platform);
174 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
175 rpmReadConfigFiles(rcfile, arch, os, 1, platform);
176 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
177 fromTarball, test, cookie);