Test for redhatness (when building RPM's)

Philip Prindeville philipp_subx at redfish-solutions.com
Fri Aug 19 18:15:05 UTC 2005


Paul Howarth wrote:

> Philip Prindeville wrote:
>
>> I'm trying to tweak a package so that it autodetects when it's being
>> built under Redhat/Fedora (et al) and does the right thing.
>>
>> Is there a simple and foolproof test for this?
>
>
> How about something like this:
>
> %define redhat %(/bin/grep "^Red Hat " /etc/redhat-release &> 
> /dev/null && echo 1 || echo 0)
> %define fedora %(/bin/grep "^Fedora " /etc/redhat-release &> /dev/null 
> && echo 1 || echo 0)
>
> ...
>
> %if %{redhat}
> echo Building on RedHat
> %else
> echo Not building on RedHat
> %endif
>
> %if %{fedora}
> echo Building on Fedora
> %else
> echo Not building on Fedora
> %endif
>
> %if %{redhat} || %{fedora}
> echo Building on RedHat or Fedora
> %else
> echo Not building on RedHat or Fedora
> %endif
>
> Paul.
>

Sorry, I wasn't very clear.

The test needs to be in the Makefile, not in the RPM spec file.

What I decided on was:

REDHAT := $(shell test -f /etc/redhat-release && echo yes)

...

ifeq ($(REDHAT),yes)
  ...
endif

as the solution.

Thanks.

-Philip





More information about the fedora-list mailing list