3 #include "build/rpmbuild.h"
8 int buildplatform(char *arg, int buildAmount, char *passPhrase,
9 char *buildRoot, int fromTarball, int test, char *cookie,
13 int buildplatform(char *arg, int buildAmount, char *passPhrase,
14 char *buildRoot, int fromTarball, int test, char *cookie,
30 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
33 specDir = alloca(BUFSIZ);
34 strcpy(specDir, "%{_specdir}");
35 /* XXX can't use spec->macros yet */
36 expandMacros(NULL, &globalMacroContext, specDir, BUFSIZ);
38 tmpSpecFile = alloca(BUFSIZ);
39 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
41 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
42 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
44 if (!(f = popen(cmd, "r"))) {
45 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
49 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
53 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
55 if (!(f = popen(cmd, "r"))) {
56 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
60 if (!fgets(buf, sizeof(buf) - 1, f)) {
62 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
71 if (*cmd == '/') specfile = cmd + 1;
77 /* remove trailing \n */
78 specfile = cmd + strlen(cmd) - 1;
81 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
82 sprintf(specfile, "%s/%s", specDir, cmd);
84 if (rename(tmpSpecFile, specfile)) {
85 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
86 tmpSpecFile, specfile, strerror(errno));
91 /* Make the directory which contains the tarball the source
92 directory for this run */
95 (void)getcwd(buf, BUFSIZ);
101 cmd = buf + strlen(buf) - 1;
102 while (*cmd != '/') cmd--;
105 addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
106 } else if (arg[0] == '/') {
109 specfile = alloca(BUFSIZ);
110 (void)getcwd(specfile, BUFSIZ);
111 strcat(specfile, "/");
112 strcat(specfile, arg);
115 stat(specfile, &statbuf);
116 if (! S_ISREG(statbuf.st_mode)) {
117 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
121 if ((fd = open(specfile, O_RDONLY)) < 0) {
122 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
125 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
129 if (! (isprint(*s) || isspace(*s))) {
130 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
137 #define _anyarch(_f) \
138 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
139 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
140 _anyarch(buildAmount), force)) {
145 if (buildSpec(spec, buildAmount, test)) {
150 if (fromTarball) unlink(specfile);
157 int build(char *arg, int buildAmount, char *passPhrase,
158 char *buildRoot, int fromTarball, int test, char *cookie,
159 char * rcfile, char * arch, char * os,
160 char *buildplatforms, int force)
165 if (buildplatforms == NULL) {
166 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
167 fromTarball, test, cookie, force);
171 /* parse up the build operators */
173 printf("building these platforms: %s\n", buildplatforms);
176 while((platform = strtok(t, ",")) != NULL) {
178 printf("building %s\n", platform);
180 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
181 rpmReadConfigFiles(rcfile, arch, os, 1, platform);
182 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
183 fromTarball, test, cookie, force);
191 #define POPT_USECATALOG 1000
192 #define POPT_NOLANG 1001
193 #define POPT_RMSOURCE 1002
194 #define POPT_RMBUILD 1003
195 #define POPT_BUILDROOT 1004
198 static int useCatalog = 0;
200 static void buildArgCallback(poptContext con, enum poptCallbackReason reason,
201 const struct poptOption * opt, const char * arg,
202 struct rpmBuildArguments * data)
205 case POPT_USECATALOG: data->useCatalog = 1; break;
206 case POPT_NOLANG: data->noLang = 1; break;
207 case POPT_RMSOURCE: data->buildAmount |= RPMBUILD_RMSOURCE; break;
208 case POPT_RMBUILD: data->buildAmount |= RPMBUILD_RMBUILD; break;
210 if (data->buildRootOverride) {
211 fprintf(stderr, _("buildroot already specified"));
214 data->buildRootOverride = strdup(arg);
219 struct poptOption rpmBuildPoptTable[] = {
220 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
221 buildArgCallback, 0, NULL, NULL },
222 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
223 N_("override build root"), "DIRECTORY" },
224 { "clean", '\0', 0, 0, POPT_RMBUILD,
225 N_("remove build tree when done"), NULL},
226 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
227 N_("do not accept I18N msgstr's from specfile"), NULL},
228 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
229 N_("remove sources and specfile when done"), NULL},
230 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
231 N_("lookup I18N strings in specfile catalog"), NULL},
232 { 0, 0, 0, 0, 0, NULL, NULL }