1998-03-05 00:51:06 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_ALLOCA_A
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <sys/types.h>
|
1995-12-14 23:56:10 +08:00
|
|
|
#include <sys/wait.h>
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <sys/stat.h>
|
1998-02-26 02:31:52 +08:00
|
|
|
#include <stdlib.h>
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "misc.h"
|
1995-11-28 06:31:21 +08:00
|
|
|
#include "spec.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "build.h"
|
|
|
|
#include "lib/misc.h"
|
|
|
|
#include "lib/messages.h"
|
1995-12-18 22:53:14 +08:00
|
|
|
#include "rpmlib.h"
|
1995-12-21 07:34:12 +08:00
|
|
|
#include "pack.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "files.h"
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
static void doRmSource(Spec spec);
|
|
|
|
static int writeVars(Spec spec, FILE *f);
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int buildSpec(Spec spec, int what, int test)
|
1995-11-28 06:31:21 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
int x, rc;
|
1995-12-18 22:53:14 +08:00
|
|
|
|
1998-01-13 05:31:29 +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++;
|
|
|
|
}
|
1996-02-19 10:27:35 +08:00
|
|
|
} else {
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what & RPMBUILD_PREP) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
1996-06-08 02:27:56 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what & RPMBUILD_BUILD) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what & RPMBUILD_INSTALL) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what & RPMBUILD_PACKAGESOURCE) {
|
|
|
|
if ((rc = processSourceFiles(spec))) {
|
|
|
|
return rc;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((what & RPMBUILD_INSTALL) || (what & RPMBUILD_PACKAGEBINARY) ||
|
|
|
|
(what & RPMBUILD_FILECHECK)) {
|
|
|
|
if ((rc = processBinaryFiles(spec, what & RPMBUILD_INSTALL))) {
|
|
|
|
return rc;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1998-01-15 06:04:06 +08:00
|
|
|
if (what & RPMBUILD_PACKAGESOURCE && !test) {
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = packageSources(spec))) {
|
|
|
|
return rc;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-01-15 06:04:06 +08:00
|
|
|
if (what & RPMBUILD_PACKAGEBINARY && !test) {
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = packageBinaries(spec))) {
|
|
|
|
return rc;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (what & RPMBUILD_CLEAN) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test))) {
|
|
|
|
return rc;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
if (what & RPMBUILD_RMBUILD) {
|
|
|
|
if ((rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test))) {
|
|
|
|
return rc;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what & RPMBUILD_RMSOURCE) {
|
|
|
|
doRmSource(spec);
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
|
|
|
if (makeTempFile(NULL, &scriptName, &fd)) {
|
|
|
|
rpmError(RPMERR_SCRIPT, "Unable to open temp file");
|
|
|
|
return RPMERR_SCRIPT;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
f = fdopen(fd, "w");
|
1996-01-08 15:06:16 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (writeVars(spec, f)) {
|
|
|
|
fclose(f);
|
|
|
|
FREE(scriptName);
|
|
|
|
return RPMERR_SCRIPT;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(f, rpmIsVerbose() ? "set -x\n\n" : "exec > /dev/null\n\n");
|
|
|
|
fprintf(f, "umask 022\n");
|
|
|
|
fprintf(f, "cd %s\n", rpmGetVar(RPMVAR_BUILDDIR));
|
|
|
|
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);
|
|
|
|
chmod(scriptName, 0600);
|
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
|
|
|
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Executing: %s\n", name);
|
|
|
|
if (!(pid = fork())) {
|
1998-01-26 01:03:30 +08:00
|
|
|
buildShell = rpmGetVar(RPMVAR_BUILDSHELL);
|
|
|
|
execl(buildShell, buildShell, "-e", scriptName, scriptName, NULL);
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, "Exec of %s failed (%s)",
|
|
|
|
scriptName, name);
|
|
|
|
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)) {
|
|
|
|
rpmError(RPMERR_SCRIPT, "Bad exit status from %s (%s)",
|
|
|
|
scriptName, name);
|
|
|
|
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-01-13 05:31:29 +08:00
|
|
|
static int writeVars(Spec spec, FILE *f)
|
1995-12-14 23:56:10 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
char *arch, *os, *s;
|
|
|
|
|
|
|
|
rpmGetArchInfo(&arch, NULL);
|
|
|
|
rpmGetOsInfo(&os, NULL);
|
1997-04-15 04:05:12 +08:00
|
|
|
|
1998-01-15 23:03:08 +08:00
|
|
|
fprintf(f, "RPM_SOURCE_DIR=\"%s\"\n", rpmGetVar(RPMVAR_SOURCEDIR));
|
|
|
|
fprintf(f, "RPM_BUILD_DIR=\"%s\"\n", rpmGetVar(RPMVAR_BUILDDIR));
|
|
|
|
fprintf(f, "RPM_DOC_DIR=\"%s\"\n", spec->docDir);
|
|
|
|
fprintf(f, "RPM_OPT_FLAGS=\"%s\"\n", rpmGetVar(RPMVAR_OPTFLAGS));
|
|
|
|
fprintf(f, "RPM_ARCH=\"%s\"\n", arch);
|
|
|
|
fprintf(f, "RPM_OS=\"%s\"\n", os);
|
|
|
|
fprintf(f, "export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_DOC_DIR "
|
|
|
|
"RPM_OPT_FLAGS RPM_ARCH RPM_OS\n");
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
if (spec->buildRoot) {
|
1998-01-15 23:03:08 +08:00
|
|
|
fprintf(f, "RPM_BUILD_ROOT=\"%s\"\n", spec->buildRoot);
|
|
|
|
fprintf(f, "export RPM_BUILD_ROOT\n");
|
1998-01-13 05:31:29 +08:00
|
|
|
/* This could really be checked internally */
|
|
|
|
fprintf(f, "if [ -z \"$RPM_BUILD_ROOT\" -o -z \"`echo $RPM_BUILD_ROOT | sed -e 's#/##g'`\" ]; then\n");
|
|
|
|
fprintf(f, " echo 'Warning: Spec contains BuildRoot: tag that is either empty or is set to \"/\"'\n");
|
|
|
|
fprintf(f, " exit 1\n");
|
|
|
|
fprintf(f, "fi\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_NAME,
|
|
|
|
NULL, (void **)&s, NULL);
|
1998-01-15 23:03:08 +08:00
|
|
|
fprintf(f, "RPM_PACKAGE_NAME=\"%s\"\n", s);
|
1998-01-13 05:31:29 +08:00
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_VERSION,
|
|
|
|
NULL, (void **)&s, NULL);
|
1998-01-15 23:03:08 +08:00
|
|
|
fprintf(f, "RPM_PACKAGE_VERSION=\"%s\"\n", s);
|
1998-01-13 05:31:29 +08:00
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_RELEASE,
|
|
|
|
NULL, (void **)&s, NULL);
|
1998-01-15 23:03:08 +08:00
|
|
|
fprintf(f, "RPM_PACKAGE_RELEASE=\"%s\"\n", s);
|
|
|
|
fprintf(f, "export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION "
|
|
|
|
"RPM_PACKAGE_RELEASE\n");
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
return 0;
|
1995-11-28 06:31:21 +08:00
|
|
|
}
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
static void doRmSource(Spec spec)
|
1995-12-20 05:08:18 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
struct Source *p;
|
1998-04-10 00:46:30 +08:00
|
|
|
Package pkg;
|
1998-01-13 05:31:29 +08:00
|
|
|
char buf[BUFSIZ];
|
1996-09-02 09:58:13 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(spec->specFile);
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
p = spec->sources;
|
|
|
|
while (p) {
|
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
|
|
|
sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), p->source);
|
|
|
|
unlink(buf);
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
p = p->next;
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|
1998-04-10 00:46:30 +08:00
|
|
|
|
|
|
|
pkg = spec->packages;
|
|
|
|
while (pkg) {
|
|
|
|
p = pkg->icon;
|
|
|
|
while (p) {
|
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
|
|
|
sprintf(buf, "%s/%s", rpmGetVar(RPMVAR_SOURCEDIR), p->source);
|
|
|
|
unlink(buf);
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
pkg = pkg->next;
|
|
|
|
}
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|