8 #include <rpm/rpmcli.h>
9 #include <rpm/rpmlib.h>
10 #include <rpm/rpmbuild.h>
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmfileutil.h>
13 #include <rpm/rpmdb.h>
14 #include <rpm/rpmps.h>
15 #include <rpm/rpmts.h>
16 #include "lib/signature.h"
23 #define POPT_NOLANG -1012
24 #define POPT_RMSOURCE -1013
25 #define POPT_RMBUILD -1014
26 #define POPT_BUILDROOT -1015
27 #define POPT_TARGETPLATFORM -1016
28 #define POPT_NOBUILD -1017
29 #define POPT_RMSPEC -1019
30 #define POPT_NODIRTOKENS -1020
31 #define POPT_BUILDINPLACE -1021
33 #define POPT_REBUILD 0x4262
34 #define POPT_RECOMPILE 0x4369
35 #define POPT_BA 0x6261
36 #define POPT_BB 0x6262
37 #define POPT_BC 0x6263
38 #define POPT_BI 0x6269
39 #define POPT_BL 0x626c
40 #define POPT_BP 0x6270
41 #define POPT_BS 0x6273
42 #define POPT_RA 0x4261
43 #define POPT_RB 0x4262
44 #define POPT_RC 0x4263
45 #define POPT_RI 0x4269
46 #define POPT_RL 0x426c
47 #define POPT_RP 0x4270
48 #define POPT_RS 0x4273
49 #define POPT_TA 0x7461
50 #define POPT_TB 0x7462
51 #define POPT_TC 0x7463
52 #define POPT_TI 0x7469
53 #define POPT_TL 0x746c
54 #define POPT_TP 0x7470
55 #define POPT_TS 0x7473
69 enum poptCallbackReason reason,
70 const struct poptOption * opt,
const char * arg,
102 buildMode = (((unsigned)opt->val) >> 8) & 0xff;
136 { NULL,
'\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
139 {
"bp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BP,
140 N_(
"build through %prep (unpack sources and apply patches) from <specfile>"),
142 {
"bc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BC,
143 N_(
"build through %build (%prep, then compile) from <specfile>"),
145 {
"bi", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BI,
146 N_(
"build through %install (%prep, %build, then install) from <specfile>"),
148 {
"bl", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BL,
149 N_(
"verify %files section from <specfile>"),
151 {
"ba", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BA,
152 N_(
"build source and binary packages from <specfile>"),
154 {
"bb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BB,
155 N_(
"build binary package only from <specfile>"),
157 {
"bs", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BS,
158 N_(
"build source package only from <specfile>"),
161 {
"rp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RP,
162 N_(
"build through %prep (unpack sources and apply patches) from <source package>"),
163 N_(
"<source package>") },
164 {
"rc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RC,
165 N_(
"build through %build (%prep, then compile) from <source package>"),
166 N_(
"<source package>") },
167 {
"ri", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RI,
168 N_(
"build through %install (%prep, %build, then install) from <source package>"),
169 N_(
"<source package>") },
170 {
"rl", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RL,
171 N_(
"verify %files section from <source package>"),
172 N_(
"<source package>") },
173 {
"ra", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RA,
174 N_(
"build source and binary packages from <source package>"),
175 N_(
"<source package>") },
176 {
"rb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RB,
177 N_(
"build binary package only from <source package>"),
178 N_(
"<source package>") },
179 {
"rs", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RS,
180 N_(
"build source package only from <source package>"),
181 N_(
"<source package>") },
183 {
"tp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TP,
184 N_(
"build through %prep (unpack sources and apply patches) from <tarball>"),
186 {
"tc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TC,
187 N_(
"build through %build (%prep, then compile) from <tarball>"),
189 {
"ti", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TI,
190 N_(
"build through %install (%prep, %build, then install) from <tarball>"),
192 {
"tl", 0, POPT_ARGFLAG_ONEDASH|POPT_ARGFLAG_DOC_HIDDEN, 0,
POPT_TL,
193 N_(
"verify %files section from <tarball>"),
195 {
"ta", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TA,
196 N_(
"build source and binary packages from <tarball>"),
198 {
"tb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TB,
199 N_(
"build binary package only from <tarball>"),
201 {
"ts", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TS,
202 N_(
"build source package only from <tarball>"),
206 N_(
"build binary package from <source package>"),
207 N_(
"<source package>") },
209 N_(
"build through %install (%prep, %build, then install) from <source package>"),
210 N_(
"<source package>") },
213 N_(
"override build root"),
"DIRECTORY" },
215 N_(
"run build in current directory"), NULL },
217 N_(
"remove build tree when done"), NULL},
219 N_(
"ignore ExcludeArch: directives from spec file"), NULL},
220 {
"fsmdebug",
'\0', (POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN), &
_fsm_debug, -1,
221 N_(
"debug file state machine"), NULL},
223 N_(
"do not execute any stages of the build"), NULL },
224 {
"nodeps",
'\0', POPT_ARG_VAL, &
noDeps, 1,
225 N_(
"do not verify build dependencies"), NULL },
227 N_(
"generate package header(s) compatible with (legacy) rpm v3 packaging"),
231 N_(
"do not execute %clean stage of the build"), NULL },
233 N_(
"do not execute %prep stage of the build"), NULL },
235 N_(
"do not execute %check stage of the build"), NULL },
237 {
"nolang",
'\0', POPT_ARGFLAG_DOC_HIDDEN, 0,
POPT_NOLANG,
238 N_(
"do not accept i18N msgstr's from specfile"), NULL},
240 N_(
"remove sources when done"), NULL},
242 N_(
"remove specfile when done"), NULL},
243 {
"short-circuit",
'\0', POPT_ARG_VAL, &
shortCircuit, 1,
244 N_(
"skip straight to specified stage (only for c,i)"), NULL },
246 N_(
"override target platform"),
"CPU-VENDOR-OS" },
263 N_(
"Build options with [ <specfile> | <tarball> | <source package> ]:"),
266 {
"quiet",
'\0', POPT_ARGFLAG_DOC_HIDDEN, &
quiet, 0, NULL, NULL},
269 N_(
"Common options for all rpm modes and executables:"),
299 f = fopen(specfile,
"r");
302 specfile, strerror(errno));
305 count = fread(buf,
sizeof(buf[0]),
sizeof(buf), f);
312 for (s = buf; count--; s++) {
323 if (checking && !(isprint(*s) || isspace(*s)))
return 0;
326 if (checking && !(isprint(*s) || isspace(*s)) && *(
unsigned char *)s < 32)
return 0;
340 char *specFile = NULL;
346 int gotspec = 0, res;
347 static const char *tryspec[] = {
"Specfile",
"\\*.spec", NULL };
350 tmpSpecFile =
rpmGetPath(
"%{_specdir}/",
"rpm-spec.XXXXXX", NULL);
352 (void) close(mkstemp(tmpSpecFile));
354 for (spec = tryspec; *spec != NULL; spec++) {
359 cmd =
rpmExpand(
"%{uncompress: ", arg,
"} | ",
360 "%{__tar} xOvof - --wildcards ", *spec,
361 " 2>&1 > ", tmpSpecFile, NULL);
363 if (!(fp = popen(cmd,
"r"))) {
368 fok = fgets(tarbuf,
sizeof(tarbuf) - 1, fp);
371 if (strstr(fok,
"tar: ")) {
377 gotspec = (specfiles == 1) &&
isSpecFile(tmpSpecFile);
394 specBase = basename(tarbuf);
396 specBase[strlen(specBase)-1] =
'\0';
398 rasprintf(&specFile,
"%s/%s", specDir, specBase);
399 res = rename(tmpSpecFile, specFile);
403 tmpSpecFile, specFile);
409 umask(mask = umask(0));
410 (void) chmod(specFile, 0666 & ~mask);
414 (void) unlink(tmpSpecFile);
423 char * buildRootURL = NULL;
424 char * specFile = NULL;
433 addMacro(NULL,
"_builddir", NULL, cwd, 0);
441 const char * buildtree =
"%{_topdir}:%{_specdir}:%{_sourcedir}:%{_builddir}:%{_rpmdir}:%{_srcrpmdir}:%{_buildrootdir}";
448 char *srcdir = NULL, *dir;
462 srcdir = dirname(dir);
470 if (*specFile !=
'/' && specFile[1] !=
':') {
472 if (*specFile !=
'/') {
483 if (stat(specFile, &st) < 0) {
487 if (! S_ISREG(st.st_mode)) {
495 _(
"File %s does not appear to be a specfile.\n"), specFile);
501 rc = unlink(specFile);
506 #define _anyarch(_f) \
507 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
527 (void) unlink(specFile);
541 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
561 printf(
_(
"Building target platforms: %s\n"), targets);
566 if (*(
target + 1) == NULL)
569 printf(
_(
"Building for target %s\n"), *
target);
595 int main(
int argc,
char *argv[])
601 const char *pkg = NULL;
606 if (ba->
buildAmount && poptPeekArg(optCon) == NULL) {
619 argerror(
_(
"arguments to --root (-r) must begin with a /"));
674 while ((pkg = poptGetArg(optCon))) {
675 char * specFile = NULL;
684 specFile =
_free(specFile);
693 while ((pkg = poptGetArg(optCon))) {