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

New `dpkg --print-subarchitecture' option



There are a reasonable number of utilities (update-modules, X
configuration, hwclock) that need to know more than just the processor
architecture that they're running on -- they need the type of hardware
as well (e.g. m68k does this).

For ARM, I wanted to have a centralised location for this information,
and thus propose to add an option to dpkg, `--print-subarchitecture',
which will open /proc/cpuinfo or /proc/hardware (or whatever you need
on your architecture to determine the hardware type) and spit out a
single, canonicalised word representing the hardware type.  On the ARM
architecture, examples of these are `acorn', `acorn26', `netwinder',
`shark', and so on.

I have an example patch which implements this which is included in the
version of this message that was posted to the `debian-dpkg' list.

There are, however, other ways that spring to mind to implement this,
including:

  * make `dpkg-architecture' do the work instead, possibly using its
    shell variable scheme;
  * have a separate shell script / small C program;
  * duplicate the code to calculate this in several different places;
  * rename the dpkg option to something else.

I'm posting this here to try and solicit some comment on what the best
thing to do is -- obviously I'd like the changes I make to be folded
back into the respective packages!

Thanks,

c.

---<cut here>---

diff -burN dpkg-1.6.14/main/enquiry.c dpkg-1.6.14-cmr/main/enquiry.c
--- dpkg-1.6.14/main/enquiry.c	Wed May  3 15:14:57 2000
+++ dpkg-1.6.14-cmr/main/enquiry.c	Wed Sep 20 18:21:30 2000
@@ -651,6 +651,55 @@
   if (fflush(stdout)) werr("stdout");
 }
 
+void printsubarch(const char *const *argv) {
+  if (*argv)
+    badusage(_("--print-subarchitecture does not take any argument"));
+
+  if (!strcmp(ARCHITECTURE, "arm")) {
+    char b[132], *h = 0;
+    FILE *fp;
+
+    /* Search for the `Hardware' field */
+
+    fp = fopen("/proc/cpuinfo", "r");
+    if (!fp) ohshite(_("error opening `/proc/cpuinfo'"));
+    while (fgets(b, sizeof b, fp)) {
+      if (!strncmp(b, "Hardware", 8)) {
+        char *p;
+        for (h = b + 8; *h != ':'; h++);
+        for (h++; *h == ' '; h++);
+        for (p = h + 1; !isspace(*p); p++);
+        *p = 0;
+      }
+    }
+    fclose(fp);
+
+    /* Convert it to a subarchitecture */
+
+    if (h) {
+      const static struct { char *h, *s; } table[] = {
+        { "Acorn-RiscPC", "acorn" },
+        { "Rebel-Netwinder", "netwinder" },
+        { "Acorn-Archimedes", "acorn26" },
+        { "Acorn-A5000", "acorn26" },
+        { "Shark", "shark" },
+        { 0, 0 }
+      }, *k;
+      for (k = table; k->h; k++)
+        if (!strcmp(k->h, h))
+          break;
+      if (k->s) {
+        if (printf("%s\n", k->s) == EOF) werr("stdout");
+        if (fflush(stdout)) werr("stdout");
+      } else
+        ohshit(_("no subarchitecture matches hardware type `%s'"), h);
+    } else
+      ohshit(_("`Hardware' field not found in `/proc/cpuinfo'!"));
+  }
+  else
+   ohshit(_("%s does not have subarchitectures"), ARCHITECTURE);
+}
+
 void printarch(const char *const *argv) {
   static const struct { const char *from, *to, *gnu; } archtable[]= {
 #include "archtable.h"
diff -burN dpkg-1.6.14/main/main.c dpkg-1.6.14-cmr/main/main.c
--- dpkg-1.6.14/main/main.c	Tue Apr 18 15:50:57 2000
+++ dpkg-1.6.14-cmr/main/main.c	Wed Sep 20 17:58:20 2000
@@ -77,6 +77,7 @@
   dpkg --print-architecture                print target architecture (uses GCC)\n\
   dpkg --print-gnu-build-architecture      print GNU version of target arch\n\
   dpkg --print-installation-architecture   print host architecture (for inst'n)\n\
+  dpkg --print-subarchitecture             print host hardware subarchitecture\
   dpkg --compare-versions <a> <rel> <b>    compare version numbers - see below\n\
   dpkg --help | --version                  show this help / version number\n\
   dpkg --force-help | -Dh|--debug=help     help on forcing resp. debugging\n\
@@ -341,6 +342,7 @@
   ACTION( "list",                           'l', act_listpackages,         listpackages    ),
   ACTION( "search",                         'S', act_searchfiles,          searchfiles     ),
   ACTION( "print-architecture",              0,  act_printarch,            printarch       ),
+  ACTION( "print-subarchitecture",	     0,  act_printarch,	   	   printsubarch    ),
   ACTION( "print-gnu-build-architecture",    0,  act_printgnuarch,         printarch       ),
   ACTION( "assert-support-predepends",       0,  act_assertpredep,         assertpredep    ),
   ACTION( "assert-working-epoch",            0,  act_assertepoch,          assertepoch     ),
diff -burN dpkg-1.6.14/main/main.h dpkg-1.6.14-cmr/main/main.h
--- dpkg-1.6.14/main/main.h	Sat Oct 23 22:15:31 1999
+++ dpkg-1.6.14-cmr/main/main.h	Wed Sep 20 17:59:10 2000
@@ -120,6 +120,7 @@
 void assertmulticonrep(const char *const *argv);
 void predeppackage(const char *const *argv);
 void printarch(const char *const *argv);
+void printsubarch(const char *const *argv);
 void printinstarch(const char *const *argv);
 void cmpversions(const char *const *argv);



Reply to: