--- main.aap.orig	2015-06-06 11:49:26.000000000 +0000
+++ main.aap	2017-10-27 12:00:00.000000000 +0000
@@ -5,7 +5,7 @@
 :attr all {comment = Same as "test"}
 :attr clean {comment = Cleanup after testing}
 :attr fetch {comment = Obtain latest version from CVS}
-:attr install {comment = Install Aap; use PREFIX=path to specify where; use FULLDOCS=no to skip installing HTML and PDF docs; use HTMLDIR=/html to install HTML files in a subdirectory}
+:attr install {comment = Install Aap; use PREFIX=path and/or DESTDIR=path to specify where; use FULLDOCS=no to skip installing HTML and PDF docs; use HTMLDIR=/html to install HTML files in a subdirectory}
 :attr uninstall {comment = Uninstall current version of Aap; use PREFIX=path to specify where; use VERSION=1.123 to specify a different version}
 :attr tags {comment = Create a tags file (requires Exuberant ctags)}
 
@@ -34,15 +34,16 @@
 install:
     @if os.name == 'posix':
 	PREFIX = `os.path.expanduser(_no.PREFIX)`
-	@if not os.access(_no.PREFIX, os.W_OK):
-	    @if os.access(_no.PREFIX, os.R_OK):
-                :error Install directory is not writable: $PREFIX
-            @r = raw_input(('\nThe $PREFIX directory does not exist: "%s"\n'
-            @               % _no.PREFIX) +
+	DESTDIR = $DESTDIR$PREFIX
+	@if not os.access(_no.DESTDIR, os.W_OK):
+	    @if os.access(_no.DESTDIR, os.R_OK):
+                :error Install directory is not writable: $DESTDIR
+            @r = raw_input(('\nThe $DESTDIR directory does not exist: "%s"\n'
+            @               % _no.DESTDIR) +
             @           "Do you want to try creating it? (y/n) ")
             @if not r or (r[0] != 'y' and r[0] != 'Y'):
-                :error Install directory does not exist: $PREFIX
-            :mkdir {r} $PREFIX
+                :error Install directory does not exist: $DESTDIR
+            :mkdir {r} $DESTDIR
 
 	# Get the version string from AapVersion.py, because $VERSIONSTR is
 	# from the current Aap, which may be older.
@@ -50,16 +51,22 @@
 				    stdin).group(1) | :assign Version
 
 	# Directories to be used.
-	dir = $PREFIX/lib/aap/Exec-$Version
+	dir = $DESTDIR/lib/aap/Exec-$Version
 	toolsdir = $dir/tools
 	modulesdir = $dir/modules
 	docdir = $dir/doc
 	htmldocdir = $docdir$?HTMLDIR
-	bindir = $PREFIX/bin
-	mandir = $PREFIX/$MANSUBDIR/man1
-	sharedocdir = $PREFIX/share/doc
+	bindir = $DESTDIR/bin
+	mandir = $DESTDIR/$MANSUBDIR/man1
+	sharedocdir = $DESTDIR/share/doc
 	sharedocdiraap = $sharedocdir/aap
 	sharehtmldocdir = $sharedocdiraap$?HTMLDIR
+	prefixdir = $PREFIX/lib/aap/Exec-$Version
+	prefixdocdir = $dir/doc
+	prefixhtmldocdir = $docdir$?HTMLDIR
+	prefixsharedocdir = $PREFIX/share/doc
+	prefixsharedocdiraap = $sharedocdir/aap
+	prefixsharehtmldocdir = $sharedocdiraap$?HTMLDIR
 
 	# Copy the files.
 	:mkdir {r}{f} $toolsdir $modulesdir
@@ -76,10 +83,10 @@
 	    # Create symbolic links for the docs dir.
 	    @if os.path.exists(sharedocdir):
 		:print Creating a symbolic link for "aap" in $sharedocdir
-		:symlink {f} $docdir $sharedocdiraap
-		indexstr = $sharehtmldocdir/index.html
-		htmlstr = $sharehtmldocdir/*.html
-		pdfstr = $sharedocdiraap/exec.pdf
+		:symlink {f} $prefixdocdir $sharedocdiraap
+		indexstr = $prefixsharehtmldocdir/index.html
+		htmlstr = $prefixsharehtmldocdir/*.html
+		pdfstr = $prefixsharedocdiraap/exec.pdf
 	    @else:
 		indexstr = $htmldocdir/index.html
 		htmlstr = $htmldocdir/*.html
@@ -119,7 +126,7 @@
 	# Create symbolic links for the program.
 	:print Creating a symbolic link for "aap" in $bindir
 	:mkdir {f} $bindir
-	:symlink {f} $dir/aap $bindir/aap
+	:symlink {f} $prefixdir/aap $bindir/aap
 
     @elif os.name in ["win32", "mswin", "nt"]:
 	# On MS-Windows we write an aap.bat file in the Windows directory.
@@ -159,26 +166,27 @@
 uninstall:
     @if os.name == 'posix':
 	PREFIX = `os.path.expanduser(_no.PREFIX)`
-	@if not os.access(_no.PREFIX, os.W_OK):
-	    :error Install directory is not writable: $PREFIX
+	DESTDIR = $DESTDIR$PREFIX
+	@if not os.access(_no.DESTDIR, os.W_OK):
+	    :error Install directory is not writable: $DESTDIR
 
 	# What version to uninstall?  Default is what we are currently running.
 	VERSION ?= $VERSIONSTR
 
-	dir = $PREFIX/lib/aap/Exec-$VERSION
-	mandir = $PREFIX/$MANSUBDIR/man1
+	dir = $DESTDIR/lib/aap/Exec-$VERSION
+	mandir = $DESTDIR/$MANSUBDIR/man1
 
 	# Only delete the bin/aap and share/doc symlinks if they point to the
 	# version we uninstalled.
 	@try:
-	    n = $PREFIX/bin/aap
+	    n = $DESTDIR/bin/aap
 	    @if string.find(os.readlink(n), _no.VERSION) >= 0:
 	        :del {f} $n
 	@except:
 	@   pass
 
 	@try:
-	    n = $PREFIX/share/doc/aap
+	    n = $DESTDIR/share/doc/aap
 	    @if string.find(os.readlink(n), _no.VERSION) >= 0:
 	        :del {f} $n
 	@except:
