--- debathena-libathdir-10.0.2.orig/configure.ac
+++ debathena-libathdir-10.0.2/configure.ac
@@ -1,14 +1,57 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT([libathdir], [10.0.2])
-AC_CONFIG_SRCDIR([athdir.c])
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
 
+AC_PREREQ([2.67])
+AC_INIT([libathdir], [10.0.2], [debathena@mit.edu])
+AM_INIT_AUTOMAKE([foreign -Wall])
+AM_MAINTAINER_MODE([enable])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SRCDIR([src/athdir.c])
+AC_CONFIG_HEADERS([config.h])
+
+# Checks for programs.
 AC_PROG_CC
-AC_PROG_INSTALL
-AC_PROG_LIBTOOL
-AC_PROG_MKDIR_P
+# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+LT_INIT
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([stdlib.h string.h sys/param.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_FUNC_REALLOC
+AC_CHECK_FUNCS([strchr])
+
+# More stuff
+AS_IF([test x"$ATHENA_SYS" = x], [AC_MSG_ERROR([ATHENA_SYS must be set])])
+AC_DEFINE_UNQUOTED([ATHSYS], ["$ATHENA_SYS"], [Define the Athena System Version])
+
+AC_ARG_WITH([hosttype],
+    [AS_HELP_STRING([--with-hosttype],
+                    [machtype for compatibility])],
+    [
+	case $withval in
+	     linux)	withval='"linux"';;
+	     sun4)    	withval='"sun4"';;
+	     inbsd)	withval='"inbsd"';;
+	     yes)	withval='"linux"';;
+	     no)	withval=NULL;;
+	     *)		AC_MSG_ERROR([invalid hosttype specified]);;
+	esac
+	hosttype=$withval
+    ],
+    [hosttype='"linux"'])
+AC_DEFINE_UNQUOTED([HOSTTYPE], [$hosttype], [Define the type of the Athena System])
 
-AC_DEFINE_UNQUOTED([ATHSYS], ["$ATHENA_SYS"])
-AC_DEFINE_UNQUOTED([HOSTTYPE_$ATHENA_HOSTTYPE])
 
-AC_CONFIG_FILES([Makefile athdir.pc])
+AC_CONFIG_FILES([Makefile
+                 src/Makefile
+		 src/athdir.pc
+])
 AC_OUTPUT
--- debathena-libathdir-10.0.2.orig/COPYING
+++ debathena-libathdir-10.0.2/COPYING
@@ -0,0 +1,30 @@
+Copyright 1998 by the Massachusetts Institute of Technology.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+* Neither the name of the M.I.T nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
--- debathena-libathdir-10.0.2.orig/Makefile.am
+++ debathena-libathdir-10.0.2/Makefile.am
@@ -0,0 +1,3 @@
+ACLOCAL_AMFLAGS = --install -I m4
+SUBDIRS = src
+EXTRA_DIST = autogen.sh
--- debathena-libathdir-10.0.2.orig/autogen.sh
+++ debathena-libathdir-10.0.2/autogen.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec autoreconf -fi
--- debathena-libathdir-10.0.2.orig/debian/compat
+++ debathena-libathdir-10.0.2/debian/compat
@@ -0,0 +1 @@
+7
--- debathena-libathdir-10.0.2.orig/debian/changelog
+++ debathena-libathdir-10.0.2/debian/changelog
@@ -0,0 +1,85 @@
+debathena-libathdir (10.0.2-0debathena5) unstable; urgency=low
+
+  * Switch from control.in to control (Trac: #561)
+  * Bump Standards-Version to 3.9.3
+  * Bump compat level to 7
+  * Convert to debhelper 7
+
+ -- Jonathan Reed <jdreed@mit.edu>  Wed, 03 Apr 2013 14:01:52 -0400
+
+debathena-libathdir (10.0.2-0debathena4) unstable; urgency=low
+
+  * Do not permit builds unless both ATHENA_HOSTTYPE and ATHENA_SYS are
+    set (Trac: #1204)
+
+ -- Jonathan Reed <jdreed@mit.edu>  Thu, 16 Aug 2012 18:52:12 -0400
+
+debathena-libathdir (10.0.2-0debathena3) unstable; urgency=low
+
+  * Stop forcing SHELL to /bin/sh in Makefile.in, since this breaks
+    libtool 2.4, and letting configure pick the shell should work fine on
+    all platforms we care about
+
+ -- Jonathan Reed <jdreed@mit.edu>  Fri, 28 Oct 2011 09:46:09 -0400
+
+debathena-libathdir (10.0.2-0debathena2) unstable; urgency=low
+
+  * Generate aclocal.m4 ourselves instead of using DEB_AUTO_UPDATE_ACLOCAL
+    to avoid potential races between aclocal and autoconf.
+
+ -- Evan Broder <broder@mit.edu>  Tue, 04 May 2010 14:00:32 -0400
+
+debathena-libathdir (10.0.2-0debathena1) unstable; urgency=low
+
+  * Fix handling of LDFLAGS.
+  * Add a check to the rules file to make sure configure.ac's version
+    stays in sync with the changelog.
+
+ -- Evan Broder <broder@mit.edu>  Wed, 28 Apr 2010 22:48:24 -0400
+
+debathena-libathdir (10.0.1-0debathena1) unstable; urgency=low
+
+  * Update our autogoo for the 21st century.
+  * Generate aclocal.m4 ourselves instead of copying in the standard
+    Athena aclocal.m4. (Trac: #334)
+  * Build libathdir as a shared library. (Trac: #70)
+  * Ship a pkgconfig file for libathdir.
+  * Bump debhelper compatibility.
+  * Bump standards version.
+
+ -- Evan Broder <broder@mit.edu>  Wed, 28 Apr 2010 16:29:46 -0400
+
+debathena-libathdir (10.0.0-0debathena2) unstable; urgency=low
+
+  * Export ATHENA_SYS and ATHENA_HOSTTYPE at build time, to make sure that
+    athdir has the correct compile-time constants built-in. (Trac: #570)
+
+ -- Evan Broder <broder@mit.edu>  Wed, 28 Apr 2010 13:23:11 -0400
+
+debathena-libathdir (10.0.0-0debathena1) unstable; urgency=low
+
+  * Change DEB_AUTO_UPDATE_AUTOCONF to 2.50, not 1.
+  * Remove DEB_AUTO_UPDATE_DEBIAN_CONTROL.
+  * Change "Debian-Athena Project" to "Debathena Project".
+  * Remove debian/control from version control.
+  * Clean up debian/copyright.
+
+ -- Tim Abbott <tabbott@mit.edu>  Sat, 24 Jan 2009 15:23:36 -0500
+
+debathena-libathdir (9.4.0+cvs20050915-0debathena3) unstable; urgency=low
+
+  * Fix conflicts/replaces.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Mon, 06 Aug 2007 02:32:10 -0400
+
+debathena-libathdir (9.4.0+cvs20050915-0debathena2) unstable; urgency=low
+
+  * Section: debathena/libs.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Tue, 17 Jul 2007 06:33:48 -0400
+
+debathena-libathdir (9.4.0+cvs20050915-0debathena1) unstable; urgency=low
+
+  * Initial release.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Mon, 29 Jan 2007 23:57:37 -0500
--- debathena-libathdir-10.0.2.orig/debian/rules
+++ debathena-libathdir-10.0.2/debian/rules
@@ -0,0 +1,6 @@
+#!/usr/bin/make -f
+
+export ATHENA_SYS=$(shell machtype -S)
+
+%:
+	dh $@ --with autoreconf
--- debathena-libathdir-10.0.2.orig/debian/control
+++ debathena-libathdir-10.0.2/debian/control
@@ -0,0 +1,38 @@
+Source: debathena-libathdir
+Section: debathena/libs
+Priority: extra
+Maintainer: Debathena Project <debathena@mit.edu>
+Build-Depends: debhelper (>= 7), autotools-dev, dh-autoreconf, debathena-machtype
+Standards-Version: 3.9.3
+
+Package: debathena-libathdir0
+Section: debathena/libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: The Athena directory location library
+ A library to implement machine-specific directory location on Athena.
+ .
+ This package contains the shared athdir library.
+
+Package: debathena-libathdir0-dbg
+Section: debathena/debug
+Architecture: any
+Depends: debathena-libathdir0 (= ${binary:Version}),
+ ${shlibs:Depends}, ${misc:Depends}
+Description: The Athena directory location library with debugging symbols
+ A library to implement machine-specific directory location on Athena.
+ .
+ This package contains an unstripped shared library. It will be used
+ automatically by gdb for debugging libathdir-related issues.
+
+Package: debathena-libathdir-dev
+Section: debathena/libdevel
+Architecture: any
+Provides: libathdir-dev
+Conflicts: debathena-libathdir (<< 9.4)
+Replaces: debathena-libathdir (<< 9.4)
+Depends: debathena-libathdir0 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
+Description: Development files for the Athena directory location library
+ A library to implement machine-specific directory location on Athena.
+ .
+ This package contains headers and static libraries for development.
--- debathena-libathdir-10.0.2.orig/debian/copyright
+++ debathena-libathdir-10.0.2/debian/copyright
@@ -0,0 +1,23 @@
+This package was debianized as part of the Debathena Project
+<http://debathena.mit.edu/> of the MIT Student Information Processing
+Board.
+
+The Athena source code was obtained from the Athena SVN repository at
+<svn://debathena.mit.edu/athena/trunk>, and is licensed as follows:
+
+  Copyright © 1996 by the Massachusetts Institute of Technology.
+
+  Permission to use, copy, modify, and distribute this
+  software and its documentation for any purpose and without
+  fee is hereby granted, provided that the above copyright
+  notice appear in all copies and that both that copyright
+  notice and this permission notice appear in supporting
+  documentation, and that the name of M.I.T. not be used in
+  advertising or publicity pertaining to distribution of the
+  software without specific, written prior permission.
+  M.I.T. makes no representations about the suitability of
+  this software for any purpose.  It is provided "as is"
+  without express or implied warranty.
+
+The Debian packaging is Copyright © 2007-2008 Tim Abbott and Anders
+Kaseorg, and has the same license as the original software.
--- debathena-libathdir-10.0.2.orig/debian/debathena-libathdir0.install
+++ debathena-libathdir-10.0.2/debian/debathena-libathdir0.install
@@ -0,0 +1 @@
+usr/lib/libathdir.so.*
--- debathena-libathdir-10.0.2.orig/debian/debathena-libathdir-dev.install
+++ debathena-libathdir-10.0.2/debian/debathena-libathdir-dev.install
@@ -0,0 +1,5 @@
+usr/include
+usr/lib/libathdir.so
+usr/lib/libathdir.la
+usr/lib/libathdir.a
+usr/lib/pkgconfig
--- debathena-libathdir-10.0.2.orig/src/athdir.h
+++ debathena-libathdir-10.0.2/src/athdir.h
@@ -0,0 +1,50 @@
+/* $Id: athdir.h,v 1.1 1998-03-17 03:43:09 cfields Exp $ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ *   may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ATHDIR__H
+#define ATHDIR__H
+
+#define ATHDIR_SUPPRESSEDITORIALS	(1<<0)
+#define ATHDIR_SUPPRESSSEARCH		(1<<1)
+#define ATHDIR_MACHINEDEPENDENT		(1<<2)
+#define ATHDIR_MACHINEINDEPENDENT	(1<<3)
+#define ATHDIR_LISTSEARCHDIRECTORIES	(1<<4)
+
+char **athdir_get_paths(char *base_path, char *type,
+			char *sys, char **syscompat, char *machine,
+			char *aux, int flags);
+void athdir_free_paths(char **paths);
+int athdir_native(char *what, char *sys);
+
+#endif
--- debathena-libathdir-10.0.2.orig/src/athdir.pc.in
+++ debathena-libathdir-10.0.2/src/athdir.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: athdir
+Description: The Athena directory location library
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lathdir
+Cflags: -I${includedir}
--- debathena-libathdir-10.0.2.orig/src/stringlist.c
+++ debathena-libathdir-10.0.2/src/stringlist.c
@@ -0,0 +1,207 @@
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ *   may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This file implements basic string array functions and structures
+ * to be used by software using the athdir library.
+ */
+
+static const char rcsid[] = "$Id: stringlist.c,v 1.2 1999-10-23 19:28:46 danw Exp $";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "stringlist.h"
+
+#define CHUNKSIZE 10
+
+/* athdir__add_string
+ *   Add a copy of "string" to "list," and to the front of "list" if
+ *   "front" is false. If "list" is NULL, initialize it as well.
+ */
+int athdir__add_string(string_list **list, char *string, int front)
+{
+  char *newstring;
+  int index;
+
+  /* To add nothing, do nothing. */
+  if (string == NULL)
+    return 0;
+
+  if (list == NULL)
+    return -1;
+
+ /* Initialize the structure if it's NULL. */
+  if (*list == NULL)
+    {
+      *list = malloc(sizeof(string_list));
+
+      if (*list == NULL)
+	return -1;
+
+      (*list)->strings = malloc(CHUNKSIZE * sizeof(char *));
+      if ((*list)->strings == NULL)
+	{
+	  free(*list);
+	  *list = NULL;
+	  return -1;
+	}
+
+      (*list)->alloced = CHUNKSIZE;
+      (*list)->length = 0;
+      (*list)->strings[0] = NULL;
+    }
+
+  /* Allocate more list space if the list is full. */
+  if ((*list)->alloced == (*list)->length + 1) /* must be NULL terminated */
+    {
+      (*list)->strings = realloc((*list)->strings,
+			      ((*list)->alloced + CHUNKSIZE) * sizeof(char *));
+      if ((*list)->strings == NULL)
+	{
+	  free(*list);
+	  return -1;
+	}
+      (*list)->alloced += CHUNKSIZE;
+    }
+
+  /* Make our own copy of the string. */
+  newstring = malloc(strlen(string) + 1);
+  if (newstring == NULL)
+    return -1;
+  strcpy(newstring, string);
+
+  /* Add the string to the list. */
+  if (front)
+    {
+      (*list)->length++;
+      for (index = (*list)->length; index > 0; index--)
+	(*list)->strings[index] = (*list)->strings[index - 1];
+      (*list)->strings[0] = newstring;
+    }
+  else
+    {
+      (*list)->strings[(*list)->length] = newstring;
+      (*list)->length++;
+      (*list)->strings[(*list)->length] = NULL;
+    }
+
+  return 0;
+}
+
+/* athdir__make_string_array
+ *   Returns a NULL terminated array of strings (or NULL if the list
+ *   is empty) while freeing the surrounding structure. free_string_array
+ *   the array when finished.
+ */
+char **athdir__make_string_array(string_list **list)
+{
+  char **strings = NULL;
+
+  if (list != NULL && *list != NULL)
+    {
+      if ((*list)->strings[0] != NULL)
+	strings = (*list)->strings;
+      else
+	free((*list)->strings);
+
+      free(*list);
+      *list = NULL;
+    }
+
+  return strings;
+}
+
+/* athdir__free_string_array
+ *   Frees a string array generated by athdir__make_string_array.
+ */
+void athdir__free_string_array(char **array)
+{
+  char **ptr;
+
+  if (array != NULL)
+    {
+      for (ptr = array; *ptr != NULL; ptr++)
+	free(*ptr);
+
+      free(array);
+    }
+}
+
+/* athdir__parse_string
+ *   Parse "string" using "sep" as a separator into separate strings, adding
+ *   adding each substring to the end of "list." Nondestructive to string,
+ *   doesn't point to string.
+ */
+int athdir__parse_string(string_list **list, char *string, char sep)
+{
+  char *ptr, *sep_ptr;
+  char *value;
+  int length;
+
+  if (string != NULL)
+    {
+      /* Allocate a buffer big enough for any substring of string. */
+      value = malloc(strlen(string) + 1);
+      if (value == NULL)
+	return -1;
+
+      ptr = string;
+      while (*ptr != '\0')
+	{
+	  /* Figure out the length of this substring. */
+	  sep_ptr = strchr(ptr, sep);
+	  if (sep_ptr == NULL)
+	    length = strlen(ptr);
+	  else
+	    length = sep_ptr - ptr;
+
+	  /* Make a copy to be copied by athdir__add_string. */
+	  strncpy(value, ptr, length);
+	  value[length] = '\0';
+
+	  if (athdir__add_string(list, value, 0))
+	    {
+	      free(value);
+	      return -1;
+	    }
+
+	  ptr += length;
+	  if (*ptr == sep)
+	    ptr++;
+	}
+
+      free(value);
+    }
+
+  return 0;
+}
--- debathena-libathdir-10.0.2.orig/src/stringlist.h
+++ debathena-libathdir-10.0.2/src/stringlist.h
@@ -0,0 +1,43 @@
+/* $Id: stringlist.h,v 1.1 1998-03-17 03:44:04 cfields Exp $ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ *   may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+typedef struct {
+  int alloced, length;
+  char **strings;
+} string_list;
+
+int athdir__add_string(string_list **list, char *string, int front);
+int athdir__parse_string(string_list **list, char *string, char sep);
+char **athdir__make_string_array(string_list **list);
+void athdir__free_string_array(char **array);
--- debathena-libathdir-10.0.2.orig/src/Makefile.am
+++ debathena-libathdir-10.0.2/src/Makefile.am
@@ -0,0 +1,11 @@
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = athdir.pc
+
+include_HEADERS = athdir.h
+
+lib_LTLIBRARIES = libathdir.la
+libathdir_la_SOURCES = \
+        athdir.c \
+	athdir.h \
+	stringlist.c \
+	stringlist.h
--- debathena-libathdir-10.0.2.orig/src/athdir.c
+++ debathena-libathdir-10.0.2/src/athdir.c
@@ -0,0 +1,375 @@
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ *   may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This file implements the main athdir library calls. */
+
+static const char rcsid[] = "$Id: athdir.c,v 1.6 1999-10-23 19:28:46 danw Exp $";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "athdir.h"
+#include "stringlist.h"
+#include "config.h"
+
+/* HOSTTYPE should always be defined when we get here, because
+   configure is responsible for getting it to us. Nonetheless, this
+   codepath is beign left in for legacy reasons, like the rest of this
+   entire file... */
+#ifdef HOSTTYPE
+char *hosttype = HOSTTYPE;
+#else
+char *hosttype = NULL;
+#endif
+
+/* Definition of known conventions and what flavors they are.  */
+
+typedef struct {
+  char *name;
+  int flavor;
+} Convention;
+
+#define ARCHflavor (1<<0)
+#define MACHflavor (1<<1)
+#define PLAINflavor (1<<2)
+#define SYSflavor (1<<3)
+#define DEPENDENTflavor (1<<8)
+#define INDEPENDENTflavor (1<<9)
+#define ATSYSflag (1<<16)
+
+#define NUMCONVENTIONS 5
+
+Convention conventions[NUMCONVENTIONS] = {
+  { NULL,		ARCHflavor | MACHflavor | PLAINflavor |
+      			DEPENDENTflavor | INDEPENDENTflavor },
+  { "%p/arch/%s/%t",	ARCHflavor | DEPENDENTflavor | ATSYSflag },
+  { "%p/%s/%t",		SYSflavor | DEPENDENTflavor | ATSYSflag },
+  { "%p/%m%t",		MACHflavor | DEPENDENTflavor },
+  { "%p/%t",		PLAINflavor | INDEPENDENTflavor }
+};
+
+/* Editorial tagging for what conventions are acceptable or
+ * preferable for what types.
+ */
+
+typedef struct {
+  char *type;
+  int allowedFlavors;	/* searching parameters */
+  int preferredFlavor;	/* creating paramaters */
+} Editorial;
+
+Editorial editorials[] = {
+  { "bin",	ARCHflavor | SYSflavor | MACHflavor,	DEPENDENTflavor },
+  { "lib",	ARCHflavor | SYSflavor | MACHflavor,	DEPENDENTflavor },
+  { "etc",	ARCHflavor | SYSflavor | MACHflavor,	DEPENDENTflavor },
+  { "man",	ARCHflavor | PLAINflavor,		INDEPENDENTflavor },
+  { "include",	ARCHflavor | PLAINflavor,		INDEPENDENTflavor },
+  { NULL,	ARCHflavor | PLAINflavor,		DEPENDENTflavor }
+};
+
+/* path = template(dir, type, sys, machine)
+ *	%p = path (dir)
+ *	%t = type
+ *	%s = sys
+ *	%m = machine
+ * %foo is inserted if the corresponding string is NULL.
+ * If this happens, expand returns 1 (not a valid path).
+ * If expand runs out of memory, it returns -1 (and path is NULL).
+ * Otherwise, expand returns 0.
+ */
+static int expand(char **path, char *template, char *dir,
+	   char *type, char *sys, char *machine)
+{
+  char *src, *dst, *oldpath;
+  int somenull = 0, size;
+
+  src = template;
+  size = strlen(template) + 1;
+  dst = oldpath = *path = malloc(size);
+  *dst = '\0';
+
+  while (*src != '\0')
+    {
+      if (*src != '%')
+	*dst++ = *src++;
+      else
+	{
+
+#define copystring(casec, cases, string)			\
+	case casec:						\
+	  src++;						\
+	  if (string)						\
+	    {							\
+	      *path = realloc(*path, size += strlen(string));	\
+	      if (!*path)					\
+		return -1;					\
+	      dst = *path + (dst - oldpath);			\
+	      oldpath = *path;					\
+	      strcpy(dst, string);				\
+	      dst += strlen(string);				\
+	    }							\
+	  else							\
+	    {							\
+	      strcpy(dst, cases);				\
+	      dst += 2;						\
+	      somenull = 1;					\
+	    }							\
+	  break;
+
+	  src++;
+	  switch(*src)
+	    {
+	      copystring('p', "%p", dir);
+	      copystring('t', "%t", type);
+	      copystring('s', "%s", sys);
+	      copystring('m', "%m", machine);
+
+#undef copystring
+
+	    case '\0':
+	      break;
+
+	    default:
+	      *dst++ = '%';
+	      *dst++ = *src++;
+	      break;
+	    }
+	}
+    }
+
+  *dst = '\0';
+  return somenull;
+}
+
+static int template_flavor(char *template)
+{
+  int flavor = ARCHflavor | MACHflavor | PLAINflavor
+    | DEPENDENTflavor | INDEPENDENTflavor;
+  char *ptr;
+
+  if (template == NULL)
+    return 0;
+
+  for (ptr = strchr(template, '%'); ptr != NULL; ptr = strchr(ptr + 1, '%'))
+    {
+      if (*(ptr+1) == 's')
+	flavor |= ATSYSflag;
+    }
+
+  return flavor;
+}
+
+int athdir_native(char *what, char *sys)
+{
+  char *ptr;
+
+  /* If sys is NULL, fall back to ATHENA_SYS if it's set, otherwise
+   * use the compiled-in value.
+   */
+  if (sys == NULL)
+    {
+      sys = getenv("ATHENA_SYS");
+      if (sys == NULL || strchr(sys, '/') != NULL)
+	sys = ATHSYS;
+    }
+
+  for (ptr = strchr(what, sys[0]); ptr != NULL; ptr = strchr(ptr + 1, sys[0]))
+    {
+      if (!strncmp(ptr, sys, strlen(sys)))
+	return 1;
+    }
+
+  return 0;
+}
+
+/* You are in a twisty little maze of interconnecting flags, all different.
+ */
+char **athdir_get_paths(char *base_path, char *type,
+			char *sys, char **syscompat, char *machine,
+			char *aux, int flags)
+{
+  char *path;
+  string_list *path_list = NULL, *compat_list = NULL;
+  int t, j, complete, preferredFlavor, want_break;
+  struct stat statbuf;
+  char **current_compat, **mysyscompat = NULL, *compat_env;
+
+  /* If sys is NULL, fall back to ATHENA_SYS if it's set, otherwise
+   * use the compiled-in value.
+   */
+  if (sys == NULL)
+    {
+      sys = getenv("ATHENA_SYS");
+      if (sys == NULL || strchr(sys, '/') != NULL)
+	sys = ATHSYS;
+    }
+
+  /* Generate the syscompat array from the environment if it wasn't
+   * passed in.
+   */
+  if (syscompat == NULL)
+    {
+      /* We're compatible with ourselves. */
+      if (athdir__add_string(&compat_list, sys, 0))
+	return NULL;
+      compat_env = getenv("ATHENA_SYS_COMPAT");
+      if (compat_env != NULL && !strchr(compat_env, '/'))
+	{
+	  if (athdir__parse_string(&compat_list, compat_env, ':'))
+	    return NULL;
+	}
+      syscompat = mysyscompat = athdir__make_string_array(&compat_list);
+    }
+
+  /* If machine is NULL, use whatever was compiled in. */
+  if (machine == NULL)
+    machine = hosttype;
+
+  /* Zeroeth convention is optionally provided by the caller. */
+  conventions[0].name = aux;
+  conventions[0].flavor = template_flavor(aux);
+
+  /* Find matching editorial for the type of directory requested
+   * (to be consulted later).
+   */
+  for (t = 0; editorials[t].type != NULL; t++)
+    {
+      if (type != NULL && !strcmp(type, editorials[t].type))
+	break;
+    }
+
+  if (flags & ATHDIR_MACHINEDEPENDENT)
+    preferredFlavor = DEPENDENTflavor;
+  else
+    {
+      if (flags & ATHDIR_MACHINEINDEPENDENT)
+	preferredFlavor = INDEPENDENTflavor;
+      else
+	preferredFlavor = editorials[t].preferredFlavor;
+    }
+
+  /* Cycle through matching conventions */
+  for (j = 0; j < NUMCONVENTIONS; j++)
+    {
+      if (conventions[j].name == NULL)
+	continue; /* conventions[0], the caller specified convention,
+		   * is not set. */
+      want_break = 0;
+
+      if (
+	  /* If the editorial says this is a reasonable convention
+	   * for this type
+	   */
+	  (editorials[t].allowedFlavors & conventions[j].flavor) ||
+
+	  /* or we don't care what the editorials say */
+	  (flags & ATHDIR_SUPPRESSEDITORIALS) || 
+
+	  /* or something more explicit than the editorials has been
+	   * specified
+	   */
+	  (((ATHDIR_MACHINEDEPENDENT | ATHDIR_MACHINEINDEPENDENT) & flags) &&
+	   (flags & ATHDIR_SUPPRESSSEARCH)))
+	{
+	  /* If we're looking for a specific flavor (machine dependent/
+	   * machine independent) and this isn't it, keep going.
+	   */
+	  if ((ATHDIR_SUPPRESSSEARCH & flags) &&
+	      !(preferredFlavor & conventions[j].flavor))
+	    continue;
+
+	  for (current_compat = syscompat; *current_compat != NULL;
+	       current_compat++)
+	    {
+	      complete = !expand(&path, conventions[j].name,
+				 base_path, type, *current_compat, hosttype);
+
+	      if (!path)
+		return NULL;
+
+	      /* If we're listing everything, or we only care about the
+	       * first match for creation purposes (both cases where we
+	       * don't want to stat()), store this match.
+	       */
+	      if ((flags & ATHDIR_LISTSEARCHDIRECTORIES) ||
+		  ((flags & ATHDIR_SUPPRESSSEARCH) && complete))
+		{
+		  if (athdir__add_string(&path_list, path, 0))
+		    {
+		      free(path);
+		      return NULL;
+		    }
+		  free(path);
+		  
+		  /* In this case (first match for creation) we're done. */
+		  if (flags & ATHDIR_SUPPRESSSEARCH)
+		    {
+		      want_break = 1;
+		      break;
+		    }
+		}
+	      else /* If it's there, store it and be done. */
+		if (complete && !stat(path, &statbuf))
+		  {
+		    if (athdir__add_string(&path_list, path, 0))
+		      {
+			free(path);
+			return NULL;
+		      }
+		    free(path);
+		    want_break = 1;
+		    break;
+		  }
+	      else
+		free(path);
+
+	      /* Don't loop over @sys values unless ATSYSflag. */
+	      if (!(conventions[j].flavor & ATSYSflag))
+		break;
+	    }
+	}
+
+      if (want_break)
+	break;
+    }
+
+  athdir__free_string_array(mysyscompat);
+  return athdir__make_string_array(&path_list);
+}
+
+void athdir_free_paths(char **paths)
+{
+  athdir__free_string_array(paths);
+}
