Re: BuildRequires: how vary depending on build host?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.  ;-)

Good luck!

Tim
-- 
Tim Mooney                              mooney@xxxxxxxxxxxxxxxxxxxxxxxxx
Information Technology Services         (701) 231-1076 (Voice)
Room 242-J6, IACC Building              (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164


_______________________________________________
Rpm-list mailing list
Rpm-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/rpm-list

[Index of Archives]     [RPM Ecosystem]     [Linux Kernel]     [Red Hat Install]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Red Hat]     [Gimp]     [Yosemite News]     [IETF Discussion]

  Powered by Linux