[28283] in Source-Commits

home help back first fref pref prev next nref lref last post

machtype commit: Remove C version; clean up build and packaging

daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Sun Jun 22 14:34:20 2014

Date: Sun, 22 Jun 2014 14:34:12 -0400
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201406221834.s5MIYCjm006100@drugstore.mit.edu>
To: source-commits@MIT.EDU

https://github.com/mit-athena/machtype/commit/a5ae3fc4cea1ed8b4b053e19512337314d096624
commit a5ae3fc4cea1ed8b4b053e19512337314d096624
Author: Jonathan Reed <jdreed@mit.edu>
Date:   Thu Jun 19 18:12:54 2014 -0400

    Remove C version; clean up build and packaging
    
    - Remove the legacy C code; we're not building for IRIX
      or Solaris anymore.
    - Remove the autotools and replace it with a simpler
      Makefile
    - Add Python script to generate the sysnames, in preference
      to doing it in debian/rules
    - Depend on the necessary OpenAFS version to allow long
      sysname lists (now present in all distros we build for)
    - Build-Depend on Python
    - Wrap Depends and Build-Depends fields in control file

 Makefile             |   37 +++++
 Makefile.in          |   65 --------
 configure.in         |   59 -------
 debian/changelog     |   10 ++
 debian/control       |    8 +-
 debian/rules         |  132 +----------------
 generate_sysnames.py |  158 +++++++++++++++++++
 machtype.c           |  192 -----------------------
 machtype.h           |    5 -
 machtype_irix.c      |  417 --------------------------------------------------
 machtype_solaris.c   |  181 ----------------------
 11 files changed, 213 insertions(+), 1051 deletions(-)

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..623a485
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,37 @@
+OS_SCRIPT = machtype_linux.sh
+MKDIR_P = mkdir -p
+INSTALL = install
+lbindir = /bin
+mandir = /usr/share/man
+ATHENA_MAJOR_VERSION = 10
+ATHENA_MINOR_VERSION = 0
+SYSNAMES := $(shell ./generate_sysnames.py)
+MACHTYPE_ATHENA_SYS := $(word 1, $(SYSNAMES))
+MACHTYPE_ATHENA_SYS_COMPAT := $(word 2, $(SYSNAMES))
+ifeq ($(MACHTYPE_ATHENA_SYS),)
+    $(error MACHTYPE_ATHENA_SYS unset)
+endif
+ifeq ($(MACHTYPE_ATHENA_SYS_COMPAT),)
+    $(error MACHTYPE_ATHENA_SYS_COMPAT unset)
+endif
+
+.PHONY: all install clean
+
+all: machtype
+
+machtype.sh: ${OS_SCRIPT}
+	rm -f $@
+	sed -e 's/@ATHENA_MAJOR_VERSION@/${ATHENA_MAJOR_VERSION}/' \
+	    -e 's/@ATHENA_MINOR_VERSION@/${ATHENA_MINOR_VERSION}/' \
+	    -e 's/@ATHENA_SYS@/${MACHTYPE_ATHENA_SYS}/' \
+	    -e 's/@ATHENA_SYS_COMPAT@/${MACHTYPE_ATHENA_SYS_COMPAT}/' \
+	    ${OS_SCRIPT} > $@
+
+install:
+	${MKDIR_P} ${DESTDIR}${lbindir}
+	${MKDIR_P} ${DESTDIR}${mandir}/man1
+	${INSTALL} -m 755 machtype.sh ${DESTDIR}${lbindir}/machtype
+	${INSTALL} -m 444 machtype.1 ${DESTDIR}${mandir}/man1
+
+clean:
+	rm -f machtype.sh
diff --git a/Makefile.in b/Makefile.in
deleted file mode 100644
index 7974963..0000000
--- a/Makefile.in
+++ /dev/null
@@ -1,65 +0,0 @@
-# $Id: Makefile.in,v 1.3 2000-06-22 21:26:23 ghudson Exp $
-
-SHELL=/bin/sh
-VPATH=@srcdir@
-INSTALL=@INSTALL@
-INSTALL_PROGRAM=@INSTALL_PROGRAM@
-srcdir=@srcdir@
-top_srcdir=@top_srcdir@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-bindir=@bindir@
-lbindir=@lbindir@
-mandir=@mandir@
-
-CC=@CC@
-DEFS=@DEFS@
-CPPFLAGS=@CPPFLAGS@
-CFLAGS=@CFLAGS@ ${WARN_CFLAGS} ${ERROR_CFLAGS}
-LDFLAGS=@LDFLAGS@
-LIBS=@LIBS@
-ALL_CFLAGS=${CPPFLAGS} ${CFLAGS} ${DEFS}
-INSTALLFLAGS=@INSTALLFLAGS@
-
-# Used for creating the script, if that's what we're doing.
-ATHENA_MAJOR_VERSION=@ATHENA_MAJOR_VERSION@
-ATHENA_MINOR_VERSION=@ATHENA_MINOR_VERSION@
-ATHENA_SYS=@ATHENA_SYS@
-ATHENA_SYS_COMPAT=@ATHENA_SYS_COMPAT@
-
-OS_SCRIPT=@OS_SCRIPT@
-TARGET=@TARGET@
-OS_OBJS=@OS_OBJS@
-OBJS=machtype.o ${OS_OBJS}
-at=@
-
-all: ${TARGET}
-
-machtype: ${OBJS}
-	${CC} ${LDFLAGS} -o machtype ${OBJS} ${LIBS}
-
-.c.o:
-	${CC} -c ${ALL_CFLAGS} $<
-
-machtype.sh: ${OS_SCRIPT}
-	rm -f $@
-	sed -e 's/${at}ATHENA_MAJOR_VERSION${at}/${ATHENA_MAJOR_VERSION}/' \
-	    -e 's/${at}ATHENA_MINOR_VERSION${at}/${ATHENA_MINOR_VERSION}/' \
-	    -e 's/${at}ATHENA_SYS${at}/${ATHENA_SYS}/' \
-	    -e 's/${at}ATHENA_SYS_COMPAT${at}/${ATHENA_SYS_COMPAT}/' \
-	    ${OS_SCRIPT} > $@
-
-check:
-
-install:
-	${top_srcdir}/mkinstalldirs ${DESTDIR}${lbindir}
-	${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man1
-	${INSTALL_PROGRAM} ${INSTALLFLAGS} ${TARGET} \
-		${DESTDIR}${lbindir}/machtype
-	${INSTALL} -m 444 ${srcdir}/machtype.1 ${DESTDIR}${mandir}/man1
-
-clean:
-	rm -f ${TARGET} ${OBJS}
-
-distclean: clean
-	rm -f config.cache config.log config.status Makefile
diff --git a/configure.in b/configure.in
deleted file mode 100644
index 71ca0ec..0000000
--- a/configure.in
+++ /dev/null
@@ -1,59 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(machtype.c)
-
-test -z "$lbindir" && lbindir='${bindir}'
-AC_SUBST(lbindir)
-
-AC_PROG_CC
-AC_PROG_INSTALL
-
-AC_CANONICAL_HOST
-case $host_os in
-solaris*)
-	OS=solaris
-	AC_CHECK_FUNC(kvm_read, :, AC_CHECK_LIB(kvm, kvm_read))
-	AC_CHECK_FUNC(read_vtoc, :, AC_CHECK_LIB(adm, read_vtoc))
-	;;
-irix*)
-	OS=irix
-	;;
-linux*)
-	OS=linux
-	;;
-netbsd*)
-	OS=netbsd
-	;;
-esac
-
-AC_MSG_CHECKING(if machtype is a script)
-if test -r ${srcdir}/machtype_$OS.sh; then
-	AC_MSG_RESULT(yes)
-	TARGET=machtype.sh
-	OS_SCRIPT=${srcdir}/machtype_$OS.sh
-	INSTALLFLAGS="-m 555"
-else
-	AC_MSG_RESULT(no)
-	TARGET=machtype
-	OS_OBJS=machtype_$OS.o
-	INSTALLFLAGS="-m 2555 -o root -g sys"
-fi
-AC_SUBST(TARGET)
-AC_SUBST(OS_SCRIPT)
-AC_SUBST(OS_OBJS)
-AC_SUBST(INSTALLFLAGS)
-
-dnl Variables used to create script
-AC_SUBST(ATHENA_MAJOR_VERSION)
-AC_SUBST(ATHENA_MINOR_VERSION)
-AC_SUBST(ATHENA_SYS)
-AC_SUBST(ATHENA_SYS_COMPAT)
-
-dnl Variables used to compile from source
-AC_DEFINE_UNQUOTED(ATHMAJV, "$ATHENA_MAJOR_VERSION")
-AC_DEFINE_UNQUOTED(ATHMINV, "$ATHENA_MINOR_VERSION")
-AC_DEFINE_UNQUOTED(OSVERS, "`uname -r`")
-AC_DEFINE_UNQUOTED(OSNAME, "`uname -s`")
-AC_DEFINE_UNQUOTED(ATHSYS, "$ATHENA_SYS")
-AC_DEFINE_UNQUOTED(ATHSYSCOMPAT, "$ATHENA_SYS_COMPAT")
-
-AC_OUTPUT(Makefile)
diff --git a/debian/changelog b/debian/changelog
index eb65b07..2af21e7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+debathena-machtype (10.5) unstable; urgency=low
+
+  * Move logic for generating sysnames from debian/rules to
+    generate_sysnames.py
+  * Drop support for IRIX and Solaris from source package
+  * Update build-dependencies to reflect new build system
+  * Transition to dh7
+
+ -- Jonathan Reed <jdreed@mit.edu>  Sun, 22 Jun 2014 13:25:21 -0400
+
 debathena-machtype (10.4.1) unstable; urgency=low
 
   * Support Trusty (Trac: #1494)
diff --git a/debian/control b/debian/control
index fc3eb74..44e7cea 100644
--- a/debian/control
+++ b/debian/control
@@ -2,11 +2,15 @@ Source: debathena-machtype
 Section: debathena/net
 Priority: extra
 Maintainer: Debathena Project <debathena@mit.edu>
-Build-Depends: cdbs, debhelper, dh-buildinfo, autoconf, lsb-release, openafs-client
+Build-Depends: debhelper,
+ lsb-release,
+ python-minimal (>= 2.6~),
 Standards-Version: 3.9.3
 
 Package: debathena-machtype
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: openafs-client (>= 1.4.12+dfsg-3~),
+ ${shlibs:Depends},
+ ${misc:Depends}
 Description: Print Athena machine type to standard output
  Print CPU type and hardware configuration information.
diff --git a/debian/rules b/debian/rules
index 684701d..2d33f6a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,132 +1,4 @@
 #!/usr/bin/make -f
 
-DEB_AUTO_UPDATE_AUTOCONF = 2.50
-include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/autotools.mk
-
-ATHENA_MAJOR_VERSION = 10
-ATHENA_MINOR_VERSION = 0
-
-arch_sysnames = $(if $(filter amd64,$(DEB_BUILD_ARCH)),$(1) $(2),$(if $(filter i386,$(DEB_BUILD_ARCH)),$(2),$(error Unrecognized architecture $(DEB_BUILD_ARCH))))
-
-DISTRO := $(shell lsb_release --short --id)
-# Ubuntu releases have Debian versions, but not vice-versa
-DEBIAN_VERSION := $(shell dpkg-query --showformat='$${Version}' --show base-files)
-UBUNTU_VERSION := $(shell lsb_release --short --release)
-
-compare_debian_version = $(shell dpkg --compare-versions $(DEBIAN_VERSION) '>=' $(1) && echo y)
-compare_ubuntu_version = $(shell dpkg --compare-versions $(UBUNTU_VERSION) '>=' $(1) && echo y)
-
-SYS_COMPAT :=
-
-ifneq ($(call compare_debian_version,3.1),y)
-    $(error Debian version $(DEBIAN_VERSION) is too old)
-endif
-
-# The order of the following code is important, and ensures the correct
-# relative order of Debian and Ubuntu releases. (Note this is not quite
-# chronological order, e.g., Debian 6.0 released before Ubuntu 11.04,
-# but after its DebianImportFreeze.)
-
-ifeq ($(call compare_debian_version,8),y)
-    SYS_COMPAT += $(call arch_sysnames,amd64_deb80,i386_deb80)
-endif
-
-ifeq ($(DISTRO),Ubuntu)
-    ifeq ($(call compare_ubuntu_version,14.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1410,i386_ubuntu1410)
-    endif
-    ifeq ($(call compare_ubuntu_version,14.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1404,i386_ubuntu1404)
-    endif
-    ifeq ($(call compare_ubuntu_version,13.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1310,i386_ubuntu1310)
-    endif
-endif
-
-# Wheezy has had like 3 freezes, all before raring's DIF, so
-# who knows if this order is right.
-ifeq ($(DISTRO),Ubuntu)
-    ifeq ($(call compare_ubuntu_version,13.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1304,i386_ubuntu1304)
-    endif
-endif
-
-ifeq ($(call compare_debian_version,7),y)
-    SYS_COMPAT += $(call arch_sysnames,amd64_deb70,i386_deb70)
-endif
-
-ifeq ($(DISTRO),Ubuntu)
-    ifeq ($(call compare_ubuntu_version,12.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1210,i386_ubuntu1210)
-    endif
-    ifeq ($(call compare_ubuntu_version,12.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1204,i386_ubuntu1204)
-    endif
-    ifeq ($(call compare_ubuntu_version,11.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1110,i386_ubuntu1110)
-    endif
-endif
-
-ifeq ($(call compare_debian_version,6),y)
-    SYS_COMPAT += $(call arch_sysnames,amd64_deb60,i386_deb60)
-endif
-
-ifeq ($(DISTRO),Ubuntu)
-    ifeq ($(call compare_ubuntu_version,11.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1104,i386_ubuntu1104)
-    endif
-
-    ifeq ($(call compare_ubuntu_version,10.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1010,i386_ubuntu1010)
-    endif
-
-    ifeq ($(call compare_ubuntu_version,10.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu1004,i386_ubuntu1004)
-    endif
-
-    ifeq ($(call compare_ubuntu_version,9.10),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu910,i386_ubuntu910)
-    endif
-
-    ifeq ($(call compare_ubuntu_version,9.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu904,i386_ubuntu904)
-    endif
-endif
-
-ifeq ($(call compare_debian_version,4.0.4),y)
-    SYS_COMPAT += $(call arch_sysnames,amd64_deb50,i386_deb50)
-endif
-
-ifeq ($(DISTRO),Ubuntu)
-    ifeq ($(call compare_ubuntu_version,8.04),y)
-        SYS_COMPAT += $(call arch_sysnames,amd64_ubuntu804,i386_ubuntu804)
-    endif
-endif
-
-ifeq ($(call compare_debian_version,4),y)
-    SYS_COMPAT += $(call arch_sysnames,amd64_deb40,i386_deb40 i386_rhel4)
-endif
-
-ifneq ($(call compare_debian_version,7),y)
-    SYS_COMPAT += i386_rhel3 i386_linux24
-endif
-
-OPENAFS_VERSION := $(shell dpkg-query --showformat='$${Version}' --show openafs-client)
-MAX_SYSNAMES_PLUS_ONE := $(if $(shell dpkg --compare-versions $(OPENAFS_VERSION) '>=' '1.4.12+dfsg-3~' && echo y),33,17)
-
-ifneq ($(word $(MAX_SYSNAMES_PLUS_ONE),$(SYS_COMPAT)),)
-    $(error Too many sysnames: $(SYSNAME_COMPAT))
-endif
-
-ATHENA_SYS := $(word 1, $(SYS_COMPAT))
-ATHENA_SYS_COMPAT := $(patsubst %:,%,$(subst : ,:,$(patsubst %,%:,$(wordlist 2, $(words $(SYS_COMPAT)), $(SYS_COMPAT)))))
-
-DEB_CONFIGURE_EXTRA_FLAGS += lbindir=/bin \
-	ATHENA_SYS=$(ATHENA_SYS) \
-	ATHENA_SYS_COMPAT=$(ATHENA_SYS_COMPAT) \
-	ATHENA_MAJOR_VERSION=$(ATHENA_MAJOR_VERSION) \
-	ATHENA_MINOR_VERSION=$(ATHENA_MINOR_VERSION)
-
-clean::
-	rm -f configure
+%:
+	dh $@
diff --git a/generate_sysnames.py b/generate_sysnames.py
new file mode 100755
index 0000000..1fd9eef
--- /dev/null
+++ b/generate_sysnames.py
@@ -0,0 +1,158 @@
+#!/usr/bin/python
+#
+# Attempt to generate the sysname and compat list for this
+# architecture and distribution.  Print the sysname and
+# a colon-separated syscompat list to stdout.
+
+from collections import defaultdict
+import itertools
+import os
+import re
+import subprocess
+import sys
+
+# Default architectures, if not specified in the distro definition
+DEFAULT_ARCHES = ('i386', 'amd64')
+
+# A dictionary mapping an architecture to a list of architectures
+# it is compatible with
+COMPAT_ARCHES = defaultdict(list,
+                            {'amd64': ['i386'],
+                             })
+
+def fail(*args):
+    """Exit and display an error gracefully"""
+    for a in args:
+        print >>sys.stderr, os.path.basename(sys.argv[0]) + ':', a
+    sys.exit(1)
+
+def run(*args):
+    """Run a command and its arguments and return the output or fail"""
+    try:
+        return subprocess.check_output(args,
+                                       shell=False,
+                                       stderr=subprocess.STDOUT).strip()
+    except subprocess.CalledProcessError as e:
+        fail("Command failed: ", args, "Output:", e.output)
+
+IS_UBUNTU = os.getenv('OVERRIDE_MACHTYPE_LSB_ID',
+                      run('lsb_release', '--short','--id')).lower() == "ubuntu"
+DEBIAN_VERSION = os.getenv('OVERRIDE_MACHTYPE_DEB_VERSION',
+                           run('dpkg-query',
+                               '--showformat=${Version}',
+                               '--show',
+                               'base-files'))
+UBUNTU_VERSION = os.getenv('OVERRIDE_MACHTYPE_UBUNTU_VERSION',
+                           run('lsb_release',
+                               '--short',
+                               '--release'))
+ARCH = os.getenv('OVERRIDE_MACHTYPE_ARCH',
+                 run('dpkg-architecture',
+                     '-qDEB_BUILD_ARCH'))
+
+MAX_SYSNAMES = 32
+
+# If you use unicode version strings, I hate you
+digits = re.compile("[^0-9]")
+
+def archlist(arch):
+    return [arch] + COMPAT_ARCHES[arch]
+
+def compare_versions(ver1, op, ver2):
+    assert ver1 is not None and ver2 is not None and \
+        op in ('lt', 'le', 'eq', 'ne', 'ge', 'gt')
+    return subprocess.call(['dpkg', '--compare-versions',
+                            ver1, op, ver2], shell=False) == 0
+
+class Distro(object):
+    def __init__(self, version, **kwargs):
+        self.version = version
+        self.vercmp = os.uname()[2]
+        self.arches = kwargs.get('arches', DEFAULT_ARCHES)
+        self.sysver = digits.sub('', kwargs.get('sysver', version))
+        self.sysprefix = kwargs.get('sysprefix', 'linux')
+
+    def suitable(self):
+        if ARCH not in self.arches:
+            return False
+        if not compare_versions(self.vercmp, 'ge', self.version):
+            return False
+        if not IS_UBUNTU and isinstance(self, Ubuntu):
+            return False
+        return True
+
+    def sysnames(self):
+        rv = []
+        for a in archlist(ARCH):
+            if a in self.arches:
+                rv.append("{a}_{d}{v}".format(a=a,
+                                              d=self.sysprefix,
+                                              v=self.sysver))
+        return rv
+
+class Debian(Distro):
+    def __init__(self, version, **kwargs):
+        assert 'sysprefix' not in kwargs
+        super(Debian, self).__init__(version, sysprefix='deb', **kwargs)
+        self.vercmp = DEBIAN_VERSION
+
+class Ubuntu(Distro):
+    def __init__(self, version, **kwargs):
+        assert 'sysprefix' not in kwargs
+        super(Ubuntu, self).__init__(version, sysprefix='ubuntu', **kwargs)
+        self.vercmp = UBUNTU_VERSION
+
+# The master distro order
+# Update this when a new release comes online
+distros = [Ubuntu('14.04'),
+           Ubuntu('13.10'), Ubuntu('13.04'),
+           Debian('7.0', arches=DEFAULT_ARCHES + ('armel',)),
+           Ubuntu('12.10'), Ubuntu('12.04'),
+           Ubuntu('11.10'),
+           Debian('6.0'),
+           Ubuntu('11.04'),
+           Ubuntu('10.10'), Ubuntu('10.04'),
+           Ubuntu('9.10'),  Ubuntu('9.04'),
+           Debian('4.0.4', sysver='5.0'),
+           Ubuntu('8.04'),
+           Debian('4.0')]
+
+print >>sys.stderr, "Using values: Debian: {0}, {1}, Arch: {2}".format(
+    DEBIAN_VERSION,
+    "Ubuntu: {0}".format(UBUNTU_VERSION) if IS_UBUNTU else "(not Ubuntu)",
+    ARCH)
+
+if not compare_versions(DEBIAN_VERSION, 'ge', '3.1'):
+    fail("Go find an operating system released in 2008 or later.")
+
+sysnames = list(
+    itertools.chain(*[d.sysnames() for d in distros if d.suitable()]))
+
+if len(sysnames) < len(archlist(ARCH)):
+    fail("Insufficient number of sysnames, cannot proceed.",
+         "sysnames: {0}".format(sysnames))
+
+if len(sysnames) > MAX_SYSNAMES:
+    fail("Sysname list too long")
+
+sysname = sysnames.pop(0)
+sysnames += ['i386_rhel4']
+
+if not compare_versions(DEBIAN_VERSION, 'ge', '7.0'):
+    sysnames += ['i386_rhel3', 'i386_linux24']
+
+if IS_UBUNTU and (Ubuntu(UBUNTU_VERSION).sysnames()[0] != sysname):
+    fail("Sysname mismatch -- is this a new release?",
+         "{0} != {1}".format(Ubuntu(UBUNTU_VERSION).sysnames()[0], sysname))
+elif not IS_UBUNTU:
+    # We only compare major versions.  This is a hack.
+    deb_ver_compare = "{0:.1f}".format(int(DEBIAN_VERSION.split('.')[0]))
+    if Debian(deb_ver_compare).sysnames()[0] != sysname:
+        fail("Sysname mismatch -- is this a new release?",
+             "{0} != {1}".format(Debian(deb_ver_compare).sysnames()[0],
+                                 sysname))
+
+print "{sysname} {syscompat}".format(
+    sysname=sysname.strip(),
+    syscompat=':'.join([x.strip() for x in sysnames]))
+sys.exit(0)
diff --git a/machtype.c b/machtype.c
deleted file mode 100644
index 55a3c6d..0000000
--- a/machtype.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- *  Machtype: determine machine type & display type
- *
- * RCS Info
- *    $Id: machtype.c,v 1.4 2002-03-21 04:24:55 ghudson Exp $
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "machtype.h"
-
-extern char *optarg;
-extern int optind;
-
-void usage(char *name);
-
-int main(int argc, char *argv[])
-{
-  int i;
-  int cpuflg = 0, dpyflg = 0, raflg = 0, memflg = 0;
-  int doathenaV = 0;
-  int dosyspV = 0;
-  int dolocalV = 0;
-  int dobosN = 0;
-  int dobosV = 0;
-  int dosysnam = 0;
-  int dosyscompatnam = 0;
-  int verbose = 0;
-  FILE *f;
-  char *progname, *cp;
-
-  progname = argv[0];
-  cp = strrchr(progname, '/');
-  if (cp != NULL)
-    progname = cp+1;
-
-  while ((i = getopt(argc, argv, "cdrMALPNESCv")) != EOF)
-    {
-      switch (i)
-	{
-	case 'c':
-	  cpuflg = 1;
-	  break;
-	case 'd':
-	  dpyflg = 1;
-	  break;
-	case 'r':
-	  raflg = 1;
-	  break;
-	case 'M':
-	  memflg = 1;
-	  break;
-	case 'A':
-	  doathenaV = 1;
-	  break;
-	case 'L':
-	  dolocalV = 1;
-	  break;
-	case 'P':
-	  dosyspV = 1;
-	  break;
-	case 'N':
-	  dobosN = 1;
-	  break;
-	case 'E':
-	  dobosV = 1;
-	  break;
-	case 'S':
-	  dosysnam = 1;
-	  break;
-	case 'C':
-	  dosyscompatnam = 1;
-	  break;
-	case 'v':
-	  verbose++;
-	  break;
-	default:
-	  usage(progname);
-	}
-    }
-  if (argv[optind] != NULL)
-    usage(progname);
-
-  if (!(cpuflg || dpyflg || raflg || memflg || doathenaV || dolocalV ||
-	dosyspV || dobosN || dobosV || dosysnam || dosyscompatnam))
-    {
-      do_machtype();
-      exit(0);
-    }
-
-  /* Print out version of Athena machtype compiled against */
-  if (doathenaV)
-    {
-      if (verbose)
-	fputs("Machtype version: ", stdout);
-      printf("%s.%s\n", ATHMAJV, ATHMINV);
-    }
-
-    /* Print out version of attached packs */
-    if (dosyspV)
-      {
-	char buf[256], *rvd_version, *p;
-	if ((f = fopen("/srvd/.rvdinfo","r")) == NULL)
-	    puts("Syspack information unavailable.");
-	else
-	  {
-	    fgets(buf, sizeof(buf), f);
-	    fclose(f);
-	    /* If it is verbose, give the whole line, else just the vers # */
-	    if (verbose)
-		fputs(buf, stdout);
-	    else
-	      {
-		p = strchr(buf,' '); /* skip "Athena" */
-		p = strchr(p+1,' '); /* skip "RVD" */
-		p = strchr(p+1,' '); /* Skip machtype */
-		p = strchr(p+1,' '); /* skip "version" */
-		rvd_version = p+1;
-		p = strchr(rvd_version,' ');
-		*p = '\0';
-		puts(rvd_version);
-	      }
-	  }
-      }
-
-  /* Print out local version from /etc/athena/version */
-  if (dolocalV)
-    {
-      char buf[256], *loc_version, *p;
-      if ((f = fopen("/etc/athena/version","r")) == NULL)
-	  puts("Local version information unavailable.");
-      else
-	{
-	  while (fgets(buf, sizeof(buf), f) != NULL)
-	    ;
-	  fclose(f);
-	  if (verbose)
-	      fputs(buf, stdout);
-	  else
-	    {
-	      p = strchr(buf,' '); /* skip "Athena" */
-	      p = strchr(p+1,' '); /* skip "Workstation/Server" */
-	      p = strchr(p+1,' '); /* Skip machtype */
-	      p = strchr(p+1,' '); /* skip "version" */
-	      loc_version = p+1;
-	      p = strchr(loc_version,' ');
-	      *p = '\0';
-	      puts(loc_version);
-	    }
-	}
-    }
-
-  /* Print out vendor OS name */
-  if (dobosN)
-    {
-      if (verbose)
-	puts(OSNAME " " OSVERS);
-      else
-	puts(OSNAME);
-    }
-
-  /* Print out vendor OS version */
-  if (dobosV)
-    puts(OSVERS);
-
-  /* Print out Athena System name */
-  if (dosysnam)
-    puts(ATHSYS);
-
-  /* Print out compatible Athena System names */
-  if (dosyscompatnam)
-    puts(ATHSYSCOMPAT);
-
-  if (cpuflg)
-    do_cpu(verbose);
-  if (dpyflg)
-    do_dpy(verbose);
-  if (raflg)
-    do_disk(verbose);
-  if (memflg)
-    do_memory(verbose);
-  exit(0);
-}
-
-void usage(char *name)
-{
-  fprintf(stderr, "usage: %s [-v] [-c] [-d] [-r] [-E] [-N] [-M]\n", name);
-  fprintf(stderr, "             [-A] [-L] [-P] [-S] [-C]\n");
-  exit(1);
-}
diff --git a/machtype.h b/machtype.h
deleted file mode 100644
index 823e168..0000000
--- a/machtype.h
+++ /dev/null
@@ -1,5 +0,0 @@
-void do_machtype(void);
-void do_cpu(int verbose);
-void do_dpy(int verbose);
-void do_disk(int verbose);
-void do_memory(int verbose);
diff --git a/machtype_irix.c b/machtype_irix.c
deleted file mode 100644
index 38010a3..0000000
--- a/machtype_irix.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- *  Machtype: determine machine type & display type
- *
- * RCS Info
- *	$Id: machtype_irix.c,v 1.2 2002-04-10 03:44:36 ghudson Exp $
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/sysinfo.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include "machtype.h"
-
-#include <invent.h>
-#include <sys/sbd.h>
-void do_INV_SCSI(inventory_t *);
-void do_INV_SCSICONTROL(inventory_t *, int);
-void do_INV_DISK(inventory_t *, int);
-void do_INV_PROCESSOR(inventory_t *,int);
-void do_INV_GRAPHICS(inventory_t *);
-void do_INV_CAM(inventory_t *);
-void do_INV_CPUCHIP(inventory_t *);
-
-void do_machtype(void)
-{
-  puts("sgi");
-}
-
-void do_cpu(int verbose)
-{
-  inventory_t *inv;
-  setinvent();
-  inv = getinvent();
-  while (inv) {
-    if (inv->inv_class == INV_PROCESSOR) {
-      do_INV_PROCESSOR(inv, verbose);
-    }
-    inv = getinvent();
-  }
-}
-
-void do_INV_CPUCHIP(inventory_t* i)
-{
-  char* pu_short = (i->inv_type == INV_CPUCHIP)?"CPU":"FPU";
-  char* pu_long = (i->inv_type == INV_CPUCHIP)?
-    "Processor Chip":"Floating Point Coprocessor";
-  int chip = (i->inv_state & C0_IMPMASK) >> C0_IMPSHIFT;
-  int major = (i->inv_state & C0_MAJREVMASK) >> C0_MAJREVSHIFT;
-  int minor = (i->inv_state & C0_MINREVMASK) >> C0_MINREVSHIFT;
-  char* s_chip = 0;
-  switch(chip)
-    {
-    case C0_IMP_R2000:
-      if (major >= C0_MAJREVMIN_R2000A)
-	s_chip = "R2000A";
-      else
-	s_chip = "R2000";
-      break;
-    case C0_IMP_R2000A:
-      if (major >= C0_MAJREVMIN_R3000A)
-	s_chip = "R3000A";
-      else if (major >= C0_MAJREVMIN_R3000)
-	s_chip = "R3000";
-      else
-	s_chip = "R2000A";
-      break;
-    case C0_IMP_R6000:
-      s_chip = "R6000";
-      break;
-    case C0_IMP_R4000:
-      if (major >= C0_MAJREVMIN_R4400)
-	s_chip = "R4400";
-      else
-	s_chip = "R4000";
-      break;
-    case C0_IMP_R6000A:
-      s_chip = "R6000A";
-      break;
-    case C0_IMP_R10000:
-      s_chip = "R10000";
-      break;
-    case C0_IMP_R8000:
-      s_chip = "R8000";
-      break;
-    case C0_IMP_R4600:
-      s_chip = "R4600";
-      break;
-    case C0_IMP_R4700:
-      s_chip = "R4700";
-      break;
-    case C0_IMP_R4650:
-      s_chip = "R4650";
-      break;
-    case C0_IMP_R5000:
-      s_chip = "R5000";
-      break;
-    default:
-      s_chip = 0;
-      break;
-    }
-  if (s_chip)
-    printf("%s: MIPS %s %s Revision: %d.%d\n", 
-	   pu_short, s_chip, pu_long, major, minor);
-  else
-    printf("%s: unknown (0x%x) %s Revision: %d.%d\n", 
-	   pu_short, chip, pu_long, major, minor);
-}
-
-void do_INV_PROCESSOR(inventory_t *i,int verbose)
-{
-  if (i->inv_type == INV_CPUBOARD )  {
-    switch (i->inv_state) {
-    case INV_IP19BOARD:
-      puts(verbose ? "SGI IP19": "IP19");
-      break;
-    case INV_IP20BOARD:
-      puts(verbose ? "SGI IP20": "IP20");
-      break;
-    case INV_IP21BOARD:
-      puts(verbose ? "SGI IP21": "IP21");
-      break;
-    case INV_IP22BOARD:
-      puts(verbose ? "SGI IP22": "IP22");
-      break;
-    case INV_IP25BOARD:
-      puts(verbose ? "SGI IP25": "IP25");
-      break;
-    case INV_IP26BOARD:
-      puts(verbose ? "SGI IP26": "IP26");
-      break;
-#ifdef INV_IP27BOARD
-    case INV_IP27BOARD:
-      puts(verbose ? "SGI IP27": "IP27");
-      break;
-#endif
-    case INV_IP28BOARD:
-      puts(verbose ? "SGI IP28": "IP28");
-      break;
-    case INV_IP30BOARD:
-      puts(verbose ? "SGI IP30": "IP30");
-      break;
-    case INV_IP32BOARD:
-      puts(verbose ? "SGI IP32": "IP32");
-      break;
-#ifdef INV_IP33BOARD
-    case INV_IP33BOARD:
-      puts(verbose ? "SGI IP33": "IP33");
-      break;
-#endif
-    case INV_IPMHSIMBOARD:
-      puts(verbose ? "SGI IPMHSIM": "IPMHSIM");
-      break;
-    default:
-      if(verbose)
-	printf("Unknown SGI type %d\n", i->inv_state);
-      else
-	puts("SGI???");
-    }
-  } else if (verbose) {
-    switch(i->inv_type) {
-    case INV_CPUCHIP:
-    case INV_FPUCHIP:
-      do_INV_CPUCHIP(i);
-    }
-  }
-}
-
-void do_dpy(int verbose)
-{
-  int status;
-  inventory_t *inv;
-  int done = 0;
-
-  if (verbose) {
-    fflush(stdout);
-    switch(fork()) {
-    case -1:
-      fprintf (stderr,
-	       "Don't know how to determine display type for this machine.\n");
-      return;
-    case 0:
-      if ((execlp("/usr/gfx/gfxinfo","gfxinfo",NULL) ) == -1 ) {
-	fprintf (stderr, 
-		 "Don't know how to determine display "
-		 "type for this machine.\n");
-	return;
-      }	
-    default:
-      wait(&status);
-      break;
-    } /* switch */
-    (void) setinvent();
-    inv = getinvent();
-    while ((inv != NULL) && !done) {
-      if ( inv->inv_class == INV_VIDEO) {
-	do_INV_CAM(inv);
-      }
-      inv = getinvent();
-    }
-  } else { /* not verbose */
-    (void) setinvent();
-    inv = getinvent();
-    while ((inv != NULL) && !done) {
-      if ( inv->inv_class == INV_GRAPHICS) {
-	do_INV_GRAPHICS(inv);
-      }
-      inv = getinvent();
-    }
-  } /* verbose */
-}
-
-void do_INV_GRAPHICS(inventory_t *i)
-{
-  switch(i->inv_type)
-    {
-    case INV_NEWPORT:
-      switch(i->inv_state)
-	{
-	case INV_NEWPORT_24:
-	  fprintf(stdout,"XL-24\n");
-	  break;
-	case INV_NEWPORT_XL:
-	  fprintf(stdout,"XL\n");
-	  break;
-	default:
-	  fprintf(stdout,"NG1\n");
-	  break;
-	}
-      break;
-    case INV_GR2:
-      /* an EXPRESS is an EXPRESS of course of course
-	 except when you are a GR3-XZ */
-      if ((i->inv_state & ~INV_GR2_INDY) == INV_GR2_ELAN )
-	fprintf(stdout,"GR3-XZ\n");
-      else
-	fprintf(stdout,"UNKNOWN video\n");
-      break;
-#ifdef INV_CRIME
-    case INV_CRIME:
-      fprintf(stdout, "CRM\n");
-      break;
-#endif
-    default:
-      fprintf(stdout,"UNKNOWN video\n");
-    }
-}
-
-void do_INV_CAM(inventory_t *i)
-{
-  if (i->inv_type == INV_VIDEO_VINO ) {
-    if (i->inv_state == INV_VINO_INDY_CAM ) {
-      fprintf(stdout,"\tIndy cam connected\n");
-    }
-  }
-}
-
-
-
-void do_disk(int verbose)
-{
-  inventory_t *inv;
-  int done=0;
-  (void) setinvent();
-  inv = getinvent();
-  while ((inv != NULL) && !done) {
-    if (inv->inv_class == INV_DISK) 
-      do_INV_DISK(inv, verbose);
-    else if (inv->inv_class == INV_SCSI)
-      do_INV_SCSI(inv);
-    inv = getinvent();
-  }
-}
-
-void do_INV_SCSI(inventory_t *i)
-{
-  if (i->inv_type == INV_CDROM) {
-    fprintf(stdout, "CDROM: unit %d, on SCSI controller %d\n",
-	    (int) i->inv_unit, (int) i->inv_controller);
-  } else {
-    fprintf(stdout, "Unknown type %d:unit %d, on SCSI controller %d\n",
-	    i->inv_type, (int) i->inv_unit, (int) i->inv_controller);
-  }
-}
-
-void do_INV_DISK(inventory_t *i, int verbose)
-{
-  switch (i->inv_type)
-    {
-    case INV_SCSIDRIVE:
-      printf("Disk drive: unit %u, on SCSI controller %u\n",
-	     (unsigned int) i->inv_unit, (unsigned int) i->inv_controller);
-      break;
-
-    case INV_SCSIFLOPPY:
-      printf("Floppy drive: unit %u, on SCSI controller %u\n",
-	     (unsigned int) i->inv_unit, (unsigned int) i->inv_controller);
-      break;
-
-    case INV_SCSICONTROL:
-    case INV_GIO_SCSICONTROL:
-#ifdef INV_PCI_SCSICONTROL
-    case INV_PCI_SCSICONTROL:
-#endif
-      do_INV_SCSICONTROL(i, verbose);
-      break;
-
-    default:
-      printf("Unknown type %u: unit %u, on SCSI controller %u\n",
-	     (unsigned int) i->inv_type, (unsigned int) i->inv_unit,
-	     (unsigned int) i->inv_controller);
-      break;
-    }
-}
-
-void do_INV_SCSICONTROL(inventory_t *i, int verbose)
-{
-  /* Only display SCSI controller info when verbose */
-  if (!verbose)
-    return;
-
-  switch (i->inv_type)
-    {
-    case INV_SCSICONTROL:
-      printf("Integral");
-      break;
-    case INV_GIO_SCSICONTROL:
-      printf("GIO");
-      break;
-#ifdef INV_PCI_SCSICONTROL
-    case INV_PCI_SCSICONTROL:
-      printf("PCI");
-      break;
-#endif
-    default:
-      printf("Unknown");
-      break;
-    }
-
-  printf(" SCSI controller %u: Version ", (unsigned int) i->inv_controller);
-
-  switch (i->inv_state)
-    {
-    case INV_WD93:
-      printf("WD 33C93");
-      break;
-
-    case INV_WD93A:
-      printf("WD 33C93A");
-      break;
-
-    case INV_WD93B:
-      printf("WD 33C93B");
-      break;
-
-    case INV_WD95A:
-      printf("WD 33C95A");
-      break;
-
-    case INV_SCIP95:
-      printf("SCIP w/WD 33C95A");
-      break;
-
-#ifdef INV_ADP7880
-    case INV_ADP7880:
-      printf("ADAPTEC 7880");
-      break;
-#endif
-
-    default:
-      printf("Unknown");
-      break;
-    }
-
-  if (i->inv_unit)
-    printf(", rev. %X", (unsigned int) i->inv_unit);
-
-  putchar('\n');
-}
-
-
-#define MEG (1024*1024)
-
-void do_memory(int verbose)
-{
-  inventory_t *inv;
-  int mem = 0;
-  int mem_mb = 0;
-  setinvent();
-  inv = getinvent();
-  while (inv) {
-    if (inv->inv_class == INV_MEMORY) {
-      switch(inv->inv_type) {
-      case INV_MAIN:
-	mem = inv->inv_state;
-	break;
-      case INV_MAIN_MB:
-	mem_mb = inv->inv_state;
-	break;
-      }
-    }
-    inv = getinvent();
-  }
-  if (!mem && !mem_mb) {
-    fprintf(stderr, "can't find main memory in inventory\n");
-    exit(2);
-  }
-  if (verbose)
-    printf("%d (%d M) total\n", mem?mem:(mem_mb * MEG), 
-	   mem_mb?mem_mb:(mem/MEG));
-  else
-    printf("%d\n", mem);
-}
diff --git a/machtype_solaris.c b/machtype_solaris.c
deleted file mode 100644
index 7660296..0000000
--- a/machtype_solaris.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- *  Machtype: determine machine type & display type
- *
- * RCS Info
- *    $Id: machtype_solaris.c,v 1.5 2002-03-21 04:35:51 ghudson Exp $
- */
-
-#define volatile 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <kvm.h>
-#include <nlist.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/cpu.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <sys/vtoc.h>
-/* OpenPROM stuff */
-#include <sys/promif.h>
-#include <sys/ddi.h>
-#include <sys/sunddi.h>
-#include <sys/ddi_impldefs.h>
-#include <sys/systeminfo.h>
-/* Frame buffer stuff */
-#include <sys/fbio.h>
-#include <errno.h>
-#include "machtype.h"
-
-void do_machtype(void)
-{
-    puts("sun4");
-}
-
-void do_cpu(int verbose)
-{
-  char            buf[BUFSIZ];
-
-  char*           cpustr;
-
-  /* read device name of the top node of the OpenPROM */
-
-  if (sysinfo(SI_PLATFORM, buf, BUFSIZ) < 0) {
-    fprintf(stderr, "Can't get CPU information\n");
-    exit(2);
-  }
-  buf[BUFSIZ-1] = '\0';
-
-  /* now, return a string identifying the CPU */
-
-  if (verbose) {
-    /* "verbose" returns the kernel information directly */
-    puts(buf);
-
-  } else {
-
-    /* skip the initial "SUNW," */
-    cpustr = strchr(buf, ',');
-    if (cpustr)
-      cpustr++;
-    else
-      cpustr = buf;
-
-    /* reformat the result to look like "SPARC/Classic" or "SPARC/5" */
-    if (! strncmp(cpustr, "SPARC", sizeof("SPARC")-1)) {
-      cpustr += sizeof("SPARC")-1;
-
-      if (! strncmp(cpustr, "station-", sizeof("station-")-1))
-	cpustr += sizeof("station-")-1;
-      else
-	if (! strcmp(cpustr, "classic")) /* backwards compat - cap classic */
-	  (*cpustr) = toupper(*cpustr);
-
-      printf("SPARC/%s\n", cpustr);
-
-    } else {
-      /* if it didn't start with "SPARC", just leave it be... */
-      puts(cpustr);
-    }
-  }
-
-  return;
-}
-
-void do_dpy(int verbose)
-{
-  int count;
-  char buf[1024], *p;
-
-  count = readlink("/dev/fb", buf, sizeof(buf) - 1);
-  if (count == -1) {
-    puts(verbose ? "unknown frame buffer" : "unknown");
-    return;
-  }
-  buf[count] = 0;
-  p = buf + count;
-  while (p > buf && isdigit((unsigned char)*(p - 1)))
-    *--p = 0;
-  p = strrchr(buf, ':');
-  if (!p) {
-    puts(verbose ? "unknown frame buffer" : "unknown");
-    return;
-  }
-  printf("%s%s\n", p + 1, verbose ? " frame buffer" : "");
-}
-
-void do_disk(int verbose)
-{
-  DIR *dp;
-  struct dirent *de;
-  char path[MAXPATHLEN];
-  const char *devdir = "/dev/rdsk";
-  char *cp;
-  int fd;
-  int devlen;			/* Length of device name, w/o partition */
-  struct vtoc vtoc;
-  
-  dp = opendir(devdir);
-  if (dp == NULL)
-    {
-      fprintf(stderr, "Cannot open %s: %s\n", devdir, strerror(errno));
-      exit(1);
-    }
-
-  while ((de = readdir(dp)) != NULL)
-    {
-      if ((!strcmp(de->d_name, ".")) || (!strcmp(de->d_name, "..")))
-	continue;
-
-      /* By convention partition (slice) 2 is the whole disk. */
-      cp = strrchr(de->d_name, 's');
-      if ((cp == NULL) || (strcmp(cp, "s2") != 0))
-	continue;
-      devlen = cp - de->d_name;		/* Get name length w/o partition */
-      sprintf(path, "%s/%s", devdir, de->d_name);
-      fd = open(path, O_RDONLY);
-      if (fd == -1)
-	continue;
-
-      if ((read_vtoc(fd, &vtoc) < 0) || (vtoc.v_sanity != VTOC_SANE))
-	{
-	  close(fd);
-	  continue;
-	}
-      close(fd);
-
-      if (!verbose)
-	{
-	  /* Strip geometry info from the label text. */
-	  cp = strchr(vtoc.v_asciilabel, ' ');
-	  if (cp)
-	    *cp = '\0';
-	}
-
-      printf("%.*s: %.*s\n",
-	     devlen, de->d_name,
-	     LEN_DKL_ASCII, vtoc.v_asciilabel);
-    }
-
-  closedir(dp);
-  return;
-}
-
-#define MEG (1024*1024)
-
-void do_memory(int verbose)
-{
-   int mem, nbpp;
-
-   nbpp = getpagesize() / 1024;
-   mem = sysconf(_SC_PHYS_PAGES);
-   if(verbose)
-      printf("%d (%d M) total\n", mem * nbpp, (mem * nbpp + 916) / 1024);
-   else
-      printf("%d\n", mem * nbpp + 916);
-   return;
-}
-

home help back first fref pref prev next nref lref last post