/* RPM - Copyright (C) 1995 Red Hat Software
*
- * build.c - routines for building a package
+ * build.c - routines for preparing and building the sources
*/
#include <stdlib.h>
#include "spec.h"
#include "specP.h"
#include "rpmerr.h"
+#include "rpmlib.h"
#include "messages.h"
#include "stringbuf.h"
+#include "var.h"
struct Script {
char *name;
FILE *file;
};
-struct Script *openScript(void);
+struct Script *openScript(Spec spec);
void writeScript(struct Script *script, char *s);
int execScript(struct Script *script);
-void closeScript(struct Script *script);
+void freeScript(struct Script *script);
+int execPart(Spec s, char *sb, char *name);
-struct Script *openScript(void)
+struct Script *openScript(Spec spec)
{
struct Script *script = malloc(sizeof(struct Script));
+ struct PackageRec *main_package = spec->packages;
+ char *s;
+ int_32 foo;
+
+ if (! main_package) {
+ error(RPMERR_INTERNAL, "Empty main package");
+ exit(RPMERR_INTERNAL);
+ }
script->name = tempnam("/usr/tmp", "rpmbuild");
script->file = fopen(script->name, "w");
- fprintf(script->file, "#!/bin/sh\n");
+
+ /* Prepare the script */
+ fprintf(script->file,
+ "#!/bin/sh -e\n"
+ "# Script generated by rpm\n\n");
+
+ if (isVerbose()) {
+ fprintf(script->file, "set -x\n\n");
+ } else {
+ fprintf(script->file, "exec > /dev/null\n\n");
+ }
+
+ fprintf(script->file, "RPM_SOURCE_DIR=\"%s\"\n", getVar(RPMVAR_SOURCEDIR));
+ fprintf(script->file, "RPM_BUILD_DIR=\"%s\"\n", getVar(RPMVAR_BUILDDIR));
+ fprintf(script->file, "RPM_DOC_DIR=\"%s\"\n", getVar(RPMVAR_DOCDIR));
+ fprintf(script->file, "RPM_OPT_FLAGS=\"%s\"\n", getVar(RPMVAR_OPTFLAGS));
+
+ getEntry(main_package->header, RPMTAG_VERSION, &foo, (void **)&s, &foo);
+ fprintf(script->file, "RPM_PACKAGE_VERSION=\"%s\"\n", s);
+ getEntry(main_package->header, RPMTAG_RELEASE, &foo, (void **)&s, &foo);
+ fprintf(script->file, "RPM_PACKAGE_RELEASE=\"%s\"\n", s);
+
+ fprintf(script->file, "\ncd %s\n\n", getVar(RPMVAR_BUILDDIR));
return script;
}
int pid;
int status;
+ writeScript(script, "\nexit 0;\n");
fclose(script->file);
chmod(script->name, 0700);
+
if (!(pid = fork())) {
execl(script->name, script->name, NULL);
error(RPMERR_SCRIPT, "Exec failed");
return 0;
}
-void closeScript(struct Script *script)
+void freeScript(struct Script *script)
{
fclose(script->file);
unlink(script->name);
free(script);
}
-int execPrep(Spec s)
+int execPart(Spec s, char *sb, char *name)
{
struct Script *script;
- script = openScript();
- writeScript(script, getStringBuf(s->prep));
+ script = openScript(s);
+ writeScript(script, sb);
execScript(script);
- closeScript(script);
+ freeScript(script);
return 0;
}
-int execBuild(Spec s)
+int execPrep(Spec s)
{
- struct Script *script;
+ /* XXX Expand macros here */
+ return execPart(s, getStringBuf(s->prep), "%prep");
+}
- script = openScript();
- writeScript(script, getStringBuf(s->build));
- execScript(script);
- closeScript(script);
- return 0;
+int execBuild(Spec s)
+{
+ return execPart(s, getStringBuf(s->build), "%build");
}
int execInstall(Spec s)
{
- struct Script *script;
-
- script = openScript();
- writeScript(script, getStringBuf(s->install));
- execScript(script);
- closeScript(script);
- return 0;
+ return execPart(s, getStringBuf(s->install), "%install");
}
int execClean(Spec s)
{
- struct Script *script;
-
- script = openScript();
- writeScript(script, getStringBuf(s->clean));
- execScript(script);
- closeScript(script);
- return 0;
+ return execPart(s, getStringBuf(s->clean), "%clean");
}
int verifyList(Spec s)
{
-}
-
-int packageBinaries(Spec s)
-{
-}
-
-int packageSource(Spec s)
-{
+ return 0;
}