| 399 | == Cleaning up the build == |
| 400 | |
| 401 | The .spec file specification supports a special section intended for performing a cleanup after a successful build by deleting intermediate files and directories created during the build process. This optional section starts with the `%clean` keyword and, if present, goes right after the `%install` section in the .spec file. |
| 402 | |
| 403 | If the `%clean` section is absent, rpmbuild does not perform any cleanup and leaves both the package build directory and the sandboxed build root directory on disk. This is usually a waste of space because these directories will be automatically removed anyway at the beginning of a subsequent rpmbuild run for the same package. For this reason it is advised to always add the `%clean` section to the .spec file which at least removes the sandboxed build root directory (as its contents matches the contents of the created .RPMs and therefore doesn't contain any usueful information). Here is how such a section will look like: |
| 404 | |
| 405 | {{{ |
| 406 | %clean |
| 407 | %{__rm} -rf ${RPM_BUILD_ROOT} |
| 408 | }}} |
| 409 | |
| 410 | Note that while it may seem reasonable to delete the package build directory (containing both the sources and all the output files of the build process) as well, it is normally not a good idea to do it from the `%clean` section as it may be needed to check the build details later to analyze possible misbehaviour of the released RPMs. |
| 411 | |