If you’ve run into a situation where you wanted to repeatedly test some code in your .spec file after the %build process, you know you have to wait for the application to re-compile every time. For larger RPMs this waiting compounds to a lot of lost time.
During my build for CodeLite I ran into several issues, mostly when cleaning up the rpmlint messages from the resulting package. The average build time was around 16 minutes with the optimal make -j value. It doesn’t sound like much but if you have to compile 5 or 6 or 7 times, it adds up.
The .spec macros will do cleaning of the working directories every time you execute rpmbuild -ba and for good reason. Ideally you should re-compile every time to ensure a repeatable build environment, however if you are impatient like me try the following:
I assume you…
- have already tested and confirmed your package compiles successfully with rpmbuild -ba
- are confident the build process can be skipped safely without compromising the rest of the .spec file
- understand that this is for testing purposes only and the .patch created below will not be included in the final .rpm
- understand this particular .patch file should only be used on the system it is created
First of all, expand the source tarball to two separate directories: pkg and pkg.compiled.
Navigate to the pkg.compiled directory and go through the configure and make process mirroring the %build process from your working .spec file. You do not need to ‘make install’ and this point.
Change the directory to the pkg.compiled parent and run the following:
$ diff -Naur pkg pkg.compiled > ~/rpmbuild/SOURCES/app-version-skip_make.patch
You will be using this patch file to “trick” the %build process into skipping most of the compiling process. I say most because make may detect inconsistencies in the source directory after the patch and go through some re-linking.
The next step is to add this patch to your .spec file:
... Patch99: app-version-skip_make.patch %prep %setup -q %patch99 -p1 ... %build #%configure make ...
Notice I’ve commented out %configure because the patch file will take care of this also.
You can now go through the rpmbuild -ba process again and you should see a very significant speed increase.
Using this, I was able to decrease the build time for CodeLite by 400%!
Good luck, and remember to remove this patch from your final RPM.
