Macros and Variables
drks — Thu, 2007-01-18 08:01
One of the most important things to become familiar with are the RPM macros available. The default macros are set at '/usr/lib/rpm/macros' on RedHat systems. You can override the defaults with your own macros file in your home directory. Simply create the file '~/.rpmmacros' and add the macro changes there.
For the purpose of interest, the following is a snippet from '/usr/lib/rpm/macros':
%_usr /usr
%_usrsrc %{_usr}/src
%_var /var
%__awk gawk
%__bzip2 /usr/bin/bzip2
%__cat /bin/cat
%__chgrp /bin/chgrp
%__chmod /bin/chmod
%__chown /bin/chown
%__cp /bin/cp
%__cpio /bin/cpio
%__file /usr/bin/file
%__gpg /usr/bin/gpg
%__grep /bin/grep
%__gzip /bin/gzip
%__id /usr/bin/id
%__install /usr/bin/install
%__ln_s ln -s
%__make /usr/bin/make
%__mkdir /bin/mkdir
%__mkdir_p /bin/mkdir -p
%__mv /bin/mvYou will notice that directories generally have a single '_' and commands have a double '__'. You should adapt this schema when creating your own macros. To define a macro, or more commonly a variable in the Spec itself you simply define it:
%define myvar value
You would then use the variable as '%{myvar}' which of course equals 'value'. You can also define variables at command line. Take for example, you may want to add an OS release tag to the RPMs (such as .rhel4). Add the following to the top of the Spec where the Release directive is:
Release: 1.bjd.%{os_ver_tag}Now from command line, you would do the following:
<b>[root@linuxbox SPECS/]#</b> rpmbuild -ba \ SPECS/pLsearch.bjd.spec \ --define="os_ver_tag rhel4"
Note: The backslashes delimite the line breaks. This is actually a single command.
The result would be an RPM looking like 'pLsearch-0.1.7-1.bjd.rhel4.noarch.rpm'. In a future section will will talk about 'If Conditions and the Bit Operator' where I will explain a cleaner way to add OS Version Tags like this.
Well this concludes the first section. At this point we are building RPMs from scratch, and we should be damn proud of it. Before you move on to the next sections, feel free to take a peak at some other Spec files. I ensure you that it will help you understand that there is MUCH more that you can do, and I will do my best to explain that in future sections. Here are some recommended Specs to look at:
Please note that any stupid issues with these may be related to me not knowing what I was doing when I first built them, or modified them. As I am in an RPM Development roll at work now, due to conflict of interest I can no longer feed the RPMs I build up to my personal webserver anymore. So I haven't been adding new stuff in a while (sorry).
RSS Feed