# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 89907 2012-02-14 18:44:28Z easieste@macports.org $

PortSystem  1.0

name        slime
version     20120213
epoch       20120213
revision    0
categories  lang
platforms   darwin
# If you want to update SLIME, go ahead, but please first test with
# all the currently working Lisps 'abcl', 'ccl', 'clisp', 'ecl' and 'sbcl'.
maintainers easieste openmaintainer

description An Emacs mode for unifying Common Lisp development

long_description    \
    SLIME extends Emacs with new support for interactive programming \
    in Common Lisp. The features are centred around `slime-mode', an \
    Emacs minor-mode that complements the standard `lisp-mode'. While \
    `lisp-mode' supports editing Lisp source files, `slime-mode' adds \
    support for interacting with a running Common Lisp process for \
    compilation, debugging, documentation lookup, and so on.

homepage        http://common-lisp.net/project/slime/
master_sites    ${homepage}
fetch.type      cvs
cvs.root        :pserver:anonymous@common-lisp.net:/project/slime/cvsroot
cvs.module      slime
cvs.password    anonymous
cvs.date        ${version}
worksrcdir      slime

use_configure   no
depends_lib     port:emacs

variant app description "Build SLIME against editors/emacs-app" {
    depends_run-append port:emacs-app
    depends_run-delete port:emacs
    depends_lib-append port:emacs-app
    depends_lib-delete port:emacs
}

variant sbcl description "Require lang/sbcl for SLIME" {
    depends_run-append port:sbcl
}

variant clisp description "Require lang/clisp for SLIME" {
    depends_run-append port:clisp
}

variant abcl description "Require lang/abcl for SLIME" {
    depends_run-append port:abcl
}

variant ccl description "Require lang/ccl for SLIME" {
    depends_run-append port:ccl
}

variant ecl description "Require lang/ecl for SLIME" {
    depends_run-append port:ecl
}

post-patch {
    reinplace "s|/usr/local|${prefix}/share|g" \
        ${worksrcpath}/doc/Makefile
}

set slime_emacs_binary ""
set slime_site_lisp_dir "${destroot}${prefix}/share/emacs/site-lisp/slime"
set slime_site_lisp_contrib_dir "${slime_site_lisp_dir}/contrib"
set slime_byte_compile_p 0


configure {
    set slime_emacs_binary [
       if { [ variant_isset app ]
            && [file exist ${applications_dir}/Emacs.app/Contents/MacOS/Emacs] } {
           list "${applications_dir}/Emacs.app/Contents/MacOS/Emacs"
       } else {
           list "${prefix}/bin/emacs"
       }
    ]

    set slime_byte_compile_p   0

    # Byte compiling doesn't seem to be working
    if {! [file executable ${slime_emacs_binary}]} {
          set slime_byte_compile_p 0
#          ui_msg "Couldn't find an executable Emacs image so won't byte compile the Elisp files."
      } else {
          set slime_byte_compile_p 1
#          ui_msg "Emacs binary used for byte compilation is ${slime_emacs_binary}."
      }

    # Comment next line out to try byte compilation
    set slime_byte_compile_p 0
}

build {
    if { ${slime_byte_compile_p} } {
        system "cd ${worksrcpath} && ${slime_emacs_binary} \
                --batch  \
                --directory ${worksrcpath}  \
                --directory ${worksrcpath}/contrib \
                --funcall batch-byte-compile \
                contrib/*.el"
        system "cd ${worksrcpath} && ${slime_emacs_binary} \
                --batch  \
                --directory ${worksrcpath}  \
                --directory ${worksrcpath}/contrib \
                --funcall batch-byte-compile \
                *.el"
    }
    system "cd ${worksrcpath}/doc && make slime.info"
}

destroot    {
    xinstall -W ${worksrcpath} -m 755 -d ${slime_site_lisp_dir}

    foreach file [glob *.el *.elc *.lisp ChangeLog] {
        xinstall -W ${worksrcpath} -m 644 ${file} ${slime_site_lisp_dir}
    }

    xinstall -W ${worksrcpath}/contrib -m 755 -d ${slime_site_lisp_contrib_dir}

    foreach file [glob *.el *.elc *.lisp ChangeLog] {
        xinstall -W ${worksrcpath}/contrib -m 644 ${file} ${slime_site_lisp_contrib_dir}
    }

    xinstall -m 644 ${worksrcpath}/doc/slime.info ${destroot}${prefix}/share/info
}

notes "

To use SLIME, you need to have a Common Lisp installed with which you
wish to interact.  At the moment, 'sbcl', 'abcl', 'ccl', 'ecl' and
'clisp' all work.  As a convenience, port variants for SLIME exist
which require the installation of these Lisps.

Then put the following in your ~/.emacs:

(add-to-list 'load-path \"${prefix}/share/emacs/site-lisp/slime\")
(setq slime-lisp-implementations
     \`((sbcl (\"${prefix}/bin/sbcl\"))
       (abcl (\"${prefix}/bin/abcl\"))
       (clisp (\"${prefix}/bin/clisp\"))))
(require \'slime)
(slime-setup  \'(slime-repl slime-asdf slime-fancy slime-banner))

Populate the initialization list in SLIME-LISP-IMPLEMENTATIONS with
the correct paths to the Common Lisp exectuables you wish to use.

Then, 'M-x slime' from Emacs should connect you to the first Common
Lisp implementation in the list. 'C-- M-x slime' will present an
interactive chooser for additional implementations in the list.

"



