{"id":14228,"date":"2023-09-12T13:47:51","date_gmt":"2023-09-12T13:47:51","guid":{"rendered":"https:\/\/blog.bachi.net\/?p=14228"},"modified":"2023-09-29T07:14:40","modified_gmt":"2023-09-29T07:14:40","slug":"redhat-rpmbuild","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=14228","title":{"rendered":"RedHat rpmbuild"},"content":{"rendered":"<p><a href=\"https:\/\/developers.redhat.com\/blog\/2019\/03\/18\/rpm-packaging-guide-creating-rpm\">RPM packaging: A simplified guide to creating your first RPM<\/a><br \/>\n<a href=\"https:\/\/www.redhat.com\/sysadmin\/create-rpm-package\">How to create a Linux RPM package<\/a><br \/>\n<a href=\"https:\/\/rpm-packaging-guide.github.io\/\">RPM Packaging Guide<\/a><br \/>\n<a href=\"https:\/\/opensource.com\/article\/18\/9\/how-build-rpm-packages\">How to build rpm packages<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/8084796\/what-actually-is-rpm-build-root\">What actually is $RPM_BUILD_ROOT?<\/a><\/p>\n<pre class=\"brush: plain; title: \/home\/andreas\/src\/myapp; notranslate\" title=\"\/home\/andreas\/src\/myapp\">\r\n\u251c\u2500\u2500 src\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 source\r\n\u251c\u2500\u2500 build\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 executables, libraries, etc.\r\n\u2514\u2500\u2500 pkg\r\n    \u251c\u2500\u2500 Makefile\r\n    \u251c\u2500\u2500 myapp.spec\r\n    \u2514\u2500\u2500 package\r\n     \u00a0\u00a0 \u2514\u2500\u2500 &lt;empty&gt;\r\n<\/pre>\n<pre class=\"brush: plain; title: Makefile; notranslate\" title=\"Makefile\">\r\nBUILD_DIR      = $(realpath .)\/..\/build\r\nPKG_BUILD_ROOT = $(realpath .)\/package\r\nPKG_DIR        = \/opt\/myapp\/mysubcomponent\r\nPKG_NAME       = myapp\r\nPKG_VERSION    = 1.0.0.5\r\nPKG_RELEASE    = 1\r\n\r\nall :\r\n    rpmbuild -v -bb                        \\\r\n        -D &quot;BUILD_DIR   $(BUILD_DIR)&quot;      \\\r\n        -D &quot;_topdir     $(PKG_BUILD_ROOT)&quot; \\\r\n        -D &quot;PKG_DIR     $(PKG_DIR)&quot;        \\\r\n        -D &quot;PKG_NAME    $(PKG_NAME)&quot;       \\\r\n        -D &quot;PKG_VERSION $(PKG_VERSION)&quot;    \\\r\n        -D &quot;PKG_RELEASE $(PKG_RELEASE)&quot;    \\\r\n        myapp.spec\r\n\r\nclean :\r\n    rm -rf &quot;$(PKG_BUILD_ROOT)&quot;\r\n<\/pre>\n<pre class=\"brush: plain; title: myapp.spec; notranslate\" title=\"myapp.spec\">\r\n# Tags ----------------------------------------------------\r\n\r\nName:           %{PKG_NAME}\r\nVersion:        %{PKG_VERSION}\r\nRelease:        %{PKG_RELEASE}\r\nSummary:        MyApp Summary\r\nLicense:        GPL\r\nAutoReqProv:    No\r\n\r\n%description\r\nMyApp Description\r\n\r\n# Phases --------------------------------------------------\r\n\r\n# Unpacking the sources     %prep     outside of packaging\r\n# Building the software     %build    outside of packaging\r\n\r\n# Installing the software in PKG_BUILD_ROOT\r\n%install\r\nPKG_PROTO=${RPM_BUILD_ROOT}%{PKG_DIR}\r\ninstall -v -d ${PKG_PROTO}\r\nrsync -av %{BUILD_DIR}\/ ${PKG_PROTO}\/\r\n\r\n# Package the files (= include these files into the RPM package)\r\n%files\r\n%defattr(-,root,root,-)\r\n%{PKG_DIR}\r\n\r\n# Cleaning up               %clean    outside of packaging\r\n\r\n# Embedded Scripts  ---------------------------------------\r\n\r\n%pre\r\necho &quot;## INFO: %{PKG_NAME} : pre&quot;\r\n\r\n%post\r\necho &quot;## INFO: %{PKG_NAME} : post&quot;\r\n\r\n%preun\r\necho &quot;## INFO: %{PKG_NAME} : preun&quot;\r\n\r\n%postun\r\necho &quot;## INFO: %{PKG_NAME} : postun&quot;\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ tree package\r\npackage\r\n\u251c\u2500\u2500 BUILD\r\n\u251c\u2500\u2500 BUILDROOT\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 myapp-1.0.0.5-1.x86_64\r\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 opt\r\n\u2502\u00a0\u00a0         \u2514\u2500\u2500 myapp\r\n\u2502\u00a0\u00a0             \u2514\u2500\u2500 mysubcomponent\r\n\u2502\u00a0\u00a0                 \u251c\u2500\u2500 bin\r\n\u2502\u00a0\u00a0                 \u2502\u00a0\u00a0 \u2514\u2500\u2500 myexecutable\r\n\u2502\u00a0\u00a0                 \u251c\u2500\u2500 etc\r\n\u2502\u00a0\u00a0                 \u2502\u00a0\u00a0 \u2514\u2500\u2500 myconfig\r\n\u2502\u00a0\u00a0                 \u2514\u2500\u2500 lib\r\n\u2502\u00a0\u00a0                  \u00a0\u00a0 \u2514\u2500\u2500 mylibrary.so\r\n\u251c\u2500\u2500 RPMS\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 x86_64\r\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 myapp-1.0.0.5-1.x86_64.rpm\r\n\u251c\u2500\u2500 SOURCES\r\n\u251c\u2500\u2500 SPECS\r\n\u2514\u2500\u2500 SRPMS\r\n<\/pre>\n<pre class=\"brush: plain; title: make package; notranslate\" title=\"make package\">\r\n$ make\r\nrpmbuild -v -bb                                                  \\\r\n            -D &quot;BUILD_DIR   \/home\/andreas\/src\/myapp\/build&quot;       \\\r\n            -D &quot;_topdir     \/home\/andreas\/src\/myapp\/pkg\/package&quot; \\\r\n            -D &quot;PKG_DIR     \/opt\/myapp\/mysubcomponent&quot;           \\\r\n            -D &quot;PKG_NAME    myapp&quot;                               \\\r\n            -D &quot;PKG_VERSION 1.0.0.5&quot;                             \\\r\n            -D &quot;PKG_RELEASE 1&quot;                                   \\\r\n            myapp.spec\r\nExecuting(%install): \/bin\/sh -e \/var\/tmp\/rpm-tmp.AW6YVB\r\n+ umask 022\r\n+ cd \/home\/andreas\/src\/myapp\/pkg\/package\/BUILD\r\n+ '&#x5B;' \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64 '!=' \/ ']'\r\n+ rm -rf \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\r\n++ dirname \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\r\n+ mkdir -p \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\r\n+ mkdir \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\r\n\r\n+ PKG_PROTO=\/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt\/myapp\/mysubcomponent\r\n+ install -v -d \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt\/myapp\/mysubcomponent\r\ninstall: creating directory '\/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt'\r\ninstall: creating directory '\/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt\/myapp'\r\ninstall: creating directory '\/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt\/myapp\/mysubcomponent'\r\n+ rsync -av \/home\/andreas\/src\/myapp\/build\/ \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\/opt\/myapp\/mysubcomponent\/\r\nsending incremental file list\r\n.\/\r\nbin\/\r\nbin\/myexecutable\r\netc\/\r\netc\/myconfig\r\nlib\/\r\nlib\/mylibrary.so\r\nsent 14,794 bytes  received 187 bytes  29,962.00 bytes\/sec\r\ntotal size is 14,064  speedup is 0.94\r\n\r\n+ \/usr\/lib\/rpm\/check-buildroot\r\n+ \/usr\/lib\/rpm\/redhat\/brp-compress\r\n+ \/usr\/lib\/rpm\/redhat\/brp-strip \/usr\/bin\/strip\r\n+ \/usr\/lib\/rpm\/redhat\/brp-strip-comment-note \/usr\/bin\/strip \/usr\/bin\/objdump\r\n+ \/usr\/lib\/rpm\/redhat\/brp-strip-static-archive \/usr\/bin\/strip\r\n+ \/usr\/lib\/rpm\/brp-python-bytecompile \/usr\/bin\/python 1\r\n+ \/usr\/lib\/rpm\/redhat\/brp-python-hardlink\r\n+ \/usr\/lib\/rpm\/redhat\/brp-java-repack-jars\r\nProcessing files: myapp-1.0.0.5-1.x86_64\r\nProvides: myapp= 1.0.0.5-1. myapp(x86-64) = 1.0.0.5-1\r\nRequires(interp): \/bin\/sh \/bin\/sh \/bin\/sh\r\nRequires(rpmlib): rpmlib(FileDigests) &lt;= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) &lt;= 4.0-1 rpmlib(CompressedFileNames) &lt;= 3.0.4-1\r\nRequires(pre): \/bin\/sh\r\nRequires(post): \/bin\/sh\r\nRequires(preun): \/bin\/sh\r\nChecking for unpackaged file(s): \/usr\/lib\/rpm\/check-files \/home\/andreas\/src\/myapp\/pkg\/package\/BUILDROOT\/myapp-1.0.0.5-1.x86_64\r\nWrote: \/home\/andreas\/src\/myapp\/pkg\/package\/RPMS\/x86_64\/myapp-1.0.0.5-1.x86_64.rpm\r\n<\/pre>\n<pre class=\"brush: plain; title: install package; notranslate\" title=\"install package\">\r\n$ yum install \/home\/andreas\/src\/myapp\/pkg\/package\/RPMS\/x86_64\/myapp-1.0.0.5-1.x86_64.rpm\r\n&#x5B;...]\r\nInstall  1 Package\r\n\r\nTotal size: 11 M\r\nInstalled size: 11 M\r\nIs this ok &#x5B;y\/d\/N]: y\r\nDownloading packages:\r\nRunning transaction check\r\nRunning transaction test\r\nTransaction test succeeded\r\nRunning transaction\r\n## INFO: myapp : pre\r\n  Installing : myapp-1.0.0.5-1.x86_64\r\n## INFO: myapp : post\r\n  Verifying  : myapp-1.0.0.5-1.x86_64\r\n\r\nInstalled:\r\n  myapp.x86_64 0:1.0.0.5-1\r\n\r\nComplete!\r\n<\/pre>\n<pre class=\"brush: plain; title: erase package; notranslate\" title=\"erase package\">\r\n$ yum erase myapp\r\n&#x5B;...]\r\nRemove  1 Package\r\n\r\nInstalled size: 9.6 M\r\nIs this ok &#x5B;y\/N]: y\r\nDownloading packages:\r\nRunning transaction check\r\nRunning transaction test\r\nTransaction test succeeded\r\nRunning transaction\r\n## INFO: myapp : preun\r\n  Erasing    : myapp-1.0.0.5-1.x86_64\r\n## INFO: myapp : postun\r\n  Verifying  : myapp-1.0.0.5-1.x86_64\r\n\r\nRemoved:\r\n  myapp-1.0.0.5-1.x86_64\r\n\r\nComplete!\r\n<\/pre>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>max-rpm<\/h3>\n<p><a href=\"http:\/\/ftp.rpm.org\/max-rpm\/s1-rpm-inside-files-list-directives.html\">Directives For the %files list<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nThe %dir Directive\r\n\r\nAs we mentioned in the Section called The %files List, if a\r\ndirectory is specified in the %files list, the contents of\r\nthat directory, and the contents of every directory under it,\r\nwill automatically be included in the package.\r\n\r\nWhile this feature can be handy (assuming you are sure that\r\nevery file under the directory should be packaged) there are\r\ntimes when this could be a problem.\r\n\r\nThe way to get around this, is to use the %dir directive. \r\n<\/pre>\n<p><a href=\"http:\/\/ftp.rpm.org\/max-rpm\/s1-rpm-depend-auto-depend.html\">Automatic Dependencies<\/a><\/p>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>Fedora<\/h3>\n<p><a href=\"https:\/\/docs.fedoraproject.org\/en-US\/package-maintainers\/Packaging_Tutorial_GNU_Hello\/\">Packaging Tutorial: GNU Hello<\/a><br \/>\n<a href=\"https:\/\/docs.fedoraproject.org\/en-US\/packaging-guidelines\/AutoProvidesAndRequiresFiltering\/\">Automatic Filtering of Provides and Requires<\/a><\/p>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>spec File<\/h3>\n<p><a href=\"https:\/\/rpm-software-management.github.io\/rpm\/manual\/spec.html\">Spec file format<\/a><\/p>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>rsync<\/h3>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/8084796\/what-actually-is-rpm-build-root\">What actually is $RPM_BUILD_ROOT?<\/a><\/p>\n<blockquote><p><code>$RPM_BUILD_ROOT<\/code> (or the equivalent <code>%{buildroot}<\/code> SPEC file macro) always<br \/>\nholds the directory under which RPM will look for any files to package.<\/p><\/blockquote>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>Disable Automatic Dependency Processing<\/h3>\n<p><a href=\"https:\/\/superuser.com\/questions\/109107\/how-do-i-prevent-rpmbuild-form-injecting-requirements-into-rpm-package\">How do I prevent rpmbuild form injecting requirements into RPM package?<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/16598201\/disable-rpmbuild-automatic-requirement-finding\">Disable rpmbuild automatic requirement finding<\/a> (<code>AutoReqProv: no<\/code>)<\/p>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>RPM Naming Schemes<\/h3>\n<p><a href=\"https:\/\/www.thegeekdiary.com\/understanding-rpm-versions-and-naming-schemes\/\">Understanding RPM Versions and Naming Schemes<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;name]-&#x5B;version]-&#x5B;release].&#x5B;arch].rpm\r\n<\/pre>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>RPM Default attributes<\/h3>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/6952384\/what-does-defattr-mean-in-rpm-spec-files\">What does %defattr mean in RPM spec files?<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nThe %defattr Directive\r\n  The %defattr directive allows setting of default attributes for files and directives.\r\n  The %defattr has a similar format to the %attr directive:\r\n    1. The default permissions, or &quot;mode&quot; for files.\r\n    2. The default user id.\r\n    3. The default group id.\r\n    4. The default permissions, or &quot;mode&quot; for directories.\r\n\r\n  The %attr directive has the following format:\r\n    %defattr(file mode, user, group, dir mode)\r\n<\/pre>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>install<\/h3>\n<p><a href=\"https:\/\/www.baeldung.com\/linux\/install-command\">Baeldung: The install Command in Linux<\/a><\/p>\n<p><!-- --------------------------------------------------------------------- --><\/p>\n<h3>rsync<\/h3>\n<p><a href=\"https:\/\/superuser.com\/questions\/1322108\/when-is-av-not-the-appropriate-option-for-rsync\">When is -av NOT the appropriate option for rsync?<\/a><\/p>\n<h4>-v<\/h4>\n<p>verbose<\/p>\n<h4>-a<\/h4>\n<p>archive mode<\/p>\n<p>includes:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n-r, --recursive recurse into directories\r\n-l, --links copy symlinks as symlinks\r\n-p, --perms preserve permissions\r\n-t, --times preserve modification times\r\n-g, --group preserve group\r\n-o, --owner preserve owner (super-user only)\r\n-D same as --devices --specials\r\n--devices preserve device files (super-user only)\r\n--specials preserve special files\r\n<\/pre>\n<p>and excludes:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n-H, --hard-links preserve hard links\r\n-A, --acls preserve ACLs (implies -p)\r\n-X, --xattrs preserve extended attributes\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>RPM packaging: A simplified guide to creating your first RPM How to create a Linux RPM package RPM Packaging Guide How to build rpm packages What actually is $RPM_BUILD_ROOT? \u251c\u2500\u2500 src \u2502\u00a0\u00a0 \u2514\u2500\u2500 source \u251c\u2500\u2500 build \u2502\u00a0\u00a0 \u2514\u2500\u2500 executables, libraries, etc. \u2514\u2500\u2500 pkg \u251c\u2500\u2500 Makefile \u251c\u2500\u2500 myapp.spec \u2514\u2500\u2500 package \u00a0\u00a0 \u2514\u2500\u2500 &lt;empty&gt; BUILD_DIR = $(realpath [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14228","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14228"}],"version-history":[{"count":12,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14228\/revisions"}],"predecessor-version":[{"id":14246,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14228\/revisions\/14246"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}