### Install Documentation and License Files Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Installs various documentation and license-related files into the installation directory. ```cmake install(FILES CONTRIBUTING.md COPYING CREDITS INSTALL README TYPE DOC) ``` -------------------------------- ### %setup macro options Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Illustrates the use of the %setup macro with options to control source unpacking and directory creation. ```spec %setup -a 1 -n my-build-dir ``` -------------------------------- ### Autotools Installation Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md The %install directive, often used with %make_install, prepares the software installation layout by copying built software into the build root. ```bash %install %make_install ``` -------------------------------- ### Install Manuals for Enabled Features Source: https://github.com/rpm-software-management/rpm/blob/master/docs/man/CMakeLists.txt Installs man pages based on enabled features and build configurations. It conditionally appends plugin-related man pages to the list before installing them to the appropriate directory. ```cmake set(manuals ${core}) if (ENABLE_PLUGINS) list(APPEND manuals rpm-plugins.8 rpms-plugin-prioreset.8 rpm-plugin-syslog.8) if (WITH_AUDIT) list(APPEND manuals rpm-plugin-audit.8) endif () if (WITH_DBUS) list(APPEND manuals rpms-plugin-dbus-announce.8 rpm-plugin-systemd-inhibit.8) endif () if (WITH_FAPOLICYD) list(APPEND manuals rpm-plugin-fapolicyd.8) endif () if (WITH_IMAEVM) list(APPEND manuals rpm-plugin-ima.8) endif () if (WITH_SELINUX) list(APPEND manuals rpm-plugin-selinux.8) endif () if (HAVE_UNSHARE) list(APPEND manuals rpm-plugin-unshare.8) endif () endif () foreach(man ${manuals}) set(fn ${CMAKE_CURRENT_BINARY_DIR}/${man}) get_filename_component(ext ${fn} EXT) string(REPLACE "." "man" section ${ext}) install(FILES ${fn} DESTINATION ${CMAKE_INSTALL_MANDIR}/${section}) endforeach() ``` -------------------------------- ### Install RPM Configuration Files Source: https://github.com/rpm-software-management/rpm/blob/master/scripts/CMakeLists.txt Installs daily, log, and suppression configuration files for RPM. ```cmake install(FILES rpm.daily rpm.log rpm.supp DESTINATION ${RPM_CONFIGDIR} ) ``` -------------------------------- ### Automated Patch Application with %autosetup Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This example demonstrates the basic usage of %autosetup to automatically apply all declared patches in order. ```rpm %prep %autosetup ``` -------------------------------- ### Install and Link Plugins Source: https://github.com/rpm-software-management/rpm/blob/master/plugins/CMakeLists.txt Iterates through all build system targets (plugins), links them to core RPM libraries, and installs them along with their associated macro files. ```cmake get_property(plugins DIRECTORY PROPERTY BUILDSYSTEM_TARGETS) foreach(plugin ${plugins}) target_link_libraries(${plugin} PRIVATE librpmio librpm ${Intl_LIBRARIES}) target_include_directories(${plugin} PRIVATE ${Intl_INCLUDE_DIRS}) install(TARGETS ${plugin} DESTINATION ${RPM_PLUGINDIR}) install(FILES macros.transaction_${plugin} DESTINATION ${RPM_MACROSDIR}) endforeach() ``` -------------------------------- ### Install Directories Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Installs directories for Lua configurations, macro definitions, and general RPM system configurations. ```cmake install(DIRECTORY DESTINATION ${RPM_CONFIGDIR}/lua) install(DIRECTORY DESTINATION ${RPM_CONFIGDIR}/macros.d) install(DIRECTORY DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/rpm) ``` -------------------------------- ### Interpreting the Example Dependency Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md Breaks down the example 'Requires' directive into its epoch, version, and release components. ```text epoch=9 version=5.00502 release=3 ``` -------------------------------- ### Get Test Help Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Displays all available options and usage information for the test execution script. ```bash ./rpmtests --help ``` -------------------------------- ### Install Jekyll and Plugins Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/devel_documentation.md Installs the Jekyll static website generator and necessary plugins for rendering the documentation locally. This is required for local development of the Reference Manual. ```bash gem install jekyll gem install jekyll-titles-from-headings jekyll-relative-links ``` -------------------------------- ### WITH Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'with' operator to require that all specified packages are fulfilled by the same package. This ensures related components are installed together. ```rpm Requires: (pkgA-foo with pkgA-bar) ``` -------------------------------- ### RPM Lead Package Name Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_lead.md Displays the bytes for the package name, version, and release, padded with null bytes. ```hex 00000010: 31 2e 32 2d 31 00 00 00 1.2-1... 00000018: 00 00 00 00 00 00 00 00 ........ 00000020: 00 00 00 00 00 00 00 00 ........ 00000028: 00 00 00 00 00 00 00 00 ........ 00000030: 00 00 00 00 00 00 00 00 ........ 00000038: 00 00 00 00 00 00 00 00 ........ 00000040: 00 00 00 00 00 00 00 00 ........ 00000048: 00 00 00 00 00 01 00 05 ........ ``` -------------------------------- ### Basic Architecture Dependency Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md A straightforward example of specifying an architecture-specific dependency using a macro. ```rpm Requires: %{name}.%{_target_cpu} ``` -------------------------------- ### Using %autosetup with Git for Patch Application Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This example shows how to use %autosetup with the 'git_am' option to apply patches as individual git commits. ```rpm %autosetup -S git_am ``` -------------------------------- ### Defining autotools build system macros Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/buildsystem.md Provides an example of how to support the classic autotools build system by defining macros for configuration, build, and install steps. These macros are used by the buildsystem specific macros. ```spec %buildsystem_autotools_conf() %configure %* %buildsystem_autotools_build() %make_build %* %buildsystem_autotools_install() %make_install %* ``` -------------------------------- ### RPM Lead OS and Signature Type Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_lead.md Shows the bytes indicating the OS the package was built for and the signature type. ```hex 00000050: 04 00 00 00 68 e6 ff bf ........ 00000058: ab ad 00 08 3c eb ff bf ........ ``` -------------------------------- ### ISA Dependency Expansion Example (i386 Target) Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md Illustrates the expansion of the %{?_isa} macro when targeting a 32-bit architecture (e.g., i386) on an x86_64 system. ```rpm Requires: libbar-devel(x86-32) >= 2.2 ``` -------------------------------- ### Install Package Configuration Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Installs the RPM package configuration file to the pkgconfig directory. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rpm.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ``` -------------------------------- ### Failed Dependencies Error Message Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Example of an error message displayed when package dependencies are not met during installation or upgrade. ```text failed dependencies: libICE.so.6 is needed by somepackage-2.11-1 libSM.so.6 is needed by somepackage-2.11-1 libc.so.5 is needed by somepackage-2.11-1 ``` -------------------------------- ### Install RPM Scripts and Utilities Source: https://github.com/rpm-software-management/rpm/blob/master/scripts/CMakeLists.txt Installs a collection of RPM-related scripts and utilities to the configuration directory. ```cmake install(PROGRAMS brp-compress brp-strip brp-strip-comment-note brp-strip-static-archive brp-remove-la-files check-files check-prereqs check-buildroot check-rpaths check-rpaths-worker find-lang.sh find-requires find-provides pkgconfigdeps.sh ocamldeps.sh fontconfig.prov script.req rpm_macros_provides.sh rpmdb_dump rpmdb_load rpm2cpio.sh tgpg sysusers.sh DESTINATION ${RPM_CONFIGDIR} ) ``` -------------------------------- ### Install librpmbuild Target Source: https://github.com/rpm-software-management/rpm/blob/master/build/CMakeLists.txt Installs the librpmbuild target and its associated export rules. This makes the library available for use by other projects after installation. ```cmake install(TARGETS librpmbuild EXPORT rpm-targets) ``` -------------------------------- ### Example BuildOption usage Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/buildsystem.md Demonstrates how to pass extra arguments to build commands, specifically for configuration. The `BuildOption` tag can be used multiple times for different sections. ```spec BuildOption: --enable-fu BuildOption(conf): --enable-fu ``` -------------------------------- ### ISA Dependency Expansion Example (x86-64) Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md Shows how the %{?_isa} macro expands for a native build on an x86_64 system, resulting in a specific architecture-bitness dependency. ```rpm Requires: libbar-devel(x86-64) >= 2.2 ``` -------------------------------- ### Interpreter Module Dependencies Output Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Example output from a per-interpreter dependency generator, showing package and module requirements with version specifiers. ```spec Mail-Header >= 1.01 perl(Carp) >= 3.2 perl(IO-Wrap) == 4.5 or perl(IO-Wrap)-4.5 ``` -------------------------------- ### Example RPM Dependency Specification Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md An example of a 'Requires' directive specifying a version with epoch and release. ```text Requires: perl >= 9:5.00502-3 ``` -------------------------------- ### Scriptlet Dependencies Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Declare dependencies required only for package scriptlets (e.g., %pre, %post) using Requires():. This ensures correct installation order and allows packages to be removed if no other dependencies exist. ```spec Requires(pre): /usr/sbin/useradd ``` -------------------------------- ### Install RPM IO Target Source: https://github.com/rpm-software-management/rpm/blob/master/rpmio/CMakeLists.txt Installs the librpmio target and exports it for use by other packages. ```cmake install(TARGETS librpmio EXPORT rpm-targets) ``` -------------------------------- ### Install RPM Programs Source: https://github.com/rpm-software-management/rpm/blob/master/scripts/CMakeLists.txt Installs executable programs for RPM management, including gendiff and rpm-setup-autosign. ```cmake install(PROGRAMS gendiff rpm-setup-autosign TYPE BIN) ``` -------------------------------- ### Serve Reference Manual Locally Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/devel_documentation.md Serves the Reference Manual locally using Jekyll's development server. This command starts a web server on localhost, enabling live preview and testing of documentation changes. ```bash jekyll serve ``` -------------------------------- ### Install librpmsign Target Source: https://github.com/rpm-software-management/rpm/blob/master/sign/CMakeLists.txt Installs the librpmsign target and exports it for use by other CMake projects. ```cmake install(TARGETS librpmsign EXPORT rpm-targets) ``` -------------------------------- ### Interpreter Module Dependencies Generator Output Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Example output from a dependency generator for interpreter modules, listing package names and versions. ```spec Foo-0.9 perl(Widget)-0-1 ``` -------------------------------- ### Package Summary Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Provide a brief summary of the package's purpose using the Summary tag, limited to 70 characters. ```spec Summary: Utility for converting mumbles into giggles ``` -------------------------------- ### Basic Package Dependency Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md Illustrates a basic dependency declaration for a package and its development sub-package. This example highlights a potential issue on multiarch systems where a 32-bit dependency might incorrectly satisfy a 64-bit requirement or vice-versa. ```rpm Name: foo ... BuildRequires: libbar-devel >= 2.2 %package devel Requires: libbar-devel >= 2.2 ... ``` -------------------------------- ### Setup Immutable Test Environment Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Use RPMTEST_SETUP for tests in an immutable system image with writable '.' and '/tmp'. ```bash RPMTEST_SETUP ``` -------------------------------- ### Example Conflict Specification Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md Demonstrates how to declare a conflict with another package using the 'Conflicts' tag. ```text Conflicts: sendmail ``` -------------------------------- ### Nested Supplements Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Example of using nested boolean operators within a 'Supplements' dependency. It requires 'foo' and either 'lang-support-cz' or 'lang-support-all'. ```rpm Supplements: (foo and (lang-support-cz or lang-support-all)) ``` -------------------------------- ### Manual Patch Application Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This is the traditional method of applying patches one by one in a spec file. ```rpm %prep %setup -q %patch 0 %patch 1 %patch 2 ... %patch 149 ``` -------------------------------- ### Chained OR Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Demonstrates chaining 'or' operators for multiple alternative dependencies. All alternatives are enclosed within a single set of parentheses. ```rpm Requires: (pkgA or pkgB or pkgC) ``` -------------------------------- ### Applying Patches in a Range using %autopatch Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This example shows how to apply patches within a specific range (inclusive) using both -m and -M options with %autopatch. ```rpm %autopatch -m 80 -M 99 ``` -------------------------------- ### Configure Mktree Common and Backend Files Source: https://github.com/rpm-software-management/rpm/blob/master/tests/CMakeLists.txt Configures common mktree files and backend-specific configurations, including setup scripts. ```cmake configure_file(mktree.common mktree.common @ONLY) configure_file(mktree.${MKTREE_BACKEND} mktree @ONLY) configure_file(setup.sh setup.sh @ONLY) ``` -------------------------------- ### Install Macros Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Installs generated macro files (macros, rpmrc, rpmpopt) to the RPM configuration directory. ```cmake makemacros() foreach(f macros rpmrc rpmpopt-${PROJECT_VERSION}) install(FILES ${CMAKE_BINARY_DIR}/${f} DESTINATION ${RPM_CONFIGDIR}) endforeach() ``` -------------------------------- ### Example of Enabling/Disabling Build Conditionals Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/conditionalbuilds.md Demonstrates how to use --with and --without command-line switches to control build features like gnutls and openssl support during the rpmbuild process. ```bash $ rpmbuild -ba newpackage.spec --with gnutls --without openssl ``` -------------------------------- ### Package License Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Use the License tag to specify a short summary of the package's license. Keep it under 70 characters. ```spec License: GPLv3 ``` -------------------------------- ### Bad Version Increment Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md Shows an example of a bad version increment where case difference ('a' vs 'A') leads to incorrect version ordering. ```text The 'a' (ASCII 97) is compared against 'A' (ASCII 65), making 2.1.7a the newer version. ``` -------------------------------- ### Customizing prep section with BuildOption Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/buildsystem.md Illustrates how to pass extra arguments to the `%prep` section, for example, to change the patch prefix stripping level. This is a global default customization and should not be overridden for individual packages. ```spec BuildOption(prep): -p0 ``` -------------------------------- ### Nested WITH and WITHOUT Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Demonstrates complex nesting with 'with' and 'without' operators. This requires either (pkgA with capB) or (pkgB without capA). ```rpm Requires: ((pkgA with capB) or (pkgB without capA)) ``` -------------------------------- ### Nested AND and UNLESS Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Example of nesting 'and' and 'unless' operators. This requires (driverA and driverA-tools) unless driverB is present. ```rpm Supplements: ((driverA and driverA-tools) unless driverB) ``` -------------------------------- ### Recommended Alternative to Nested IF in OR Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Shows the recommended way to express a dependency similar to the nested 'if' in 'or' example, using 'and' for clarity and predictable behavior. ```rpm Requires: ((pkgA and pkgB) or pkgC or pkg) ``` -------------------------------- ### Short Inline Comment Example Source: https://github.com/rpm-software-management/rpm/blob/master/CODING_STYLE.md Demonstrates the preferred style for short, inline comments. ```c /* Short and sweet */ ``` -------------------------------- ### Install RPM File Attributes Source: https://github.com/rpm-software-management/rpm/blob/master/fileattrs/CMakeLists.txt Installs various RPM file attribute definition files to the specified configuration directory. These files are essential for RPM's attribute management system. ```cmake install(FILES debuginfo.attr desktop.attr elf.attr font.attr metainfo.attr pkgconfig.attr ocaml.attr rpm_macro.attr rpm_lua.attr script.attr sysusers.attr usergroup.attr DESTINATION ${RPM_CONFIGDIR}/fileattrs ) ``` -------------------------------- ### Make Macros Configuration Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Configures installation paths and finds various system utilities required for RPM. It also generates platform-specific configuration files. ```cmake function(makemacros) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix "${prefix}") set(bindir "${exec_prefix}/${CMAKE_INSTALL_BINDIR}") set(sbindir "${exec_prefix}/${CMAKE_INSTALL_SBINDIR}") set(libexecdir "${exec_prefix}/${CMAKE_INSTALL_LIBEXECDIR}") set(datarootdir "${prefix}/${CMAKE_INSTALL_DATAROOTDIR}") set(datadir "${datarootdir}") set(sysconfdir "${CMAKE_INSTALL_FULL_SYSCONFDIR}") set(sharedstatedir "${CMAKE_INSTALL_FULL_SHAREDSTATEDIR}") set(localstatedir "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") set(libdir "${prefix}/=LIB=") set(includedir "${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") set(oldincludedir "${CMAKE_INSTALL_FULL_OLDINCLUDEDIR}") set(infodir "${prefix}/${CMAKE_INSTALL_INFODIR}") set(mandir "${prefix}/${CMAKE_INSTALL_MANDIR}") set(rundir /run) set(bindir_full ${CMAKE_INSTALL_FULL_BINDIR}) pkg_get_variable(sysusersdir systemd sysusersdir) if (NOT sysusersdir) set(sysusersdir /usr/lib/sysusers.d) endif() findutil(__7ZIP "7za;7z") findutil(__BZIP2 bzip2) findutil(__CAT cat) findutil(__CAR car) findutil(__CHMOD chmod) findutil(__CHOWN chown) findutil(__CP cp) findutil(__CURL curl) findutil(__FILE file) findutil(__GPG gpg) findutil(__GREP grep) findutil(__GZIP gzip) findutil(__ID id) findutil(__CC cc) findutil(__LN ln) findutil(__INSTALL install) findutil(__LRZIP lrzip) findutil(__LZIP lzip) findutil(__XZ xz) findutil(__MAKE make) findutil(__MKDIR mkdir) findutil(__MV mv) findutil(__PATCH patch) findutil(__RM rm) findutil(__SED sed) findutil(__TAR tar) findutil(__UNZIP unzip) findutil(__ZSTD zstd) findutil(__GEM gem) findutil(__GIT git) findutil(__HG hg) findutil(__BZR bzr) findutil(__QUILT quilt) findutil(__LD ld) findutil(__OBJDUMP objdump) findutil(__STRIP strip) findutil(__SYSTEMD_SYSUSERS systemd-sysusers) findutil(__FIND_DEBUGINFO find-debuginfo) findutil(__AWK awk) findutil(__AR ar) findutil(__AS as) findutil(__CPP cpp) findutil(__CXX c++) findutil(__SQ sq) list(GET db_backends 0 DB_BACKEND) set(host_cpu ${CMAKE_HOST_SYSTEM_PROCESSOR}) string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} host_os) set(host_vendor ${RPM_VENDOR}) set(host ${host_cpu}-${host_vendor}-${host_os}) set(RPMCANONVENDOR ${host_vendor}) set(RPMCANONOS ${host_os}) set(RPMCANONGNU -gnu) configure_file(platform.in platform @ONLY) configure_file(rpmrc.in rpmrc @ONLY) configure_file(macros.in macros @ONLY) configure_file(rpmpopt.in rpmpopt-${PROJECT_VERSION} @ONLY) configure_file(rpm.pc.in rpm.pc @ONLY) install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E env pkglibdir=${RPM_CONFIGDIR} ${CMAKE_SOURCE_DIR}/installplatform rpmrc platform macros ${RPMCANONVENDOR} ${RPMCANONOS} ${RPMCANONGNU} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})") endfunction() ``` -------------------------------- ### Nested IF and OR Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Shows nesting of 'if' and 'or' operators. This recommends myPkg-langCZ if langsupportCZ is present, and also requires specific fonts. ```rpm Recommends: ((myPkg-langCZ and (font1-langCZ or font2-langCZ)) if langsupportCZ) ``` -------------------------------- ### RPM Header Index Entry Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_header.md An index entry consists of four 32-bit integers: tag, type, offset, and count. This example shows an entry for package name (tag 1000, type STRING). ```Assembly 00000010: 00 00 03 e8 00 00 00 06 00 00 00 00 00 00 00 01 ................ ``` -------------------------------- ### Setup Mutable Test Environment Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Use RPMTEST_SETUP_RW to prepare a mutable snapshot for tests that need to modify the system image. The snapshot root is available at $RPMTEST. ```bash RPMTEST_SETUP_RW ``` -------------------------------- ### RPM Lead Magic Bytes Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_lead.md Illustrates the first 4 bytes of an RPM package, which serve as 'magic' to identify the package. ```hex 00000000: ed ab ee db 03 00 00 00 ``` -------------------------------- ### RPM Lead Version and Type Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_lead.md Shows the bytes representing the major and minor RPM file format version, and the package type (binary or source). ```hex 00000008: 00 01 72 70 6d 2d 32 2e ..rpm-2. ``` -------------------------------- ### Source Declaration Examples Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Declare source files used for building the package with the Source tag. Multiple sources can be declared, numbered or unnumbered. ```spec Source0: mysoft-1.0.tar.gz Source1: mysoft-data-1.0.zip ``` -------------------------------- ### Configure File as Configurable (Missing OK) Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md The %config(missingok) directive indicates that a configuration file need not exist on the installed machine. This is useful for optional configuration files or symlinks. ```bash %config(missingok) ``` -------------------------------- ### Package Group Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md The Group tag is optional and used for a short categorization of the package, also under 70 characters. ```spec Group: Development/Libraries ``` -------------------------------- ### Relocate Multiple Prefixes During Installation Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/relocatable.md For packages with multiple 'Prefix' definitions, use the '--relocate' option to specify new locations for each original prefix individually. ```bash rpm ... --relocate /opt=/usr/opt --relocate /etc=/usr/etc ... ``` -------------------------------- ### Build and Serve RPM Reference Manual Locally Source: https://github.com/rpm-software-management/rpm/blob/master/docs/README.md Build the RPM reference manual site and serve it locally for preview. This command should be run from the build directory after configuring the build with website support. ```bash make site ``` -------------------------------- ### Configure Include Directories for RPM IO Source: https://github.com/rpm-software-management/rpm/blob/master/rpmio/CMakeLists.txt Sets private and public include directories for the librpmio target, including build and install interfaces. ```cmake target_include_directories(librpmio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${Intl_INCLUDE_DIRS} PUBLIC $ $ ) ``` -------------------------------- ### AND Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'and' operator to require all specified packages to be fulfilled for the dependency to be true. This is a basic boolean operation. ```rpm Conflicts: (pkgA and pkgB) ``` -------------------------------- ### Configure File as Configurable (No Replace) Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md The %config(noreplace) directive ensures that a configuration file is installed with a .rpmnew extension if a modified version already exists on the system. ```bash %config(noreplace) ``` -------------------------------- ### Marking files as documentation with %doc Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Use %doc to mark files as documentation. The special form installs files in the documentation path, stripping all but the last path component. ```rpm %doc path/to/docfile ``` -------------------------------- ### Applying Patches with Number >= 100 using %autopatch Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This snippet shows how to use the -m option with %autopatch to apply patches starting from a specific number. ```rpm %autopatch -m 100 ``` -------------------------------- ### Install Relocatable Package to a Specific Prefix Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/relocatable.md When installing a relocatable RPM package, use the '--prefix' option to override the default installation directory specified in the spec file. ```bash rpm --prefix -i ``` -------------------------------- ### RPM Header Data Section Example (Strings) Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_header.md The data section follows the index entries. This snippet shows null-terminated strings for package name, version, and description. ```Hexdump 00000210: 72 70 6d 00 32 2e 31 2e 32 00 31 00 52 65 64 20 rpm.2.1.2.1.Red 00000220: 48 61 74 20 50 61 63 6b 61 67 65 20 4d 61 6e 61 Hat Package Mana 00000230: 67 65 72 00 31 e7 cb b4 73 63 68 72 6f 65 64 65 ger.1...schroede 00000240: 72 2e 72 65 64 68 61 74 2e 63 6f 6d 00 00 00 00 r.redhat.com.... ... 00000970: 6c 69 62 63 2e 73 6f 2e 35 00 6c 69 62 64 62 2e libc.so.5.libdb. 00000980: 73 6f 2e 32 00 00 so.2.. ``` -------------------------------- ### Overriding a build script section Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/buildsystem.md Shows how to completely override a declarative build system section, such as `%install`, by defining it manually in the spec file. Use with caution as it may not be supported by all build systems. ```spec %install # Your custom install steps here ``` -------------------------------- ### RPM Header Data Alignment Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/format_header.md Illustrates data alignment for integer types. Null bytes are inserted to ensure proper alignment for INT32, INT64, and INT16 types. ```Hexdump 00000060: 00 00 03 ef 00 00 00 06 00 00 00 28 00 00 00 01 ................ 00000070: 00 00 03 f1 00 00 00 04 00 00 00 40 00 00 00 01 ................ ... 00000240: 72 2e 72 65 64 68 61 74 2e 63 6f 6d 00 00 00 00 r.redhat.com.... 00000250: 00 09 9b 31 52 65 64 20 48 61 74 20 4c 69 6e 75 ....Red Hat Linu ``` -------------------------------- ### OR Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'or' operator to require at least one of the specified packages to be fulfilled for the dependency to be true. Useful for alternative package options. ```rpm Requires: (pkgA >= 3.2 or pkgB) ``` -------------------------------- ### Build Reference Manual Locally Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/devel_documentation.md Builds the Reference Manual locally using Jekyll. This command generates the static website in the 'docs/_site' directory, allowing for local preview of documentation changes. ```bash jekyll build ``` -------------------------------- ### Shell globbing examples Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Illustrates shell globbing rules for file names, including escaping metacharacters and handling spaces. Enclosing names in double quotes preserves literal values, with exceptions for \ and %. ```shell /opt/are.you|bob\? /opt/bob's\*htdocs\* /opt/bob's%%htdocs%% "/opt/bob's htdocs" ``` -------------------------------- ### Conditional ISA Dependency for Mixed Bitness Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md Provides an example of how to declare dependencies for rare cases where a 64-bit package might also require a 32-bit version of the same architecture family. This uses conditional logic based on the system's bitness. ```rpm Requires: foo%{_isa} %if %{__isa_bits} == 64 Requires: foo(%{__isa_name}-32) %endif ``` -------------------------------- ### Generating a file list for RPM with shell script Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md A shell script example demonstrating how to generate a file list with escaped file names for use with the %files -f option. It uses find and perl to format the output correctly. ```shell rm -f filelist.txt find %{buildroot} -type f -printf '/%%P\n' |\ perl -pe 's/(%)/%$1/g;'\ -pe 's/(["\\])/\\$1/g;'\ -pe 's/(^.*$)/"$1"/g;'\ > filelist.txt %files -f filelist.txt ``` -------------------------------- ### Configure Mktree Backend (Rootfs) Source: https://github.com/rpm-software-management/rpm/blob/master/tests/CMakeLists.txt Sets up the mktree build tool with the rootfs backend, requiring the 'bwrap' executable. ```cmake elseif (MKTREE_BACKEND STREQUAL rootfs) set(MKTREE_NATIVE yes) find_program(BWRAP bwrap REQUIRED) mark_as_advanced(BWRAP) endif() ``` -------------------------------- ### Configure Mktree Backend (OCI) Source: https://github.com/rpm-software-management/rpm/blob/master/tests/CMakeLists.txt Sets up the mktree build tool with the OCI backend, including finding necessary tools like podman or docker and configuring Dockerfiles. ```cmake set(MKTREE_BACKEND oci CACHE STRING "Mktree backend to use") if (MKTREE_BACKEND STREQUAL oci) find_program(PODMAN podman) find_program(DOCKER docker) mark_as_advanced(PODMAN DOCKER) os_release(OS_NAME ID) os_release(OS_VERSION VERSION_ID) set(DOCKERFILE ${CMAKE_CURRENT_SOURCE_DIR}/Dockerfile.${OS_NAME}) if (PODMAN AND EXISTS ${DOCKERFILE}) set(MKTREE_NATIVE yes) configure_file(${DOCKERFILE} Dockerfile COPYONLY) add_custom_target(ci COMMAND ./mktree.oci build --toolchain clang COMMAND ./mktree.oci clean COMMAND ./mktree.oci build --toolchain gcc COMMAND ./mktree.oci check ${JOBS} $(TESTOPTS) COMMAND ./mktree.oci clean WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) else() set(MKTREE_NATIVE no) configure_file(Dockerfile Dockerfile COPYONLY) endif() find_program(PODMAN NAMES podman docker REQUIRED) ``` -------------------------------- ### Include Directories Configuration Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Sets up include directories for the build process, including binary directory, misc, public headers, and specific subdirectories. ```cmake include_directories(${CMAKE_BINARY_DIR}) # global private includes include_directories(${CMAKE_SOURCE_DIR}/misc) # public headers include_directories(${CMAKE_SOURCE_DIR}/include) ``` -------------------------------- ### Build All Manuals Source: https://github.com/rpm-software-management/rpm/blob/master/docs/man/CMakeLists.txt Iterates through a combined list of core and extra manuals to generate man pages. It uses a custom command to process source files and create the final man pages, embedding the RPM version. ```cmake set(manuals ${core} ${extra}) foreach(man ${manuals}) add_custom_command(OUTPUT ${man} COMMAND sed '1 s/$$/ "RPM ${CMAKE_PROJECT_VERSION}"/' < ${CMAKE_CURRENT_SOURCE_DIR}/${man}.scd | ${SCDOC} > ${man} DEPENDS ${man}.scd) endforeach() add_custom_target(man ALL DEPENDS ${manuals}) ``` -------------------------------- ### Run OCI Image with Podman Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Demonstrates how to run the tagged OCI image interactively using Podman. ```bash podman run -it ... ``` -------------------------------- ### Mark File as Artifact Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md The %artifact attribute denotes files that are side-effects of packaging and can be filtered out during queries or installations. ```bash %artifact ``` -------------------------------- ### Overriding Dependency Checks Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md Illustrates the command-line flag used to bypass dependency checking during package installation. ```bash --nodeps ``` -------------------------------- ### Add Dummy Database Backend Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Appends 'dummy' to the list of database backends. ```cmake list(APPEND db_backends dummy) ``` -------------------------------- ### Comment in Spec File Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md A basic comment in an RPM spec file starts with a '#'. Comments are processed after macro expansion. ```spec # this is a comment ``` -------------------------------- ### Configure RPM Build for Website Source: https://github.com/rpm-software-management/rpm/blob/master/docs/README.md Configure the RPM build to include website generation. This is a prerequisite for rendering the reference manual locally. ```bash cmake -DWITH_WEBSITE=ON [...] ``` -------------------------------- ### %patch macro usage Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Demonstrates applying patches using the %patch macro with different syntaxes and options. ```spec %patch -P1 ``` ```spec %patch 1 ``` ```spec %patch -p1 -b .orig ``` -------------------------------- ### Configure Include Directories for librpmbuild Source: https://github.com/rpm-software-management/rpm/blob/master/build/CMakeLists.txt Sets up include directories for the librpmbuild library, distinguishing between build-time and install-time visibility. It includes local, project-wide, and external include paths. ```cmake target_include_directories(librpmbuild PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/rpmio ${CMAKE_SOURCE_DIR}/lib ${Intl_INCLUDE_DIRS} PUBLIC $ $ ) ``` -------------------------------- ### Run All Tests Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Builds the OCI image if not already built and performs automated testing. This is the standard command for comprehensive testing. ```bash make check ``` -------------------------------- ### IF Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'if' operator for reverse implication: the first package is required if the second is fulfilled. This is useful for optional language packs. ```rpm Recommends: (myPkg-langCZ if langsupportCZ) ``` -------------------------------- ### Configure config.h Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Generates the config.h file from config.h.in. ```cmake configure_file(config.h.in config.h) ``` -------------------------------- ### Querying Packages Requiring or Providing an Item Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Use --whatrequires to find all packages that depend on a specified item. Use --whatprovides to find all packages that offer a specified virtual package. ```bash rpm --query --whatrequires rpm --query --whatprovides ``` -------------------------------- ### Specifying ISA Dependencies Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/arch_dependencies.md Demonstrates how to declare an architecture-specific dependency using the %{?_isa} macro. This ensures that the correct bitness of the dependency package is selected. ```rpm Requires: libbar-devel%{?_isa} >= 2.2 ``` -------------------------------- ### UNLESS Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'unless' operator for reverse negative implication: the first package is required if the second is NOT fulfilled. This is useful for alternative drivers. ```rpm Conflicts: (myPkg-driverA unless driverB) ``` -------------------------------- ### Configure Package Export Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt Configures and installs package configuration files (like rpm-config.cmake) to make the RPM libraries findable by other CMake projects using find_package(). ```cmake include(CMakePackageConfigHelpers) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/rpm-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/rpm-config.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rpm ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/rpm-config-version.cmake COMPATIBILITY SameMinorVersion ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/rpm-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/rpm-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rpm ) ``` -------------------------------- ### Marking files as licenses with %license Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/spec.md Use %license to mark files as licenses. This is similar to %doc but licenses cannot be filtered out and must always be present. ```rpm %license path/to/licensefile ``` -------------------------------- ### Programmatically Generating Patch Declarations with Lua Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/autosetup.md This example uses the embedded Lua interpreter within a spec file to programmatically generate a series of patch declarations. ```rpm %{lua:for i=1,45 do print(string.format("Patch%u: bash42-%03u\n", i, i)) end} ``` -------------------------------- ### WITHOUT Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'without' operator to require a single package that satisfies the first condition but not the second. This is useful for excluding specific versions or features. ```rpm Requires: (pkgA-foo without pkgA-bar) ``` -------------------------------- ### IF ELSE Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'if else' operator for conditional requirements. The first package is required if the second is fulfilled, otherwise the third package is required. ```rpm Requires: (myPkg-backend-mariaDB if mariaDB else sqlite) ``` -------------------------------- ### Run Binary within Snapshot Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Prefix commands with 'runroot' to execute them within the snapshot. Use '--setenv' to pass environment variables. ```bash runroot rpm ... ``` ```bash runroot --setenv FOO "foo" rpm ... ``` -------------------------------- ### Run Binary as Specific User Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Use 'runroot_user' to execute a binary as the specified user within the snapshot. Use '-n ' to select a user from a list. ```bash runroot_user rpm ... ``` ```bash runroot_user -n rpm ... ``` -------------------------------- ### Bad Version Format Change Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md Highlights a problematic version format change where a date is numerically greater than a previous version, causing RPM to consider it 'newer'. ```text The date may be the older version, but it is numerically greater 2 so it is considered newer :( ``` -------------------------------- ### Get User/Group Name from ID Source: https://github.com/rpm-software-management/rpm/blob/master/CMakeLists.txt A helper function to extract the username or group name associated with UID 0 or GID 0 from /etc/passwd or /etc/group using AWK. ```cmake function(id0name var file) execute_process(COMMAND ${AWK} -F: "$3==0 {print $1;exit}" ${file} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE name) if ("${name}" STREQUAL "") set(name root) endif() set(${var} ${name} PARENT_SCOPE) endfunction() ``` -------------------------------- ### Run Tests by Keyword Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Selects and runs tests based on keywords present in their descriptions. Multiple -k parameters can be used for combined filtering. ```bash make check TESTOPTS="-k $KEYWORD" ``` -------------------------------- ### Define OS Release Function Source: https://github.com/rpm-software-management/rpm/blob/master/tests/CMakeLists.txt A CMake function to extract OS release information. It executes a shell command to get a specific key from /etc/os-release and converts it to lowercase. ```cmake function(os_release var key) execute_process( COMMAND sh -c ". /etc/os-release; echo $${key}" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE value ) string(TOLOWER ${value} value) set(${var} ${value} PARENT_SCOPE) endfunction() ``` -------------------------------- ### Nested Boolean Operators Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Shows nesting of boolean operators, combining 'or' and 'and' to create complex dependency rules. Inner expressions must also be parenthesized. ```rpm Requires: (pkgA or (pkgB and pkgC)) ``` -------------------------------- ### UNLESS ELSE Operator Example Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/boolean_dependencies.md Use the 'unless else' operator for conditional requirements with an alternative. The first package is required if the second is NOT fulfilled, otherwise the third package is required. ```rpm Conflicts: (myPkg-backend-SDL1 unless myPkg-backend-SDL2 else SDL2) ``` -------------------------------- ### Create Custom Users for Snapshot Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Supply a list of usernames to RPMTEST_USER to create multiple custom users. ```bash RPMTEST_USER([user1, user2]) ``` -------------------------------- ### Querying Package Dependencies Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Use --requires to list packages a specific package depends on, including version constraints. Use --provides to list capabilities a package offers. ```bash rpm --query --requires rpm --query --provides ``` -------------------------------- ### Handle Literal Square Brackets in Commands Source: https://github.com/rpm-software-management/rpm/blob/master/tests/README.md Wrap scripts or expected output in double square brackets to specify literal square brackets, for example, in RPM --qf format strings. ```bash RPMTEST_CHECK([[ runroot rpm -q --qf '[%{FILENAMES}\n]' ... ]]) ``` -------------------------------- ### CMakeLists.txt for RPM Debug Plugin Source: https://github.com/rpm-software-management/rpm/blob/master/tests/data/debugplugin/CMakeLists.txt This snippet shows the CMake configuration to build a shared library plugin for RPM debugging. It finds the RPM package, defines the library, links it, and installs it along with its macros. ```cmake cmake_minimum_required(VERSION 3.18) project(trpm VERSION 1.0 DESCRIPTION "test rpm plugin API" LANGUAGES C) find_package(rpm REQUIRED) set(CMAKE_SHARED_MODULE_PREFIX "") add_library(debug MODULE debug.c) target_link_libraries(debug PRIVATE rpm::librpm) install(TARGETS debug DESTINATION ${RPM_PLUGINDIR}) install(FILES macros.transaction_debug DESTINATION ${RPM_MACROSDIR}) ``` -------------------------------- ### Define Package Prefix in Spec File Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/relocatable.md Use the 'Prefix' directive in your RPM spec file to specify a base directory for relocatable packages. All files listed in the %files section must start with this prefix. ```spec Prefix: ``` -------------------------------- ### Verifying Package Dependencies Source: https://github.com/rpm-software-management/rpm/blob/master/docs/manual/more_dependencies.md Use the -V or --verify flag to check package dependencies. Use --nodeps to ignore dependencies during verification, or --nofiles to verify only dependencies and not file attributes. ```bash rpm -V rpm --verify rpm -V --nodeps rpm -V --nofiles rpm -Va --nofiles --nodeps ```