DEV Community

Eric F 🇺🇦
Eric F 🇺🇦

Posted on

1

RPM: dynamic macro for %_topdir

When building RPM packages with rpmbuild and you run rpmdev-setuptree to setup the build environment. The default macro for %_topdir is %{getenv:HOME}/rpmbuild.

If you don't want to use the default location, you can define that with --define on the command line, or define the macro in ~/.rpmmacros.

To use a custom path I've seen suggestions to use $(pwd) - which is a great way to select current path. However… If you then run rpmdev-setuptree in your home folder, forgetting about the macro. All folders end up all over your home folder.

So, here's an example to set a macro in ~/.rpmmacros to make it more dynamic - and to prevent your custom macro to run in HOME.

# RPM build
# ------------------------------------------
# rpmdev-setuptree:
#   - If run in HOME: use standard folder layout
#     Ex: HOME/rpmbuild
#   - if not: use PWD from current dir
#     Ex1: PWD/rpmbuild,
#     Ex2: $ mkdir project && cd rpmbuild/project
#          $ rpmdev-setuptree
#          HOME/rpmbuild/project/{SOURCES,SPECS,etc}
#
# This is mainly a protection, to prevent PWD to create
# the folders directly in HOME
#
%_topdir %([[ %(pwd) == %{getenv:HOME} ]] && \
    echo %{getenv:HOME}/rpmbuild || echo %(pwd))
Enter fullscreen mode Exit fullscreen mode

So, now I can use it in better and more organized way. I put all in .rpm/rpmbuild/, and all projects can live side-by-side in there.

# Example
$ cd .rpm/rpmbuild/
$ mkdir baz && cd baz
$ rpmdev-setuptree
$ mkdir X_NOTES && touch X_NOTES/__notes.txt
$ cd ..
$ ls
foo bar baz
Enter fullscreen mode Exit fullscreen mode

This setup works really great for me. The xtra X_NOTES folder is just something I find useful to keep notes in, backups, original files, logs from failed builds, etc. Whatever you dont want to put in the other folders. Keeping it a bit cleaner.

Hope you found it useful.

 

// Happy hacking… 👍

· Eric

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay