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];
90 const char *patch, *
flags;
95 #if defined(RPM_VENDOR_OPENPKG)
98 t =
stpcpy(t,
"-b --suffix .orig ");
125 Lurlfn =
_free(Lurlfn);
130 urltype =
urlPath(Lurlfn, &fn);
141 Lurlfn =
_free(Lurlfn);
147 if (!(patch && *patch !=
'\0')) {
148 patch =
_free(patch);
152 flags =
rpmExpand(
"%{?_default_patch_flags}%{!?_default_patch_flags:-s}",
NULL);
157 switch (compressed) {
162 zipper =
"%{__gzip}";
165 zipper =
"%{__bzip2}";
168 zipper =
"%{__lzop}";
171 zipper =
"%{__lzma}";
180 "echo \"Patch #%d (%s):\"\n"
181 "%s -d < '%s' | %s -p%d %s %s\n"
183 "if [ $STATUS -ne 0 ]; then\n"
188 (
const char *) basename((
char *)fn),
191 fn, patch, strip, args, flags);
192 zipper =
_free(zipper);
195 "echo \"Patch #%d (%s):\"\n"
196 "%s -p%d %s %s < '%s'", c,
198 (
const char *) basename((
char *)fn),
200 patch, strip, args, flags, fn);
203 patch =
_free(patch);
204 flags =
_free(flags);
205 Lurlfn =
_free(Lurlfn);
222 const char *
fn, *Lurlfn;
223 static char buf[BUFSIZ];
242 t = strrchr(sp->
source,
'.');
243 if(t && !strcasecmp(t,
".gem"))
246 t =
stpcpy(taropts,
"-x");
256 #if defined(RPM_VENDOR_OPENPKG)
264 Lurlfn =
_free(Lurlfn);
269 urltype =
urlPath(Lurlfn, &fn);
280 Lurlfn =
_free(Lurlfn);
291 fprintf(stderr,
"==> %s: %s\n", fn, t);
298 if (!(tar && *tar !=
'\0')) {
303 #if defined(RPM_VENDOR_ARK)
313 switch (compressed) {
319 t =
"%{__bzip2} -dc";
334 t =
"%{__lrzip} -dqo-";
341 #if defined(RPM_VENDOR_OPENPKG)
342 t =
"%{__bsdtar} -x -f";
347 t =
"%{__unzip} -qq";
355 zipper =
_free(zipper);
370 "if [ $STATUS -ne 0 ]; then\n"
383 "if [ -f data.tar.gz ]; then\n"
393 Lurlfn =
_free(Lurlfn);
428 if ((rc = poptParseArgvString(line, &argc, &argv))) {
438 while ((arg = poptGetNextOpt(optCon)) > 0) {
439 optArg = poptGetOptArg(optCon);
445 spec->
lineNum, (optArg ? optArg :
"???"));
446 optCon = poptFreeContext(optCon);
462 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
464 optCon = poptFreeContext(optCon);
475 buf[
sizeof(
buf)-1] =
'\0';
482 optCon = poptFreeContext(optCon);
487 const char *buildDir;
491 sprintf(buf,
"cd '%s'", buildDir);
493 buildDirURL =
_free(buildDirURL);
510 char *
t = strrchr(sp->
source,
'.');
511 if(t && !strcasecmp(t,
".gem"))
519 mkdir_p =
rpmExpand(
"%{?__mkdir_p}%{!?__mkdir_p:mkdir -p}",
NULL);
522 sprintf(buf,
"%s '%s'\ncd '%s'",
524 mkdir_p =
_free(mkdir_p);
554 {
static const char *fixmacs[] =
555 {
"%{_fixowner}",
"%{_fixgroup}",
"%{_fixperms}",
NULL };
558 for (fm = fixmacs; *fm; fm++) {
561 if (fix && *fix !=
'%')
591 char buf[BUFSIZ], *bp;
595 memset(patch_nums, 0,
sizeof(patch_nums));
596 opt_P = opt_p = opt_R = opt_E = 0;
597 opt_F =
rpmExpandNumeric(
"%{?_default_patch_fuzz}%{!?_default_patch_fuzz:-1}");
602 if (! strchr(
" \t\n", line[6])) {
604 sprintf(buf,
"%%patch -P %s", line + 6);
606 strncpy(buf, line,
sizeof(buf)-1);
607 buf[
sizeof(
buf)-1] =
'\0';
611 for (bp = buf; (s = strtok(bp,
" \t\n")) !=
NULL;) {
618 }
else if (!
strcmp(s,
"-R")) {
620 }
else if (!
strcmp(s,
"-E")) {
622 }
else if (!
strcmp(s,
"-b")) {
624 opt_b = strtok(
NULL,
" \t\n");
627 _(
"line %d: Need arg to %%patch -b: %s\n"),
631 }
else if (!
strcmp(s,
"-z")) {
633 opt_b = strtok(
NULL,
" \t\n");
636 _(
"line %d: Need arg to %%patch -z: %s\n"),
640 }
else if (!
strcmp(s,
"-F")) {
642 const char * fnum = (!strchr(
" \t\n", s[2])
643 ? s+2 : strtok(
NULL,
" \t\n"));
646 opt_F = (fnum ? strtol(fnum, &end, 10) : 0);
647 if (! opt_F || *end) {
649 _(
"line %d: Bad arg to %%patch -F: %s\n"),
653 }
else if (!
strcmp(s,
"-d")) {
655 opt_d = strtok(
NULL,
" \t\n");
658 _(
"line %d: Need arg to %%patch -d: %s\n"),
662 }
else if (!strncmp(s,
"-p",
sizeof(
"-p")-1)) {
664 if (! strchr(
" \t\n", s[2])) {
667 s = strtok(
NULL,
" \t\n");
670 _(
"line %d: Need arg to %%patch -p: %s\n"),
677 _(
"line %d: Bad arg to %%patch -p: %s\n"),
683 if (patch_index == 1024) {
687 if (
parseNum(s, &(patch_nums[patch_index]))) {
700 s =
doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
706 for (x = 0; x < patch_index; x++) {
707 s =
doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
730 if ((buf = (
char *)malloc(buf_len)) ==
NULL)
733 for (i = (
int)strlen(buf); i <= 11; i++)
736 i = (
int)strlen(buf);
738 xx =
snprintf(buf+i, buf_len-i,
" %9lu Bytes\n", (
unsigned long)st->st_size);
740 xx =
snprintf(buf+i, buf_len-i,
" ...MISSING\n");
753 #if defined(RPM_VENDOR_OPENPKG)
756 const char *Lmacro, *Lurlfn =
NULL;
757 const char *Rmacro, *Rurlfn =
NULL;
767 if (Lurlfn !=
NULL && *Lurlfn !=
'\0')
769 Lurlfn =
_free(Lurlfn);
776 if (Lurlfn !=
NULL && *Lurlfn !=
'\0')
778 Lurlfn =
_free(Lurlfn);
785 if (Lurlfn !=
NULL && *Lurlfn !=
'\0')
787 Lurlfn =
_free(Lurlfn);
797 #if defined(RPM_VENDOR_OPENPKG)
798 Smacro =
"%{?_specdir}/";
800 #if defined(RPM_VENDOR_OPENPKG)
807 Rmacro =
"%{?_Rsourcedir}/";
810 Rmacro =
"%{?_Rpatchdir}/";
813 Rmacro =
"%{?_Ricondir}/";
817 #if defined(RPM_VENDOR_OPENPKG)
822 rc =
Lstat(Lurlfn, &st);
829 rc =
Lstat(Lurlfn, &st);
839 if (
errno != ENOENT) {
852 if (!(Rurlfn ==
NULL || Rurlfn[0] ==
'\0' || !
strcmp(Rurlfn,
"/") || !
strcmp(Lurlfn, Rurlfn))) {
885 Lurlfn =
_free(Lurlfn);
886 Rurlfn =
_free(Rurlfn);
939 for (lines = saveLines; *lines; lines++) {
941 for (cp = *lines; *cp ==
' ' || *cp ==
'\t'; cp++)
943 if (!strncmp(cp,
"%setup",
sizeof(
"%setup")-1)) {
946 }
else if (! strncmp(cp,
"%patch",
sizeof(
"%patch")-1)) {
952 if (res && !spec->
force) {
const char * getSourceDir(rpmfileAttrs attr)
Return the macro directory location from source file flags.
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.
rpmlog(RPMLOG_ERR,"%s\n", buf)
int isCompressed(const char *file, rpmCompressedMagic *compressed)
Return type of compression used in file.
int parseNum(const char *line, rpmuint32_t *res)
Parse a number.
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.
const char * getUname(uid_t uid)
Return cached user name from user id.
struct rpmBuildArguments_s rpmBTArgs
#define reverse(bot, top)
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 const char * doUntar(Spec spec, rpmuint32_t c, int quietly)
Expand setup macro into prep scriptlet.
int parsePrep(Spec spec, int verify)
Parse %prep section of a spec file.
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
sprintf(t," (%u)",(unsigned) dig->nbytes)
enum rpmRC_e rpmRC
RPM return codes.
memset(_r, 0, sizeof(*_r))
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.
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
int Lstat(const char *path, struct stat *st)
lstat(2) clone.
static int skipDefaultAction
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.
static const char *char c
Return text between pl and matching pr characters.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
static const char * dirName
static void prepFetchVerbose(struct Source *sp, struct stat *st)
return strcmp(ame->name, bme->name)
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 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
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
char * buf
Parse (and execute) macro undefinition.
int
Save source and expand field into target.
const char * getGname(gid_t gid)
Return cached group name from group id.
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmmg rpmmgFree(rpmmg mg)
Destroy a magic wrapper.