3 #include "build/rpmbuild.h"
8 int buildForTarget(char *arg, int buildAmount, char *passPhrase,
9 char *buildRoot, int fromTarball, int test, char *cookie,
13 static int buildForTarget(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 *targets, int force)
164 if (targets == NULL) {
165 rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
166 fromTarball, test, cookie, force);
170 /* parse up the build operators */
172 printf("Building target platforms: %s\n", targets);
175 while((target = strtok(t, ",")) != NULL) {
177 printf("Building for target %s\n", target);
179 rpmReadConfigFiles(rcfile, target);
180 rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
181 fromTarball, test, cookie, force);
189 #define POPT_USECATALOG 1000
190 #define POPT_NOLANG 1001
191 #define POPT_RMSOURCE 1002
192 #define POPT_RMBUILD 1003
193 #define POPT_BUILDROOT 1004
194 #define POPT_BUILDARCH 1005
195 #define POPT_BUILDOS 1006
196 #define POPT_TARGETPLATFORM 1007
197 #define POPT_NOBUILD 1008
198 #define POPT_SHORTCIRCUIT 1009
201 static int noBuild = 0;
202 static int useCatalog = 0;
204 static void buildArgCallback(poptContext con, enum poptCallbackReason reason,
205 const struct poptOption * opt, const char * arg,
206 struct rpmBuildArguments * data)
209 case POPT_USECATALOG: data->useCatalog = 1; break;
210 case POPT_NOBUILD: data->noBuild = 1; break;
211 case POPT_NOLANG: data->noLang = 1; break;
212 case POPT_SHORTCIRCUIT: data->shortCircuit = 1; break;
213 case POPT_RMSOURCE: data->buildAmount |= RPMBUILD_RMSOURCE; break;
214 case POPT_RMBUILD: data->buildAmount |= RPMBUILD_RMBUILD; break;
216 if (data->buildRootOverride) {
217 fprintf(stderr, _("buildroot already specified"));
220 data->buildRootOverride = strdup(arg);
223 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
227 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
230 case POPT_TARGETPLATFORM:
232 int len = strlen(data->targets) + strlen(arg) + 2;
233 data->targets = realloc(data->targets, len);
234 strcat(data->targets, ",");
236 data->targets = malloc(strlen(arg) + 1);
237 data->targets[0] = '\0';
239 strcat(data->targets, arg);
244 struct poptOption rpmBuildPoptTable[] = {
245 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
246 buildArgCallback, 0, NULL, NULL },
247 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
248 N_("override build architecture"), "ARCH" },
249 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
250 N_("override build operating system"), "OS" },
251 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
252 N_("override build root"), "DIRECTORY" },
253 { "clean", '\0', 0, 0, POPT_RMBUILD,
254 N_("remove build tree when done"), NULL},
255 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
256 N_("do not execute any stages of the build"), NULL },
257 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
258 N_("do not accept I18N msgstr's from specfile"), NULL},
259 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
260 N_("remove sources and specfile when done"), NULL},
261 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
262 N_("skip straight to specified stage (only for c,i)"), NULL },
263 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
264 N_("override target platform"), "CPU-VENDOR-OS" },
265 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
266 N_("lookup I18N strings in specfile catalog"), NULL},
267 { 0, 0, 0, 0, 0, NULL, NULL }