1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "rpmbuild.h"
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#ifdef DYING
|
1998-01-13 05:31:29 +08:00
|
|
|
static void doRmSource(Spec spec);
|
1998-07-26 05:00:26 +08:00
|
|
|
#endif
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
static void doRmSource(Spec spec)
|
1995-11-28 06:31:21 +08:00
|
|
|
{
|
1998-07-26 05:00:26 +08:00
|
|
|
struct Source *p;
|
|
|
|
Package pkg;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
unlink(spec->specFile);
|
1995-12-18 22:53:14 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
p = spec->sources;
|
|
|
|
while (p) {
|
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
1998-09-06 04:02:08 +08:00
|
|
|
strcpy(buf, "%{_sourcedir}/");
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
strcat(buf, p->source);
|
1998-07-26 05:00:26 +08:00
|
|
|
unlink(buf);
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
p = p->next;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
pkg = spec->packages;
|
|
|
|
while (pkg) {
|
|
|
|
p = pkg->icon;
|
|
|
|
while (p) {
|
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
1998-09-06 04:02:08 +08:00
|
|
|
strcpy(buf, "%{_sourcedir}/");
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
strcat(buf, p->source);
|
1998-07-26 05:00:26 +08:00
|
|
|
unlink(buf);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
p = p->next;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
pkg = pkg->next;
|
|
|
|
}
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
/*
|
|
|
|
* The _preScript string is expanded to export values to a script environment.
|
|
|
|
*/
|
|
|
|
|
1998-09-06 07:13:35 +08:00
|
|
|
static char *_preScriptEnvironment = "%{_preScriptEnvironment}";
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
static char *_preScriptChdir =
|
|
|
|
"umask 022\n"
|
|
|
|
"cd %{_builddir}\n"
|
|
|
|
;
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int doScript(Spec spec, int what, char *name, StringBuf sb, int test)
|
1996-01-08 15:06:16 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
int fd;
|
|
|
|
FILE *f;
|
|
|
|
char *scriptName;
|
|
|
|
int pid;
|
|
|
|
int status;
|
1998-01-26 01:03:30 +08:00
|
|
|
char *buildShell;
|
1998-09-06 07:13:35 +08:00
|
|
|
char buf[BUFSIZ];
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case RPMBUILD_PREP:
|
|
|
|
name = "%prep";
|
|
|
|
sb = spec->prep;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_BUILD:
|
|
|
|
name = "%build";
|
|
|
|
sb = spec->build;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_INSTALL:
|
|
|
|
name = "%install";
|
|
|
|
sb = spec->install;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_CLEAN:
|
|
|
|
name = "%clean";
|
|
|
|
sb = spec->clean;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_RMBUILD:
|
|
|
|
name = "--clean";
|
|
|
|
break;
|
|
|
|
case RPMBUILD_STRINGBUF:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((what != RPMBUILD_RMBUILD) && !sb) {
|
|
|
|
return 0;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-09-06 07:13:35 +08:00
|
|
|
if (makeTempFile(NULL, &scriptName, &fd) ||
|
|
|
|
fchmod(fd, 0600) < 0 ||
|
|
|
|
(f = fdopen(fd, "w")) == NULL) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Unable to open temp file"));
|
1998-09-06 07:13:35 +08:00
|
|
|
return RPMERR_SCRIPT;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 07:13:35 +08:00
|
|
|
strcpy(buf, _preScriptEnvironment);
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
strcat(buf, "\n");
|
|
|
|
fputs(buf, f);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(f, rpmIsVerbose() ? "set -x\n\n" : "exec > /dev/null\n\n");
|
1998-09-06 04:02:08 +08:00
|
|
|
|
|
|
|
/* XXX umask 022; cd %{_builddir} */
|
|
|
|
strcpy(buf, _preScriptChdir);
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
fputs(buf, f);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD) {
|
1998-01-15 06:02:01 +08:00
|
|
|
if (spec->buildSubdir) {
|
|
|
|
fprintf(f, "cd %s\n", spec->buildSubdir);
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
if (what == RPMBUILD_RMBUILD) {
|
1998-04-08 22:22:41 +08:00
|
|
|
if (spec->buildSubdir) {
|
|
|
|
fprintf(f, "rm -rf %s\n", spec->buildSubdir);
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
} else {
|
|
|
|
fprintf(f, "%s", getStringBuf(sb));
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(f, "\nexit 0\n");
|
|
|
|
|
|
|
|
fclose(f);
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (test) {
|
|
|
|
FREE(scriptName);
|
|
|
|
return 0;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Executing: %s\n"), name);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (!(pid = fork())) {
|
1998-01-26 01:03:30 +08:00
|
|
|
buildShell = rpmGetVar(RPMVAR_BUILDSHELL);
|
|
|
|
execl(buildShell, buildShell, "-e", scriptName, scriptName, NULL);
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Exec of %s failed (%s)"),
|
1998-01-13 05:31:29 +08:00
|
|
|
scriptName, name);
|
1998-04-20 09:15:41 +08:00
|
|
|
unlink(scriptName);
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(scriptName);
|
|
|
|
return RPMERR_SCRIPT;
|
1996-01-29 11:32:22 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
wait(&status);
|
|
|
|
if (! WIFEXITED(status) || WEXITSTATUS(status)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Bad exit status from %s (%s)"),
|
1998-01-13 05:31:29 +08:00
|
|
|
scriptName, name);
|
1998-09-06 07:13:35 +08:00
|
|
|
#if HACK
|
1998-04-20 09:15:41 +08:00
|
|
|
unlink(scriptName);
|
1998-09-06 07:13:35 +08:00
|
|
|
#endif
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(scriptName);
|
|
|
|
return RPMERR_SCRIPT;
|
1997-04-15 04:05:12 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
unlink(scriptName);
|
|
|
|
FREE(scriptName);
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
return 0;
|
1995-12-14 23:56:10 +08:00
|
|
|
}
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
int buildSpec(Spec spec, int what, int test)
|
1995-12-14 23:56:10 +08:00
|
|
|
{
|
1998-07-26 05:00:26 +08:00
|
|
|
int x, rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
if (!spec->inBuildArchitectures && spec->buildArchitectureCount) {
|
|
|
|
/* When iterating over buildArchitectures, do the source */
|
|
|
|
/* packaging on the first run, and skip RMSOURCE altogether */
|
|
|
|
x = 0;
|
|
|
|
while (x < spec->buildArchitectureCount) {
|
|
|
|
if ((rc = buildSpec(spec->buildArchitectureSpecs[x],
|
|
|
|
(what & ~RPMBUILD_RMSOURCE) |
|
|
|
|
(x ? 0 : (what & RPMBUILD_PACKAGESOURCE)),
|
|
|
|
test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (what & RPMBUILD_PREP) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & RPMBUILD_BUILD) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & RPMBUILD_INSTALL) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
if (what & RPMBUILD_PACKAGESOURCE) {
|
|
|
|
if ((rc = processSourceFiles(spec))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
if ((what & RPMBUILD_INSTALL) || (what & RPMBUILD_PACKAGEBINARY) ||
|
|
|
|
(what & RPMBUILD_FILECHECK)) {
|
|
|
|
if ((rc = processBinaryFiles(spec, what & RPMBUILD_INSTALL,
|
|
|
|
test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|
1998-04-10 00:46:30 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
if (what & RPMBUILD_PACKAGESOURCE && !test) {
|
|
|
|
if ((rc = packageSources(spec))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & RPMBUILD_PACKAGEBINARY && !test) {
|
|
|
|
if ((rc = packageBinaries(spec))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what & RPMBUILD_CLEAN) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & RPMBUILD_RMBUILD) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test))) {
|
|
|
|
return rc;
|
1998-04-10 00:46:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
|
|
|
|
if (what & RPMBUILD_RMSOURCE) {
|
|
|
|
doRmSource(spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|