Some macros

A repository where I can work on whatever random RPM macros come to mind.

Feel free to file issues if you have macros you'd like to see in Fedora, or send pull requests. Eventually I will add useful macros to the appropriate packages so that they can be used throughout Fedora.

You should be able to do fedpkg prep or fedpkg mockbuild from a checkout of this repo to see the packager-facing portion of these macros in action.

What's in here

Macros are grouped into individual files by function. Many macros have no output or effect on the specfile; they instead add objects (generally functions) to the Lua namespace. Such functions live in the 'fedora' table, but there is generally a macro which imports them into the global namespace. Macros for general use in Fedora should never pollute the global namespace and thus should never use these import functions. Packagers can use them in their own specs, of course.

Context is important for many macros and the functions they define. Some assume they will be evaluated or called while RPM is processing a scriptlet (%prep, %build, %install, etc.) and they may simply output code intended to be interpreted by the shell. Outside of a scriptlet, this will be interpreted by RPM as regular specfile directives and will likely cause an error. Similarly, some functions or macros may output specfile directives which will cause errors if evaluated inside of a scriptlet.

Note that macros themselves can begin scriptlets, and that once the first scriptlet tag (or the %description tag) is parsed by RPM, no more specfile directives will be parsed; everything that follows is either being run by the shell or interpreted as a file list.

Note that RPM will in some cases re-parse macro output. You must be careful when using percent signs in strings passed to macros which output text into the parse stream, because you may end up with recursive expansions.


Some additional macros for R.

Simplifies specifying the source URL for a package on CRAN.
Simple way to get the URL for a package's page on CRAN.

The above two will also cause %packname to be defined automatically from Name: if it isn't already defined.

The standard %prep boilerplate for an R package. Use at the beginning of the %prep section.
The standard %install boilerplate for an R package. Use at the beginning of the %install section. Also includes code to generate a file list in %packname.files which can if desired be included in the %files directive.
The standard %check boilerplate for an R package.
Adds the basic dependencies and build dependenciesi for a noarch R package. Also defines %rlibdir for convenience. Use anywhere before %prep.
Adds the basic build dependencies for an archful R package. Also defines %rlibdir appropriately for convenience. Use anywhere before %prep.
Expands to %r_archful_package, plus complete %prep, %install and %check sections using %r_prep, %r_install and %r_check. If a package uses only the boilerplate for those sections then this macro can replace most of the package.

These macros are under development and will change.

The %r_simple_noarch_package macro is not yet written.


Defines one macro, %omit_patch. It removes a patch from the set of patches which %autosetup will apply. This lets you use %autosetup even if you have a patch which doesn't always need to be applied.

%omit_patch takes an integer, which is the patch number (i.e. N in PatchN:) to omit, or a string, which is the patch name (i.e. XXX in Patch7: XXX) to omit.


Contains two macros:

Adds some utility functions to the Lua environment in the fedora table.
Imports those functions into the global namespace.

The included functions:

Performs the usual basename function.
get_numbered_patch(N), get_numbered_source(N)

Gets the full path to the patchfile or sourcefile given by N.

fedora.get_numbered_source(7) will produce the full path to the source file defined earlier in the spec with Source7:

Note that Patch: and Source: define the zeroth patch/source file, not the first.

If the given number does not correspond to a currently defined patch/source file, nil is returned.


Called while RPM is parsing scriptlet, will cause that scriptlet to echo the provided string (by outputting an echo statement into the spec).

Note that string will be interpreted by the shell as an argument to echo. Leading dashes or shell metacharacters will not print literally.

Will almost certainly cause errors if called while RPM is not parsing a scriptlet.


When called in a scriptlet, will cause that scriptlet to fail (by outputting exit 1).

Will almost certainly cause errors if called while RPM is not parsing a scriptlet.

Calls into the RPM %error macro, which causes RPM to store the provided string to be used in the final error report. Doesn't cause any output or interrupt any current scriptlet.
When called in a scriptlet, will echo the string, call rpmerror and then call exit.

Not implemented.

Returns true if the flag was passed to the macro in which the function is called, and false otherwise.


If option was passed to the macro in which the function is called, returns the value of that option as a string.

Returns nil otherwise.