1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-12-02 01:18:38 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "build/rpmbuild.h"
|
1998-12-02 01:18:38 +08:00
|
|
|
#include "popt/popt.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "build.h"
|
|
|
|
|
1998-11-08 08:15:33 +08:00
|
|
|
#ifdef DYING
|
1998-12-02 07:28:26 +08:00
|
|
|
int buildForTarget(char *arg, int buildAmount, char *passPhrase,
|
1998-11-08 08:15:33 +08:00
|
|
|
char *buildRoot, int fromTarball, int test, char *cookie,
|
|
|
|
force);
|
|
|
|
#endif
|
1998-08-07 03:27:54 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
static int buildForTarget(const char *arg, int buildAmount, const char *passPhrase,
|
|
|
|
const char *buildRoot, int fromTarball, int test, char *cookie,
|
1998-11-08 08:15:33 +08:00
|
|
|
int force)
|
1998-08-09 06:27:08 +08:00
|
|
|
{
|
1998-08-07 03:27:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
FILE *f;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char * specfile;
|
1998-01-13 05:31:29 +08:00
|
|
|
int res = 0;
|
|
|
|
struct stat statbuf;
|
|
|
|
char * s;
|
|
|
|
int count, fd;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
Spec spec = NULL;
|
|
|
|
|
1998-09-23 21:31:54 +08:00
|
|
|
rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (fromTarball) {
|
1999-01-06 07:13:56 +08:00
|
|
|
const char *specDir;
|
|
|
|
const char * tmpSpecFile;
|
1999-01-07 01:33:50 +08:00
|
|
|
char * cmd, *s;
|
1998-09-06 05:54:05 +08:00
|
|
|
|
1999-01-06 07:13:56 +08:00
|
|
|
specDir = rpmGetPath("%{_specdir}", NULL);
|
|
|
|
|
1999-01-14 03:28:12 +08:00
|
|
|
{ char tfn[64];
|
|
|
|
strcpy(tfn, "rpm-spec.XXXXXX");
|
1999-01-27 23:40:06 +08:00
|
|
|
tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
|
1999-01-14 03:28:12 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
|
1999-01-14 03:28:12 +08:00
|
|
|
sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
|
|
|
|
arg, tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (!(f = popen(cmd, "r"))) {
|
|
|
|
fprintf(stderr, _("Failed to open tar pipe: %s\n"),
|
|
|
|
strerror(errno));
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(specDir);
|
|
|
|
xfree(tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1998-04-02 00:02:05 +08:00
|
|
|
if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
|
|
|
|
/* Try again */
|
|
|
|
pclose(f);
|
|
|
|
|
|
|
|
sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
|
|
|
|
tmpSpecFile);
|
|
|
|
if (!(f = popen(cmd, "r"))) {
|
|
|
|
fprintf(stderr, _("Failed to open tar pipe: %s\n"),
|
|
|
|
strerror(errno));
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(specDir);
|
|
|
|
xfree(tmpSpecFile);
|
1998-04-02 00:02:05 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!fgets(buf, sizeof(buf) - 1, f)) {
|
|
|
|
/* Give up */
|
|
|
|
fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
|
|
|
|
unlink(tmpSpecFile);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(specDir);
|
|
|
|
xfree(tmpSpecFile);
|
|
|
|
return 1;
|
1998-04-02 00:02:05 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
cmd = s = buf;
|
1998-01-13 05:31:29 +08:00
|
|
|
while (*cmd) {
|
1999-01-07 01:33:50 +08:00
|
|
|
if (*cmd == '/') s = cmd + 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
cmd++;
|
|
|
|
}
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
cmd = s;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* remove trailing \n */
|
1999-01-07 01:33:50 +08:00
|
|
|
s = cmd + strlen(cmd) - 1;
|
|
|
|
*s = '\0';
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
s = alloca(strlen(specDir) + strlen(cmd) + 5);
|
|
|
|
sprintf(s, "%s/%s", specDir, cmd);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
if (rename(tmpSpecFile, s)) {
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
|
1999-01-07 01:33:50 +08:00
|
|
|
tmpSpecFile, s, strerror(errno));
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(tmpSpecFile);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(specDir);
|
|
|
|
xfree(tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make the directory which contains the tarball the source
|
|
|
|
directory for this run */
|
|
|
|
|
|
|
|
if (*arg != '/') {
|
1998-11-17 05:40:28 +08:00
|
|
|
(void)getcwd(buf, BUFSIZ);
|
1998-01-13 05:31:29 +08:00
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, arg);
|
|
|
|
} else
|
|
|
|
strcpy(buf, arg);
|
|
|
|
|
|
|
|
cmd = buf + strlen(buf) - 1;
|
|
|
|
while (*cmd != '/') cmd--;
|
|
|
|
*cmd = '\0';
|
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
|
1999-01-06 07:13:56 +08:00
|
|
|
xfree(specDir);
|
|
|
|
xfree(tmpSpecFile);
|
1999-01-07 01:33:50 +08:00
|
|
|
specfile = s;
|
1998-01-13 05:31:29 +08:00
|
|
|
} else if (arg[0] == '/') {
|
|
|
|
specfile = arg;
|
|
|
|
} else {
|
1999-01-07 01:33:50 +08:00
|
|
|
char *s = alloca(BUFSIZ);
|
|
|
|
(void)getcwd(s, BUFSIZ);
|
|
|
|
strcat(s, "/");
|
|
|
|
strcat(s, arg);
|
|
|
|
specfile = s;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stat(specfile, &statbuf);
|
|
|
|
if (! S_ISREG(statbuf.st_mode)) {
|
|
|
|
fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-07-16 22:23:41 +08:00
|
|
|
if ((fd = open(specfile, O_RDONLY)) < 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
|
|
|
|
return 1;
|
|
|
|
}
|
1998-04-02 00:02:05 +08:00
|
|
|
count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
|
1998-01-13 05:31:29 +08:00
|
|
|
close(fd);
|
|
|
|
s = buf;
|
|
|
|
while(count--) {
|
|
|
|
if (! (isprint(*s) || isspace(*s))) {
|
|
|
|
fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
|
|
|
|
specfile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
1998-09-25 04:36:54 +08:00
|
|
|
#define _anyarch(_f) \
|
1998-11-08 06:05:28 +08:00
|
|
|
(((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
|
1998-09-25 04:36:54 +08:00
|
|
|
if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
|
1998-11-08 08:15:33 +08:00
|
|
|
_anyarch(buildAmount), force)) {
|
1998-09-25 04:36:54 +08:00
|
|
|
return 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-09-25 04:36:54 +08:00
|
|
|
#undef _anyarch
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
if (buildSpec(spec, buildAmount, test)) {
|
|
|
|
freeSpec(spec);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fromTarball) unlink(specfile);
|
|
|
|
|
|
|
|
freeSpec(spec);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
1998-08-09 06:27:08 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
int build(const char *arg, int buildAmount, const char *passPhrase,
|
|
|
|
const char *buildRoot, int fromTarball, int test, char *cookie,
|
|
|
|
const char * rcfile, char *targets, int force)
|
1998-08-09 06:27:08 +08:00
|
|
|
{
|
1999-03-18 02:11:01 +08:00
|
|
|
char *t, *te;
|
1998-08-09 06:27:08 +08:00
|
|
|
int rc;
|
|
|
|
|
1998-12-02 07:28:26 +08:00
|
|
|
if (targets == NULL) {
|
|
|
|
rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
|
1998-11-08 08:15:33 +08:00
|
|
|
fromTarball, test, cookie, force);
|
1998-08-09 06:27:08 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1998-08-16 22:26:04 +08:00
|
|
|
/* parse up the build operators */
|
|
|
|
|
1998-12-02 07:28:26 +08:00
|
|
|
printf("Building target platforms: %s\n", targets);
|
1998-08-16 22:26:04 +08:00
|
|
|
|
1999-03-18 04:01:09 +08:00
|
|
|
for (t = targets; *t != '\0'; t = te) {
|
|
|
|
char *target;
|
|
|
|
if ((te = strchr(t, ',')) == NULL)
|
|
|
|
te = t + strlen(t);
|
|
|
|
target = alloca(te-t+1);
|
1999-03-18 02:11:01 +08:00
|
|
|
strncpy(target, t, (te-t));
|
|
|
|
target[te-t] = '\0';
|
1998-12-02 07:28:26 +08:00
|
|
|
printf("Building for target %s\n", target);
|
1998-08-09 06:27:08 +08:00
|
|
|
|
1998-12-02 07:28:26 +08:00
|
|
|
rpmReadConfigFiles(rcfile, target);
|
|
|
|
rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
|
1998-11-08 08:15:33 +08:00
|
|
|
fromTarball, test, cookie, force);
|
1998-08-09 06:27:08 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-12-02 01:18:38 +08:00
|
|
|
|
|
|
|
#define POPT_USECATALOG 1000
|
|
|
|
#define POPT_NOLANG 1001
|
|
|
|
#define POPT_RMSOURCE 1002
|
|
|
|
#define POPT_RMBUILD 1003
|
|
|
|
#define POPT_BUILDROOT 1004
|
1998-12-02 07:28:26 +08:00
|
|
|
#define POPT_BUILDARCH 1005
|
|
|
|
#define POPT_BUILDOS 1006
|
|
|
|
#define POPT_TARGETPLATFORM 1007
|
|
|
|
#define POPT_NOBUILD 1008
|
|
|
|
#define POPT_SHORTCIRCUIT 1009
|
1998-12-02 01:18:38 +08:00
|
|
|
|
|
|
|
extern int noLang;
|
1998-12-02 07:28:26 +08:00
|
|
|
static int noBuild = 0;
|
1998-12-02 01:18:38 +08:00
|
|
|
static int useCatalog = 0;
|
|
|
|
|
|
|
|
static void buildArgCallback(poptContext con, enum poptCallbackReason reason,
|
|
|
|
const struct poptOption * opt, const char * arg,
|
|
|
|
struct rpmBuildArguments * data)
|
|
|
|
{
|
|
|
|
switch (opt->val) {
|
|
|
|
case POPT_USECATALOG: data->useCatalog = 1; break;
|
1998-12-02 07:28:26 +08:00
|
|
|
case POPT_NOBUILD: data->noBuild = 1; break;
|
1998-12-02 01:18:38 +08:00
|
|
|
case POPT_NOLANG: data->noLang = 1; break;
|
1998-12-02 07:28:26 +08:00
|
|
|
case POPT_SHORTCIRCUIT: data->shortCircuit = 1; break;
|
1998-12-02 01:18:38 +08:00
|
|
|
case POPT_RMSOURCE: data->buildAmount |= RPMBUILD_RMSOURCE; break;
|
|
|
|
case POPT_RMBUILD: data->buildAmount |= RPMBUILD_RMBUILD; break;
|
|
|
|
case POPT_BUILDROOT:
|
|
|
|
if (data->buildRootOverride) {
|
|
|
|
fprintf(stderr, _("buildroot already specified"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
data->buildRootOverride = strdup(arg);
|
|
|
|
break;
|
1998-12-02 07:28:26 +08:00
|
|
|
case POPT_BUILDARCH:
|
|
|
|
fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
case POPT_BUILDOS:
|
|
|
|
fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
case POPT_TARGETPLATFORM:
|
|
|
|
if (data->targets) {
|
|
|
|
int len = strlen(data->targets) + strlen(arg) + 2;
|
|
|
|
data->targets = realloc(data->targets, len);
|
|
|
|
strcat(data->targets, ",");
|
|
|
|
} else {
|
|
|
|
data->targets = malloc(strlen(arg) + 1);
|
|
|
|
data->targets[0] = '\0';
|
|
|
|
}
|
|
|
|
strcat(data->targets, arg);
|
|
|
|
break;
|
1998-12-02 01:18:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct poptOption rpmBuildPoptTable[] = {
|
|
|
|
{ NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
|
|
|
|
buildArgCallback, 0, NULL, NULL },
|
1998-12-02 07:28:26 +08:00
|
|
|
{ "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
|
|
|
|
N_("override build architecture"), "ARCH" },
|
|
|
|
{ "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
|
|
|
|
N_("override build operating system"), "OS" },
|
1998-12-02 01:18:38 +08:00
|
|
|
{ "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
|
|
|
|
N_("override build root"), "DIRECTORY" },
|
|
|
|
{ "clean", '\0', 0, 0, POPT_RMBUILD,
|
|
|
|
N_("remove build tree when done"), NULL},
|
1998-12-02 07:28:26 +08:00
|
|
|
{ "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
|
|
|
|
N_("do not execute any stages of the build"), NULL },
|
1998-12-02 01:18:38 +08:00
|
|
|
{ "nolang", '\0', 0, &noLang, POPT_NOLANG,
|
|
|
|
N_("do not accept I18N msgstr's from specfile"), NULL},
|
|
|
|
{ "rmsource", '\0', 0, 0, POPT_RMSOURCE,
|
|
|
|
N_("remove sources and specfile when done"), NULL},
|
1998-12-02 07:28:26 +08:00
|
|
|
{ "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
|
|
|
|
N_("skip straight to specified stage (only for c,i)"), NULL },
|
|
|
|
{ "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
|
|
|
|
N_("override target platform"), "CPU-VENDOR-OS" },
|
1998-12-02 01:18:38 +08:00
|
|
|
{ "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
|
|
|
|
N_("lookup I18N strings in specfile catalog"), NULL},
|
|
|
|
{ 0, 0, 0, 0, 0, NULL, NULL }
|
|
|
|
};
|