Apply patch from source tarball

Hopefully it is a simple question.
When building from an .spec file, how to apply a patch contained within the source tarball?
Have to have the patch beforehand on SOURCES, or extract it from tarball through a prep-sources script or how shall I do it while keeping it reproducible (for instance for Travis processing).

Usually, patches are kept outside the source tarball.

...
Source0: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tgz
Patch0: shebang-and-thanks.patch
...
%prep
%setup -q -n %{srcname}
%patch0 -p1

See: https://github.com/NethServer/lightsquid/blob/master/lightsquid.spec

1 Like

Thanks for answering. I’ve it as in your example (with a local patch and also tested with a patch from an URL). As upstream keeps the patch in a separte directory within the source tarball just thought if there was a way to use it (to avoid having to track eventual changes on the patch file), but will keep it simple as per the example.

You could call patch with the provided patch file within the tarball. The %setup macro has additional options to expand the tarball contents to a given directory. Not easy to find the right configuration at the first attempt, but fun anyway :slight_smile:

2 Likes