Thank you very much Tim, for the great background on RPM macros. The shell programming is no problem; the main problem was my lack of understanding of RPM. Thank you for your most helpful insight. Your examples are very helpful. Tim Mooney wrote: > In regard to: BuildRequires: how vary depending on build host?, Nick...: > > >Dear Folks, > > > >I am writing RPM packages. How do I write a BuildRequires statement > >that depends on the version of Red Hat/Fedora of the build host? > > > >My problem is that the package needs db3-devel on build platforms Red > >Hat 7.3 and older, and needs db4-devel otherwise. Please could anyone > >suggest a macro or some sensible way of writing such a BuildRequires > >statement? I would be most grateful for any suggestions. > > Disclaimer: I'm behind the times with RPM (but I do follow the list pretty > closely and look longingly at *some* of the features in recent RPM. ;-) ) > > Before you can make the determination in a spec file, you need to be able > to make the determination programmatically. If you were going to make > the determination of "older than 7.3" from a shell script, how would you > do it? > > For better or worse, when I've had to do this, I generally look for > /etc/redhat-release, and pull out the version from that. Enterprise Linux > makes it a little harder because you can't just do something like: > > vers=`awk '{ print $5 }' /etc/redhat-release` > # can't use expr, it doesn't like floats > vers_x_10=`/bin/echo -e "$vers\n10\n*\np\n" | dc | sed -e 's/.0$//'` > if test $vers_x_10 -le 73 ; then > # whew, what smells? > : > else > # that's the stuff > : > fi > > You have to also check if it's Enterprise, and then Enterprise 2.1 would > be "older than 7.3" but Enterprise 3.0 is not. Note that the version > field also isn't in position 5 in the file in that case either. > > If you know all the codenames for the versions of Red Hat of vintage 7.3 > and older, it's probably more straightforward to egrep for all of them. > If grep finds a match, it's "7.3 or older". > > Once you have a programmatic way of determining the question, that can be > turned into a macro: > > %define is_rh_lt_73 %(your shell code here) > > You basically want your shell code to *output* `1' if it is RH <= 7.3, and > 0 if it's not. The trick is going to be cramming all your shell code into > the RHS of that macro. ;-) > > And then you can do something like (my syntax may be a bit off) > > %if %{is_rh_lt_73} > BuildRequires: db3-devel > %endif > > %if %{!is_rh_lt_73} > BuildRequires: db4-devel > %endif > > You can learn a lot by looking at /usr/share/doc/rpm/macros and reading > some of the /usr/lib/rpm/macros that are part of RPM. > > If it's any consolation, it's not an easy problem. Getting a succinct bit > of shell code that answers 0 or 1 is the hard part, and then stuffing that > shell code into %(...) for evaluation is not going to be trivial > either, but once you've solved *those* two problems, the rest is pretty > trivial. ;-) -- Nick Urbanik RHCE nicku(at)vtc.edu.hk Dept. of Information & Communications Technology Hong Kong Institute of Vocational Education (Tsing Yi) Tel: (852) 2436 8576, (852) 2436 8713 Fax: (852) 2436 8526 PGP: 53 B6 6D 73 52 EE 1F EE EC F8 21 98 45 1C 23 7B ID: 7529555D GPG: 7FFA CDC7 5A77 0558 DC7A 790A 16DF EC5B BB9D 2C24 ID: BB9D2C24 _______________________________________________ Rpm-list mailing list Rpm-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/rpm-list