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

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay