31 { NULL,
'a', POPT_ARG_STRING, NULL,
'a', NULL, NULL},
32 { NULL,
'b', POPT_ARG_STRING, NULL,
'b', NULL, NULL},
33 { NULL,
'c', 0, &
createDir, 0, NULL, NULL},
34 { NULL,
'D', 0, &
leaveDirs, 0, NULL, NULL},
35 { NULL,
'n', POPT_ARG_STRING, &
dirName, 0, NULL, NULL},
37 { NULL,
'q', 0, &
quietly, 0, NULL, NULL},
38 { 0, 0, 0, 0, 0, NULL, NULL}
52 if (
Lstat(urlfn, &sb)) {
54 urlfn, strerror(
errno));
80 int reverse,
int removeEmpties,
int fuzz,
const char *subdir)
84 const char *fn, *Lurlfn;
85 static char buf[BUFSIZ];
86 char args[BUFSIZ], *t = args;
90 const char *patch, *
flags;
95 #if defined(RPM_VENDOR_OPENPKG) 98 t =
stpcpy(t,
"-b --suffix .orig ");
104 sprintf(t,
"%10.10d", fuzz);
112 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
125 Lurlfn =
_free(Lurlfn);
130 urltype =
urlPath(Lurlfn, &fn);
141 Lurlfn =
_free(Lurlfn);
147 if (strcmp(patch,
"%{__patch}") == 0)
150 flags =
rpmExpand(
"%{?_default_patch_flags}%{!?_default_patch_flags:-s}", NULL);
155 switch (compressed) {
160 zipper =
"%{__gzip}";
163 zipper =
"%{__bzip2}";
166 zipper =
"%{__lzop}";
169 zipper =
"%{__lzma}";
178 "echo \"Patch #%d (%s):\"\n" 179 "%s -d < '%s' | %s -p%d %s %s\n" 181 "if [ $STATUS -ne 0 ]; then\n" 186 (
const char *) basename((
char *)fn),
189 fn, patch, strip, args, flags);
190 zipper =
_free(zipper);
193 "echo \"Patch #%d (%s):\"\n" 194 "%s -p%d %s %s < '%s'", c,
196 (
const char *) basename((
char *)fn),
198 patch, strip, args, flags, fn);
201 patch =
_free(patch);
202 flags =
_free(flags);
203 Lurlfn =
_free(Lurlfn);
220 const char *fn, *Lurlfn;
221 static char buf[BUFSIZ];
230 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
240 t = strrchr(sp->
source,
'.');
241 if(t && !strcasecmp(t,
".gem"))
244 t =
stpcpy(taropts,
"-x");
254 #if defined(RPM_VENDOR_OPENPKG) 262 Lurlfn =
_free(Lurlfn);
267 urltype =
urlPath(Lurlfn, &fn);
278 Lurlfn =
_free(Lurlfn);
289 fprintf(stderr,
"==> %s: %s\n", fn, t);
296 if (strcmp(tar,
"%{__tar}") == 0)
299 #if defined(RPM_VENDOR_ARK) 309 switch (compressed) {
315 t =
"%{__bzip2} -dc";
330 t =
"%{__lrzip} -dqo-";
337 #if defined(RPM_VENDOR_OPENPKG) 338 t =
"%{__bsdtar} -x -f";
343 t =
"%{__unzip} -qq";
351 zipper =
_free(zipper);
366 "if [ $STATUS -ne 0 ]; then\n" 379 "if [ -f data.tar.gz ]; then\n" 389 Lurlfn =
_free(Lurlfn);
424 if ((rc = poptParseArgvString(line, &argc, &argv))) {
433 optCon = poptGetContext(NULL, argc, argv,
optionsTable, 0);
434 while ((arg = poptGetNextOpt(optCon)) > 0) {
435 optArg = poptGetOptArg(optCon);
441 spec->
lineNum, (optArg ? optArg :
"???"));
442 optCon = poptFreeContext(optCon);
451 (void)
rpmiobAppend((arg ==
'a' ? after : before), chptr, 1);
458 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
460 optCon = poptFreeContext(optCon);
470 (void)
snprintf(buf,
sizeof(buf),
"%s-%s", N, V);
471 buf[
sizeof(buf)-1] =
'\0';
478 optCon = poptFreeContext(optCon);
483 const char *buildDir;
485 (void)
urlPath(buildDirURL, &buildDir);
487 sprintf(buf,
"cd '%s'", buildDir);
489 buildDirURL =
_free(buildDirURL);
500 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
506 char *t = strrchr(sp->
source,
'.');
507 if(t && !strcasecmp(t,
".gem"))
515 mkdir_p =
rpmExpand(
"%{?__mkdir_p}%{!?__mkdir_p:mkdir -p}", NULL);
518 sprintf(buf,
"%s '%s'\ncd '%s'",
520 mkdir_p =
_free(mkdir_p);
550 {
static const char *fixmacs[] =
551 {
"%{_fixowner}",
"%{_fixgroup}",
"%{_fixperms}", NULL };
554 for (fm = fixmacs; *fm; fm++) {
557 if (fix && *fix !=
'%')
587 char buf[BUFSIZ], *bp;
591 memset(patch_nums, 0,
sizeof(patch_nums));
592 opt_P = opt_p = opt_R = opt_E = 0;
593 opt_F =
rpmExpandNumeric(
"%{?_default_patch_fuzz}%{!?_default_patch_fuzz:-1}");
598 if (! strchr(
" \t\n", line[6])) {
600 sprintf(buf,
"%%patch -P %s", line + 6);
606 for (bp = buf; (s = strtok(bp,
" \t\n")) != NULL;) {
611 if (!strcmp(s,
"-P")) {
613 }
else if (!strcmp(s,
"-R")) {
615 }
else if (!strcmp(s,
"-E")) {
617 }
else if (!strcmp(s,
"-b")) {
619 opt_b = strtok(NULL,
" \t\n");
622 _(
"line %d: Need arg to %%patch -b: %s\n"),
626 }
else if (!strcmp(s,
"-z")) {
628 opt_b = strtok(NULL,
" \t\n");
631 _(
"line %d: Need arg to %%patch -z: %s\n"),
635 }
else if (!strcmp(s,
"-F")) {
637 const char * fnum = (!strchr(
" \t\n", s[2])
638 ? s+2 : strtok(NULL,
" \t\n"));
641 opt_F = (fnum ? strtol(fnum, &end, 10) : 0);
642 if (! opt_F || *end) {
644 _(
"line %d: Bad arg to %%patch -F: %s\n"),
648 }
else if (!strcmp(s,
"-d")) {
650 opt_d = strtok(NULL,
" \t\n");
653 _(
"line %d: Need arg to %%patch -d: %s\n"),
657 }
else if (!strncmp(s,
"-p",
sizeof(
"-p")-1)) {
659 if (! strchr(
" \t\n", s[2])) {
662 s = strtok(NULL,
" \t\n");
665 _(
"line %d: Need arg to %%patch -p: %s\n"),
672 _(
"line %d: Bad arg to %%patch -p: %s\n"),
678 if (patch_index == 1024) {
682 if (
parseNum(s, &(patch_nums[patch_index]))) {
695 s =
doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
701 for (x = 0; x < patch_index; x++) {
702 s =
doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
725 if ((buf = (
char *)malloc(buf_len)) == NULL)
728 for (i = (
int)strlen(buf); i <= 11; i++)
731 i = (int)strlen(buf);
733 xx =
snprintf(buf+i, buf_len-i,
" %9lu Bytes\n", (
unsigned long)st->st_size);
735 xx =
snprintf(buf+i, buf_len-i,
" ...MISSING\n");
748 #if defined(RPM_VENDOR_OPENPKG) 751 const char *Lmacro, *Lurlfn = NULL;
752 const char *Rmacro, *Rurlfn = NULL;
761 Lurlfn =
rpmGenPath(NULL,
"%{?_sourcedir}", NULL);
762 if (Lurlfn != NULL && *Lurlfn !=
'\0')
764 Lurlfn =
_free(Lurlfn);
770 Lurlfn =
rpmGenPath(NULL,
"%{?_patchdir}", NULL);
771 if (Lurlfn != NULL && *Lurlfn !=
'\0')
773 Lurlfn =
_free(Lurlfn);
779 Lurlfn =
rpmGenPath(NULL,
"%{?_icondir}", NULL);
780 if (Lurlfn != NULL && *Lurlfn !=
'\0')
782 Lurlfn =
_free(Lurlfn);
790 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
792 #if defined(RPM_VENDOR_OPENPKG) 793 Smacro =
"%{?_specdir}/";
795 #if defined(RPM_VENDOR_OPENPKG) 802 Rmacro =
"%{?_Rsourcedir}/";
805 Rmacro =
"%{?_Rpatchdir}/";
808 Rmacro =
"%{?_Ricondir}/";
812 #if defined(RPM_VENDOR_OPENPKG) 817 rc =
Lstat(Lurlfn, &st);
824 rc =
Lstat(Lurlfn, &st);
834 if (
errno != ENOENT) {
844 if (cp != NULL && strcmp(cp,
"/") != 0) {
847 if (!(Rurlfn == NULL || Rurlfn[0] ==
'\0' || !strcmp(Rurlfn,
"/") || !strcmp(Lurlfn, Rurlfn))) {
880 Lurlfn =
_free(Lurlfn);
881 Rurlfn =
_free(Rurlfn);
897 if (spec->
prep != NULL) {
934 for (lines = saveLines; *lines; lines++) {
936 for (cp = *lines; *cp ==
' ' || *cp ==
'\t'; cp++)
938 if (!strncmp(cp,
"%setup",
sizeof(
"%setup")-1)) {
941 }
else if (! strncmp(cp,
"%patch",
sizeof(
"%patch")-1)) {
947 if (res && !spec->
force) {
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
const char * rpmmgFile(rpmmg mg, const char *fn)
Return magic string for a file.
static int doSetupMacro(Spec spec, const char *line)
Parse setup macro.
int isCompressed(const char *file, rpmCompressedMagic *compressed)
Return type of compression used in file.
enum urltype_e urltype
Supported URL types.
char * xstrdup(const char *str)
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
int rpmioMkpath(const char *path, mode_t mode, uid_t uid, gid_t gid)
Insure that directories in path exist, creating as needed.
#define reverse(bot, top)
struct rpmBuildArguments_s rpmBTArgs
void addMacro(MacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
const char * ftpStrerror(int errorNumber)
static void rpmlog(int code, const char *fmt,...)
static const char * doUntar(Spec spec, rpmuint32_t c, int quietly)
Expand setup macro into prep scriptlet.
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
int parsePrep(Spec spec, int verify)
Parse %prep section of a spec file.
const char * getUname(uid_t uid)
Return cached user name from user id.
const char * getSourceDir(rpmfileAttrs attr)
Return the macro directory location from source file flags.
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
int urlGetFile(const char *url, const char *dest)
Copy data from URL to local file.
static char * doPatch(Spec spec, rpmuint32_t c, int strip, const char *db, int reverse, int removeEmpties, int fuzz, const char *subdir)
Expand patchN macro into prep scriptlet.
int Lstat(const char *path, struct stat *st)
lstat(2) clone.
static int skipDefaultAction
const char * getGname(gid_t gid)
Return cached group name from group id.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
const char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
rpmmg rpmmgNew(const char *fn, int flags)
Create and load a magic wrapper.
The structure used to store values parsed from a spec file.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
static struct poptOption optionsTable[]
rpmRC rpmMkdirPath(const char *dpath, const char *dname)
Create directory if it does not exist, and make sure path is writable.
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
enum rpmRC_e rpmRC
RPM return codes.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
static const char * dirName
int parseNum(const char *line, rpmuint32_t *res)
Parse a number.
static void prepFetchVerbose(struct Source *sp, struct stat *st)
enum rpmCompressedMagic_e rpmCompressedMagic
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
static int snprintf(char *buf, int nb, const char *fmt,...)
This is the only module users of librpmbuild should need to include.
char * stpcpy(char *dest, const char *src)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int headerNEVRA(Header h, const char **np, const char **ep, const char **vp, const char **rp, const char **ap)
Return name, epoch, version, release, arch strings from header.
static int prepFetch(Spec spec)
Check that all sources/patches/icons exist locally, fetching if necessary.
static rpmRC checkOwners(const char *urlfn)
Check that file owner and group are known.
static rpmRC doPatchMacro(Spec spec, const char *line)
Parse patch line.
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
enum rpmParseState_e rpmParseState
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmmg rpmmgFree(rpmmg mg)
Destroy a magic wrapper.