# Main Recipe for Aap # These targets can be used: :attr test {comment = Test for obvious problems} :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 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)} # Testing is defined in a separate recipe. The "testall" target does the work. :child test.aap # The default is to run the tests, because that is harmless. test all: testall # Install all docs by default. FULLDOCS ?= yes fetch: @if not os.path.exists("_no.CVS"): :error Can only fetch after checkout from CVS. @else: :fetch {fetch = cvs://} . # Install: # - copy the relevant files to /usr/local or ~/. # - compile all Python .py files to .pyc. 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) + @ "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 # Get the version string from AapVersion.py, because $VERSIONSTR is # from the current Aap, which may be older. :cat AapVersion.py | :eval re.search('version_string = "(\\d[^"]*)"', stdin).group(1) | :assign Version # Directories to be used. dir = $PREFIX/lib/aap/Exec-$Version toolsdir = $dir/tools modulesdir = $dir/modules docdir = $dir/doc htmldocdir = $docdir$?HTMLDIR bindir = $PREFIX/bin mandir = $PREFIX/man/man1 sharedocdir = $PREFIX/share/doc sharedocdiraap = $sharedocdir/aap sharehtmldocdir = $sharedocdiraap$?HTMLDIR # Copy the files. :mkdir {r}{f} $toolsdir $modulesdir :copy *.py aap $dir :copy tools/*.py $toolsdir :copy modules/*.aap $modulesdir :copy COPYING README.txt default.aap $dir # Copy the docs. Adjust paths in aap.1 for the $PREFIX used. @if _no.FULLDOCS != 'no': :mkdir {r}{f} $docdir $htmldocdir :copy doc/exec.pdf $docdir :copy doc/*.html $htmldocdir # 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 @else: indexstr = $htmldocdir/index.html htmlstr = $htmldocdir/*.html pdfstr = $docdir/exec.pdf @else: indexstr = "" htmlstr = "" pdfstr = "" indexstr = `string.replace(indexstr, "\\", "\\\\")` htmlstr = `string.replace(htmlstr, "\\", "\\\\")` pdfstr = `string.replace(pdfstr, "\\", "\\\\")` # Modify the manual page to include the actually used paths. # Make a backup copy and restore it afterwards. :mkdir {r}{f} $mandir :copy {exist} aap.1 aap.1.orig :cat aap.1 | :eval re.sub('".*/index.html"', indexstr, stdin) | :eval re.sub('".*.html"', htmlstr, stdin) | :eval re.sub('".*/exec.pdf"', pdfstr, stdin) >! aap.1 :copy aap.1 $mandir :move {f} aap.1.orig aap.1 # Compile *.py files into *.pyc. This must be done after copying, # otherwise they won't be used. # Trick: Only compile aapre.py with Python 2.3, otherwise it generates # an error message. @if not skipbuild(): @import compileall @if sys.version[0] != '2' or sys.version[2] != "3": :move $dir/aapre.py $dir/aapre.py.not @compileall.compile_dir(dir, 1) @if sys.version[0] != '2' or sys.version[2] != "3": :move $dir/aapre.py.not $dir/aapre.py # Create symbolic links for the program. :print Creating a symbolic link for "aap" in $bindir :mkdir {f} $bindir :symlink {f} $dir/aap $bindir/aap @elif os.name in ["win32", "mswin", "nt"]: # On MS-Windows we write an aap.bat file in the Windows directory. # That is ugly but the only solution that works reliably everywhere. PREFIX = $?_arg.PREFIX @if not PREFIX: PREFIX = `os.environ.get("WINDIR")` @if not PREFIX: PREFIX = `os.environ.get("SystemRoot")` @if not PREFIX: :print Do not know where to install Aap, please use a PREFIX argument. :print Example: "aap install PREFIX=C:/bin". @else: :progsearch pyloc python @if pyloc: pyloc = python # "python" is in $PATH, don't add path @else: pyloc = `sys.executable` main = `string.replace(os.path.abspath("Main.py"), "\\", "\\\\")` pyloc = `string.replace(pyloc, "\\", "\\\\")` :cat aap.bat | :eval re.sub("%AAPDIR%\\\\Main.py", main, stdin) | :eval re.sub("=python", '="' + pyloc + '"', stdin) >! $PREFIX/aap.bat :print Installed $PREFIX/aap.bat. # Compile *.py files into *.pyc. @if not skipbuild(): @import compileall @compileall.compile_dir(".", 1) @else: :print On this system you will have to do this manually: :print 1. Add the directory "`os.getcwd()`" to your $($)PATH :print 2. Make sure the ".py" extension is associated with the Python program. # Uninstall: reverse of install. 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 # What version to uninstall? Default is what we are currently running. VERSION ?= $VERSIONSTR dir = $PREFIX/lib/aap/Exec-$VERSION mandir = $PREFIX/man/man1 # Only delete the bin/aap and share/doc symlinks if they point to the # version we uninstalled. @try: n = $PREFIX/bin/aap @if string.find(os.readlink(n), _no.VERSION) >= 0: :del {f} $n @except: @ pass @try: n = $PREFIX/share/doc/aap @if string.find(os.readlink(n), _no.VERSION) >= 0: :del {f} $n @except: @ pass # Give a message when the files for this version can't be found. # Don't bail out, may still want to uninstall the rest. @if not os.path.isdir(dir): :print Aap directory not found: $dir @else: :del {r}{f} $dir # We delete the manual page if there is no "aap" command to be found # now. That works when you install and then uninstall the same # version. When you install a new version and then uninstall an older # one the manual page won't be deleted. :progsearch Aap aap @if not Aap: :del {f} $mandir/aap.1 @elif os.name in ["win32", "mswin", "nt"]: # Delete the aap.bat file that was installed in the Windows directory. PREFIX = $?_arg.PREFIX @if not PREFIX: PREFIX = `os.environ.get("WINDIR")` @if not PREFIX: PREFIX = `os.environ.get("SystemRoot")` @if PREFIX: aaploc = $PREFIX/aap.bat @if not os.path.exists(aaploc): PREFIX = @if not PREFIX: # Can't find it, try searching in $PATH. Don't accept aap.bat in # the current directory. :progsearch aaploc aap.bat @if aaploc == os.path.abspath("aap.bat"): aaploc = @if not (aaploc and os.path.exists(aaploc)): :print Do not know where "aap.bat" is, please use a PREFIX argument. :print Example: "aap uninstall PREFIX=C:/bin". @else: :delete $aaploc dir = `os.path.abspath(".")` :print You can now delete the Aap directory "$dir". @else: :print On this system you will have to uninstall manually # Reporting a problem. report: tmpfile = `tempfname()` :print >$tmpfile Aap version: $VERSIONSTR :print >>$tmpfile system type: `os.name` @if os.name == "posix": :print >>$tmpfile system details: `os.uname()` :print >>$tmpfile :print >>$tmpfile State your problem with Aap here :do email {subject = 'problem in Aap'} {to = bugs@a-a-p.org} {edit} {remove} $tmpfile # Generate a tags file. Let ctags figure out which files to scan. tags: *.py :sys ctags -R . # vim: sts=4 sw=4 :