3 * Top-level build dispatcher.
8 #include <rpmio_internal.h>
13 static int _build_debug = 0;
17 static void doRmSource(Spec spec)
23 unlink(spec->specFile);
26 for (p = spec->sources; p != NULL; p = p->next) {
27 if (! (p->flags & RPMBUILD_ISNO)) {
28 const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
34 for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
35 for (p = pkg->icon; p != NULL; p = p->next) {
36 if (! (p->flags & RPMBUILD_ISNO)) {
37 const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
46 * @todo Single use by %%doc in files.c prevents static.
48 int doScript(Spec spec, int what, const char *name, StringBuf sb, int test)
50 const char * rootURL = spec->rootURL;
52 const char *scriptName = NULL;
53 const char * buildDirURL = rpmGenPath(rootURL, "%{_builddir}", "");
54 const char * buildScript;
55 const char * buildCmd = NULL;
56 const char * buildTemplate = NULL;
57 const char * buildPost = NULL;
58 const char * mTemplate = NULL;
59 const char * mPost = NULL;
61 const char **argv = NULL;
75 mTemplate = "%{__spec_prep_template}";
76 mPost = "%{__spec_prep_post}";
81 mTemplate = "%{__spec_build_template}";
82 mPost = "%{__spec_build_post}";
84 case RPMBUILD_INSTALL:
87 mTemplate = "%{__spec_install_template}";
88 mPost = "%{__spec_install_post}";
93 mTemplate = "%{__spec_clean_template}";
94 mPost = "%{__spec_clean_post}";
96 case RPMBUILD_RMBUILD:
98 mTemplate = "%{__spec_clean_template}";
99 mPost = "%{__spec_clean_post}";
101 case RPMBUILD_STRINGBUF:
103 mTemplate = "%{___build_template}";
104 mPost = "%{___build_post}";
108 if ((what != RPMBUILD_RMBUILD) && sb == NULL) {
113 if (makeTempFile(rootURL, &scriptName, &fd) || fd == NULL || Ferror(fd)) {
114 rpmError(RPMERR_SCRIPT, _("Unable to open temp file."));
123 (void)fchmod(Fileno(fd), 0600);
130 if (fdGetFp(fd) == NULL)
131 xfd = Fdopen(fd, "w.fpio");
134 if ((fp = fdGetFp(xfd)) == NULL) {
139 (void) urlPath(rootURL, &rootDir);
140 if (*rootDir == '\0') rootDir = "/";
142 (void) urlPath(scriptName, &buildScript);
144 buildTemplate = rpmExpand(mTemplate, NULL);
145 buildPost = rpmExpand(mPost, NULL);
147 fputs(buildTemplate, fp);
149 if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir)
150 fprintf(fp, "cd %s\n", spec->buildSubdir);
152 if (what == RPMBUILD_RMBUILD) {
153 if (spec->buildSubdir)
154 fprintf(fp, "rm -rf %s\n", spec->buildSubdir);
156 fprintf(fp, "%s", getStringBuf(sb));
158 fputs(buildPost, fp);
168 fprintf(stderr, "*** rootURL %s buildDirURL %s\n", rootURL, buildDirURL);
169 if (buildDirURL && buildDirURL[0] != '/' &&
170 (urlSplit(buildDirURL, &u) != 0)) {
175 switch (u->urltype) {
178 fprintf(stderr, "*** addMacros\n");
179 addMacro(spec->macros, "_remsh", NULL, "%{__remsh}", RMIL_SPEC);
180 addMacro(spec->macros, "_remhost", NULL, u->host, RMIL_SPEC);
181 if (strcmp(rootDir, "/"))
182 addMacro(spec->macros, "_remroot", NULL, rootDir, RMIL_SPEC);
190 buildCmd = rpmExpand("%{___build_cmd}", " ", buildScript, NULL);
191 poptParseArgvString(buildCmd, &argc, &argv);
193 rpmMessage(RPMMESS_NORMAL, _("Executing(%s): %s\n"), name, buildCmd);
194 if (!(child = fork())) {
197 execvp(argv[0], (char *const *)argv);
199 rpmError(RPMERR_SCRIPT, _("Exec of %s failed (%s): %s"), scriptName, name, strerror(errno));
204 rc = waitpid(child, &status, 0);
206 if (!WIFEXITED(status) || WEXITSTATUS(status)) {
207 rpmError(RPMERR_SCRIPT, _("Bad exit status from %s (%s)"),
217 free((void *)scriptName);
220 switch (u->urltype) {
224 fprintf(stderr, "*** delMacros\n");
225 delMacro(spec->macros, "_remsh");
226 delMacro(spec->macros, "_remhost");
227 if (strcmp(rootDir, "/"))
228 delMacro(spec->macros, "_remroot");
243 int buildSpec(Spec spec, int what, int test)
247 if (!spec->inBuildArchitectures && spec->buildArchitectureCount) {
249 /* When iterating over buildArchitectures, do the source */
250 /* packaging on the first run, and skip RMSOURCE altogether */
251 for (x = 0; x < spec->buildArchitectureCount; x++) {
252 if ((rc = buildSpec(spec->buildArchitectureSpecs[x],
253 (what & ~RPMBUILD_RMSOURCE) |
254 (x ? 0 : (what & RPMBUILD_PACKAGESOURCE)),
260 if ((what & RPMBUILD_PREP) &&
261 (rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test)))
264 if ((what & RPMBUILD_BUILD) &&
265 (rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test)))
268 if ((what & RPMBUILD_INSTALL) &&
269 (rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test)))
272 if ((what & RPMBUILD_PACKAGESOURCE) &&
273 (rc = processSourceFiles(spec)))
276 if (((what & RPMBUILD_INSTALL) || (what & RPMBUILD_PACKAGEBINARY) ||
277 (what & RPMBUILD_FILECHECK)) &&
278 (rc = processBinaryFiles(spec, what & RPMBUILD_INSTALL, test)))
281 if (((what & RPMBUILD_PACKAGESOURCE) && !test) &&
282 (rc = packageSources(spec)))
285 if (((what & RPMBUILD_PACKAGEBINARY) && !test) &&
286 (rc = packageBinaries(spec)))
289 if ((what & RPMBUILD_CLEAN) &&
290 (rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test)))
293 if ((what & RPMBUILD_RMBUILD) &&
294 (rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test)))
298 if (what & RPMBUILD_RMSOURCE)
301 if (what & RPMBUILD_RMSPEC)
302 unlink(spec->specFile);
305 if (rc && rpmlogGetNrecs() > 0) {
306 rpmMessage(RPMMESS_NORMAL, _("\n\nRPM build errors:\n"));