First crack at adding ISA provides to packages (rhbz#235755)
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 10 Apr 2008 16:36:03 +0000 (19:36 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 10 Apr 2008 16:36:03 +0000 (19:36 +0300)
- Horrible kludgery to get the isa names and bits into platform specific
  macros from installplatform script. That beast needs to die. I mean really

- In build, add provides: name(isa) = evr automatically when it makes
  sense (similarly to name = evr provides). ISA consists of ISA name and
  bitness (or wordsize). This can be used to correctly
  express multilib dependencies without resorting to (expensive!) file
  dependency kludges, eg for dlopen()'ed libraries where automatic
  dep extraction doesn't force dependency on 32bit vs 64bit version, you
  can now use:
      Requires: foo-plugin%{?_isa}
  This expands to foo-plugin(x86-32) for i?86 packages, foo-plugin(x86-64)
  to x86_64 etc, and permits spec to be shared with older distros which
  don't have ISA provides.

- The same could be expressed with "canon arch" just as well, but
  using the ISA to differentiate from %_arch and the like:
  eg i386 could be used instead of x86-32 but it's overloaded with meanings
  (the actual i386 processor vs i386 compatible cpu family etc)

build/pack.c
installplatform
macros.in
platform.in

index 711207b..37159a0 100644 (file)
@@ -601,15 +601,33 @@ static const rpmTag copyTags[] = {
 static void addPackageProvides(Header h)
 {
     HAE_t hae = headerAddOrAppendEntry;
-    const char *name = NULL;
-    char *evr;
+    HGE_t hge = headerGetEntry;
+    const char *name = NULL, *arch = NULL;
+    char *evr, *isaprov;
     rpmsenseFlags pflags = RPMSENSE_EQUAL;
+    int noarch = 0;
 
     /* <name> = <evr> provide */
     evr = headerGetEVR(h, &name);
     hae(h, RPMTAG_PROVIDENAME, RPM_STRING_ARRAY_TYPE, &name, 1);
     hae(h, RPMTAG_PROVIDEFLAGS, RPM_INT32_TYPE, &pflags, 1);
     hae(h, RPMTAG_PROVIDEVERSION, RPM_STRING_ARRAY_TYPE, &evr, 1);
+
+    /*
+     * <name>(<isa>) = <evr> provide
+     * FIXME: noarch needs special casing for now as BuildArch: noarch doesn't
+     * cause reading in the noarch macros :-/ 
+     */
+    isaprov = rpmExpand(name, "%{?_isa}", NULL);
+    hge(h, RPMTAG_ARCH, NULL, (rpm_data_t *)&arch, NULL);
+    noarch = (strcmp(arch, "noarch") == 0);
+    if (!noarch && strcmp(name, isaprov)) {
+       hae(h, RPMTAG_PROVIDENAME, RPM_STRING_ARRAY_TYPE, &isaprov, 1);
+       hae(h, RPMTAG_PROVIDEFLAGS, RPM_INT32_TYPE, &pflags, 1);
+       hae(h, RPMTAG_PROVIDEVERSION, RPM_STRING_ARRAY_TYPE, &evr, 1);
+    }
+    free(isaprov);
+
     free(evr);
 }
 
index de458a7..193625a 100755 (executable)
@@ -75,6 +75,45 @@ for SUBST in $SUBSTS ; do
     x86_64-linux|amd64-linux|ia32e-linux) LIB=lib64; MULTILIBNO=2 ;;
   esac
 
+  # XXX FIXME: incomplete and quite likely wrong too in places,
+  # consult various arch folks for correct names etc.
+  ISANAME=
+  ISABITS=
+  case "${ARCH}" in
+    sparc|sparcv8|sparcv9*) 
+       ISANAME=sparc
+       ISABITS=32
+       ;;
+    sparc64|sparc64v) 
+       ISANAME=sparc
+       ISABITS=64
+       ;;
+    s390)
+       ISANAME=s390
+       ISABITS=32
+       ;;
+    s390x)
+       ISANAME=s390
+       ISABITS=64
+       ;;
+    ppc)
+       ISANAME=ppc
+       ISABITS=32
+       ;;
+    ppc64)
+       ISANAME=ppc
+       ISABITS=64
+       ;;
+    i?86|pentium?|athlon|geode)
+       ISANAME=x86
+       ISABITS=32
+       ;;
+    x86_64|amd64|ia32e)
+       ISANAME=x86
+       ISABITS=64
+       ;;
+  esac
+
   if [ -n "$MULTILIBNO" ]; then
     MULTILIBSED='-e /^@MULTILIB/d -e s,@MULTILIBNO@,'$MULTILIBNO,
   else
@@ -114,6 +153,8 @@ for SUBST in $SUBSTS ; do
        -e "s,@ARCH_INSTALL_POST@,$ARCH_INSTALL_POST," \
        -e "s,@DEFAULTDOCDIR@,$DEFAULTDOCDIR," \
        -e '/\${\w*:-/!s,\${,%{_,' \
+       -e "s,@ISANAME@,$ISANAME," \
+       -e "s,@ISABITS@,$ISABITS," \
        $MULTILIBSED \
        $VENDORSED \
   | grep -v '^@' \
@@ -124,7 +165,7 @@ done
 { cd ${DESTDIR}/${platformdir}
   [ -L noarch-${OS} ] && rm -f noarch-${OS} 2>/dev/null
   mkdir -p noarch-${OS}
-  sed -e "/^%_arch/s,${arch},noarch," ${arch}-${OS}/macros | grep -v '^%optflags' > noarch-${OS}/macros
+  sed -e "/^%_arch/s,${arch},noarch," ${arch}-${OS}/macros | grep -v '^%optflags' | grep -v "^%__isa" > noarch-${OS}/macros
 #  [ -d ${VENDOR} ] || mkdir ${VENDOR}
 #  for i in brp-* find-lang.sh find-provides find-requires perl.prov perl.req
 #  do
index e4cd2df..93c60fe 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -811,6 +811,10 @@ print (t)\
 %optflags              -O2
 
 #
+# ISA dependency marker, none for noarch and name-bitness for others
+%_isa                  %{?__isa:(%{__isa})}%{!?__isa:%{nil}}
+
+#
 # Define per-arch and per-os defaults. Normally overridden by per-target macros.
 %__arch_install_post   %{nil}
 %__os_install_post     %{___build_post}
index bf4f0b5..ed4f148 100644 (file)
 %_target_platform      %{_target_cpu}-%{_vendor}-%{_target_os}
 %optflags              @RPMRC_OPTFLAGS@
 
+%__isa_name            @ISANAME@
+%__isa_bits            @ISABITS@
+%__isa                 %{__isa_name}-%{__isa_bits}
+
 #==============================================================================
 # ---- configure macros.
 #