--- Portfile.orig	2011-04-14 14:00:17.000000000 +0900
+++ Portfile	2011-05-12 00:06:25.000000000 +0900
@@ -4,39 +4,59 @@
 PortSystem          1.0
 
 name                julius
-version             4.1.5.1
+version             4.2
 categories          audio japanese
 platforms           darwin
 maintainers         nomaintainer
-supported_archs     noarch
 license             BSD
 
 description         Large Vocabulary Continuous Speech Recognition (LVCSR) Engine
+
 long_description    "Julius" is an open-source high-performance large vocabulary \
                     continuous speech recognition (LVCSR) decoder software for \
                     speech-related researchers and developers. \
                     Based on word N-gram and triphone context-dependent HMM, \
                     it can perform almost real-time decoding on most current \
                     PCs with small amount of memory.
-homepage            http://julius.sourceforge.jp/
-master_sites        sourceforge_jp:julius/50318/:julius \
-                    sourceforge_jp:julius/51158/:dictation_kit
 
-distfiles           ${distname}${extract.suffix}:julius
+homepage            http://julius.sourceforge.jp/
+master_sites        sourceforge_jp:julius/51820/
 
 checksums           ${distname}${extract.suffix} \
-                         sha1    bf746719ea05095ead4be70cf27b52ae77ed5b37 \
-                         rmd160  904738b1f5cd26bf42fe29f10961d42217be0e86
+                    sha1    94b262d1682ec26a250aa294d10389663041040f \
+                    rmd160  ac5aa9f514deabf357404ded261be67f8dcfd34e
 
-patchfiles          patch-configure.in.diff
+patchfiles          patch-configure.diff
 
-use_autoconf        yes
+# Note: '--enable-words-int' should be declared ahead of '--with-mictype'.
+variant words_int description {Use integer for word ID to extend vocabulary limit} {
+    configure.args-append    --enable-words-int
+    notes-append "
+        An executable built with '--enable-words-int' fails to convert\
+        2-bytes bingrams, and it cannot start with the dictation-kit.
+        If you'd like to use the dictation-kit, you may replace its\
+        2-bytes bingram with a 4-bytes one."
+}
 
-pre-configure {
-    foreach dir { mkgshmm gramtools jcontrol julius libjulius libsent } {
-        ui_debug "Running autoconf in ${dir}"
-        system "cd ${worksrcpath}/$dir && ${prefix}/bin/autoconf"
-    }
+platform darwin 10 {
+    depends_lib-append       port:portaudio
+    configure.args-append    --with-mictype=portaudio
+}
+
+destroot.target-append  install.man
+destroot.destdir    prefix=${destroot}${prefix}
+
+post-destroot {
+    xinstall -d ${destroot}${prefix}/share/doc/${name}
+    xinstall -m 644 -W ${worksrcpath} \
+        00readme-ja.txt \
+        00readme.txt \
+        ChangeLog \
+        LICENSE.txt \
+        Release-ja.txt \
+        Release.txt \
+        Sample.jconf \
+        ${destroot}${prefix}/share/doc/${name}
 }
 
 default_variants    +kit
@@ -44,31 +64,41 @@
 set kit_name        dictation-kit
 set kit_version     v4.1
 set dictation_kit   ${kit_name}-${kit_version}
+set kit_distfile    ${dictation_kit}${extract.suffix}
 
 variant kit description {Add dictation kit and a demo script} {
-    distfiles-append    ${dictation_kit}${extract.suffix}:dictation_kit
-
-    checksums-append    ${dictation_kit}${extract.suffix} \
-                            sha1    7fd6fd6de13cd18c9ab811266da9d548d57c422a \
-                            rmd160  9f8603f95cbb363cb8a92189198837f81c4968dd
+    distfiles-append    ${kit_distfile}:kit
+    master_sites-append sourceforge_jp:julius/51930/:kit
+    checksums-append    ${kit_distfile} \
+                        sha1    7fd6fd6de13cd18c9ab811266da9d548d57c422a \
+                        rmd160  9f8603f95cbb363cb8a92189198837f81c4968dd
 
     post-destroot {
         # copy the dictation kit.
-        set lib_inst     ${prefix}/lib/${name}
-        set lib_dest     ${destroot}${lib_inst}
-        file mkdir       ${lib_dest}
-        copy ${workpath}/${dictation_kit}/model      ${lib_dest}
-        copy ${workpath}/${dictation_kit}/fast.jconf ${lib_dest}
+        set lib_dest     ${destroot}${prefix}/lib/${name}
+        xinstall -d ${lib_dest}
+        xinstall -m 644 -W ${workpath}/${dictation_kit} \
+            fast.jconf \
+            light.jconf \
+            ${lib_dest}
+        copy ${workpath}/${dictation_kit}/model ${lib_dest}
         # configure the dictation kit.
         set conf_dest    ${lib_dest}/fast.jconf
-        reinplace "s| model/| ${lib_inst}/model/|g"  ${conf_dest}
+        reinplace "s| model/| ${prefix}/lib/${name}/model/|g"    ${conf_dest}
         reinplace "s|#-charconv from to|-charconv EUC-JP UTF-8|" ${conf_dest}
         # configure an executable demo script file.
         set script_name  julius_demo
         set script_dest  ${destroot}${prefix}/bin/${script_name}
         xinstall -m 755  ${filespath}/${script_name} ${script_dest}
         reinplace "s|@prefix@|${prefix}|g"           ${script_dest}
-        reinplace "s|@lib_inst@|${lib_inst}|g"       ${script_dest}
+        # copy documentation.
+        set kit_docdir   ${destroot}${prefix}/share/doc/${name}/${kit_name}
+        xinstall -d ${kit_docdir}
+        xinstall -m 644 -W ${workpath}/${dictation_kit} \
+            00readme.txt \
+            HOWTO.txt \
+            TROUBLE.txt \
+            ${kit_docdir}
     }
 }
 
