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

Re: getting architecture/os info when building an rpm



On Tue, Jan 08, 2002 at 11:59:19AM -0500, rpjday wrote:
> 
>   i've been trying to figure out how to identify/select
> architecture info in a spec file, and i'm getting just plain
> confused.
> 
>   first, near as i can tell, there are two variables,
> RPM_ARCH and RPM_OS, that reflect the architecture and the
> operating system on which the build is being done.  these
> are entirely dependent on the host OS, and are not affected
> by anything else you do, like selecting a build architecture
> and so on, is that right?  for me, they're always "i386"
> and "linux".  so far, so good.

RPM_{ARCH,OS} are set by the %___build_pre macro that is expanded at
the beginning of a scriptlet (to make it a script):

%___build_pre   \
  RPM_SOURCE_DIR=\"%{u2p:%{_sourcedir}}\"\
  RPM_BUILD_DIR=\"%{u2p:%{_builddir}}\"\
  RPM_OPT_FLAGS=\"%{optflags}\"\
  RPM_ARCH=\"%{_arch}\"\
  RPM_OS=\"%{_os}\"\
  export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\
  RPM_DOC_DIR=\"%{_docdir}\"\
  export RPM_DOC_DIR\
  RPM_PACKAGE_NAME=\"%{name}\"\
  RPM_PACKAGE_VERSION=\"%{version}\"\
  RPM_PACKAGE_RELEASE=\"%{release}\"\
  export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
  %{?buildroot:RPM_BUILD_ROOT=\"%{u2p:%{buildroot}}\"\
  export RPM_BUILD_ROOT}\
  \
  %{verbose:set -x}%{!verbose:exec > /dev/null}\
  umask 022\
  cd %{u2p:%{_builddir}}\

> 
>   but how exactly does the "--target" option work with
> rpmbuild?  from the man page, i read that the argument to
> target is interpreted as "arch-vendor-os", and sets the
> macros %_target, %_target_arch and %_target_os.  certainly,
> it doesn't seem that this means "respectively," otherwise
> those are incredibly misnamed macros.
> 
>   so i tested by adding some "echo" statements to the %prep,
> was confused by what i saw, gratuitously added "echo"es for
> two more macros i just made up, and here's what got printed
> when i ram rpmbuild with "--target sparc-sun-sunos -bp" on my
> spec file:
> 
>   %_target		sparc-sunos
>   %_target_arch		%_target_arch (clearly no such macro)

The macro you want is %{_target_cpu}, same name as what autoconf uses.

>   %_target_os		sunos
>   %_target_vendor	pc	(huh?)
>   %_vendor		redhat	(double huh??)
> 
> are these macros documented anywhere?  more to the point,

The macros are the same as the similarly named autoconf variables.

> when one is doing a conditional based on %ifos or %ifarch,
> what exactly is being compared?  by that, i mean there is

%ifarch uses the expansion of %_target_cpu, %ifos uses %_target_os.

>From build/parseSpec.c:247

...
    if (! strncmp("%ifarch", s, sizeof("%ifarch")-1)) {
        const char *arch = rpmExpand("%{_target_cpu}", NULL);
        s += 7;
        match = matchTok(arch, s);
        arch = _free(arch);
    } else if (! strncmp("%ifnarch", s, sizeof("%ifnarch")-1)) {
        const char *arch = rpmExpand("%{_target_cpu}", NULL);
        s += 8;
        match = !matchTok(arch, s);
        arch = _free(arch);
    } else if (! strncmp("%ifos", s, sizeof("%ifos")-1)) {
        const char *os = rpmExpand("%{_target_os}", NULL);
        s += 5;
        match = matchTok(os, s);
        os = _free(os);
    } else if (! strncmp("%ifnos", s, sizeof("%ifnos")-1)) {
        const char *os = rpmExpand("%{_target_os}", NULL);
        s += 6;
        match = !matchTok(os, s);
        os = _free(os);
    } else if (! strncmp("%if", s, sizeof("%if")-1)) {
...

> no macro listed that equals just "sparc".  so what's being
> compared if i use the test
> 
>   %ifarch sparc
> 
> getting curiouser and curiouser,

Yup. Isn't legacy wonderful :-(

73 de Jeff

-- 
Jeff Johnson	ARS N3NPQ
jbj@jbj.org	(jbj@redhat.com)
Chapel Hill, NC





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