Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use rpm to expand the macros in a specfile?

Tags:

rpm

rpm-spec

The concrete example being I have lots of specfiles with Source0: or other Source lines containing macros. How can I have these macros expanded without actually starting a build on the specfile or writing my own parser?

like image 414
user376403 Avatar asked Sep 03 '10 09:09

user376403


People also ask

What are RPM macros?

RPM provides a rich set of macros to make package maintenance simpler and consistent across packages. For example, it includes a list of default path definitions which are used by the build system macros, and definitions for RPM package build specific directories.

What is Buildroot in RPM spec file?

By using Buildroot: in your spec file you are indicating that your package can be built (installed into and packaged from) a user-definable directory. This helps package building by normal users. RPM will use the buildroot listed in the spec file as the default buildroot.


2 Answers

Since rpm 4.9 you can use:

rpmspec -P <spec_file>

This will print out expanded spec file on stdout

like image 157
Stan Avatar answered Oct 18 '22 19:10

Stan


If its only the source lines you need parsed, spectool will do that for you. It's part of Fedora's rpmdevtools.

$ spectool ./mg.spec 
Source0: http://homepage.boetes.org/software/mg/mg-20110120.tar.gz
$ 

Here's its help screen

Usage: spectool [<options>] <specfile>
Options:
operating mode:
-l, --lf, --list-files        lists the expanded sources/patches (default)
-g, --gf, --get-files         gets the sources/patches that are listed with
                              a URL
-h, --help                    display this help screen

files on which to operate:
-A, --all                     all files, sources and patches (default)
-S, --sources                 all sources
-P, --patches                 all patches
-s, --source x[,y[,...]]      specified sources
-p, --patch a[,b[,...]]       specified patches

misc:
-d, --define 'macro value'    defines RPM macro 'macro' to be 'value'
-C, --directory dir           download into specified directory (default '.')
-R, --sourcedir               download into rpm's %{_sourcedir}
-n, --dryrun, --dry-run       don't download anything, just show what would be
                              done
-D, --debug                   output debug info, don't clean up when done
like image 20
Mark McKinstry Avatar answered Oct 18 '22 21:10

Mark McKinstry