RPM provides a macro to expand archives, %setup. There are several options, without any options it will expand the archive and place the contents in the BUILD directory. I usually only use the quiet option (-q). Other options are occasionally necessary if the package you are building is nonconformist.
For our example spec file, the following will expand our archive and place the contents in the BUILD directory for us.
%prep %setup -qOur package will not build with this spec file, but we'll try anyway so we can see an error.
[build@client11 SPECS]$ rpmbuild -ba tar.spec error: File /home/build/rpmbuild/SOURCES/tar-1.22.tar.bz2: No such file or directoryWe need to move the source file we downloaded earlier into the SOURCES directory.
[build@client11 SPECS]$ mv ~/tar-1.22.tar.bz2 ../SOURCES [build@client11 SPECS]$ rpmbuild tar.spec [build@client11 SPECS]$[build@client11 SPECS]$ rpmbuild -bb tar.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.21480 + umask 022 + cd /home/build/rpmbuild/BUILD + cd /home/build/rpmbuild/BUILD + rm -rf tar-1.22 + /usr/bin/bzip2 -dc /home/build/rpmbuild/SOURCES/tar-1.22.tar.bz2 + tar -xf - + STATUS=0 + '[' 0 -ne 0 ']' + cd tar-1.22 + exit 0 Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot} [build@client11 SPECS]$ As you can see, rpm ran bzip2 to uncompress the file then piped it through tar to extract the files. RPM then cd'd to the directory tar-1.22, which is the name of our rpm - version. This is important, it is the directory you start in when you are at the build stage. We'll write our %build section now.