--- Portfile.orig	2022-07-23 11:13:13.000000000 -0500
+++ Portfile	2022-07-23 15:45:55.000000000 -0500
@@ -2,84 +2,64 @@
 PortSystem              1.0
 
 name                    reduce
-version                 20181123
-revision                2
+version                 20211019
+revision                0
 set version_dashes      [regsub {^(\d{4})(\d{2})(\d{2})$} ${version} {\1-\2-\3}]
-set svnrev              4829
-checksums               rmd160  cf81887b9bab0d6fd7b4e4ff88e3eb67223d1330 \
-                        sha256  9787f31ef1ec23988f4c551388c6ffffe5b97ca290de6eed1c12dff1737763c8 \
-                        size    261842669
-
-categories              math
-license                 BSD LGPL-2.1
+set svnrev              6110
+categories              math lang
+license                 BSD
 platforms               darwin
 maintainers             {gmail.com:mark.brethen @mbrethen} openmaintainer
-
 description             REDUCE Computer Algebra System
-
-long_description        REDUCE is a graphical Computer Algebra System. It \
-                        allows for solving differential equations, integration,\
-                        matrix manipulation and 3D plotting. It also contains a\
-                        large number of additional packages.
-
+long_description \
+    REDUCE is an interactive system for general algebraic computations of \
+    interest to mathematicians, scientists and engineers.
 homepage                https://reduce-algebra.sourceforge.io/
 master_sites            sourceforge:project/reduce-algebra/snapshot_${version_dashes}
 distname                Reduce-svn${svnrev}-src
 
-universal_variant       no
+checksums               sha256  046e3eda8ab006bb184b6bbf911bb87b35f110b300b5f52766445e9c8a22ad1a \
+                        size    240908050
 
-patchfiles-append       patch-packages-plot-gnuintfc.red.diff      \
-                        patch-generic-breduce-breduce.1.diff       \
-                        patch-reduce-deployment-target.diff        \
-                        patch-csl-prefix.diff                      \
-                        patch-csl-create_old_bundle.diff
+compiler.cxx_standard 2011
 
-post-patch {
-    reinplace           -W ${worksrcpath} "s|@PREFIX@|${prefix}|g" \
-                        csl/cslbase/configure                      \
-                        csl/cslbase/configure.ac                   \
-                        csl/fox/configure                          \
-                        csl/fox/configure.ac                       \
-                        csl/foxtests/configure                     \
-                        csl/foxtests/configure.ac                  \
-                        packages/plot/gnuintfc.red                 \
-                        generic/breduce/breduce.1
-}
+patchfiles-append       patch-configure.ac.diff \
+                        patch-csl-build.diff \
+                        patch-packages-plot-gnuintfc.red.diff
+
+depends_build-append    port:gnuplot \
+                        port:automake \
+                        port:autoconf \
+                        port:libtool \
+                        port:xorg-xorgproto \
+                        port:xorg-libX11 \
+                        port:xorg-libXcursor \
+                        port:xorg-libXext \
+                        port:Xft2 \
+                        port:xorg-libXrandr \
+                        port:xrender
+
+depends_lib-append      port:fontconfig \
+                        port:freetype \
+                        port:libffi \
+                        port:ncurses \
+                        port:netpbm
 
-compiler.cxx_standard   2011
+configure.ldflags-append -lintl
 
 use_parallel_build      no
 
-depends_build-append    port:automake        \
-                        port:autoconf        \
-                        port:libtool         \
-                        port:netpbm
+universal_variant       no
 
-if {[variant_isset doc]} {
-    depends_build-append  \
-                        port:dvipng                   \
-                        port:texlive-fonts-extra      \
-                        port:texlive-formats-extra    \
-                        port:texlive-latex-extra      \
-                        port:texlive-plain-generic    \
-                        port:texlive-bin-extra        \
-                        port:texlive-fonts-recommended
+post-patch {
+    reinplace -W ${worksrcpath} "s|@PREFIX@|${prefix}|g" \
+        configure.ac \
+        csl/cslbase/configure.ac \
+        csl/fox/configure.ac \
+        csl/foxtests/configure.ac \
+        packages/plot/gnuintfc.red
 }
 
-depends_lib-append      port:libedit         \
-                        port:xorg-libXcursor \
-                        port:Xft2            \
-                        port:xorg-libXrandr  \
-                        port:fontconfig      \
-                        port:freetype        \
-                        port:ncurses
-
-depends_run-append      port:gnuplot         \
-                        path:bin/latex:texlive
-
-configure.ldflags-append \
-                       -lintl
-
 configure {
     # we have to run configure twice, once --with-csl
     # and another time --with-psl, prior to building
@@ -98,109 +78,40 @@
     portconfigure::configure_main
 }
 
-# Documentation is also re-generated in the tree so that regardless of
-# history it should end up clean and organized.
-post-build {
-    if {[variant_isset doc]} {
-        system -W ${worksrcpath}/doc/misc ${build.cmd}
-        system -W ${worksrcpath}/doc/manual ${build.cmd}
-    }
-}
-
 destroot {
     set builddir [exec ${worksrcpath}/scripts/findhost.sh [exec ${worksrcpath}/config.guess]]
-
     set cslbuilddir ${worksrcpath}/cslbuild/${builddir}
     set pslbuilddir ${worksrcpath}/pslbuild/${builddir}
-    set genericdir  ${worksrcpath}/generic
-
-    set sharedir    ${prefix}/share/${name}
-    set libexecdir  ${prefix}/libexec/${name}
-    set bindir      ${prefix}/bin
-    set mandir      ${prefix}/share/man/man1
-    set docdir      ${prefix}/share/doc/${name}
+    set libexecdir  ${destroot}${prefix}/libexec/${name}
+    set bindir      ${destroot}${prefix}/bin
+    set appsdir     ${destroot}${applications_dir}/${name}
 
-    # Create target directories
     xinstall -d \
-        ${destroot}${sharedir}           \
-        ${destroot}${libexecdir}/csl     \
-        ${destroot}${libexecdir}/psl/psl \
-        ${destroot}${libexecdir}/psl/red
-
-    # Manual files
-    copy                                  \
-        ${filespath}/redcsl.1             \
-        ${filespath}/redpsl.1             \
-        ${genericdir}/newfront/redfront.1 \
-        ${destroot}${mandir}
-
-    ln -s ${prefix}/share/man/man1/redfront.1 ${destroot}${mandir}/rfcsl.1
-    ln -s ${prefix}/share/man/man1/redfront.1 ${destroot}${mandir}/rfpsl.1
-
-    # CSL files
-    copy {*}[glob ${cslbuilddir}/csl/*.app] ${destroot}${libexecdir}/csl
-    ln -s ${prefix}/libexec/${name}/csl/reduce.app ${destroot}${applications_dir}/reduce.app
-
-    copy ${filespath}/runcsl.sh ${destroot}${bindir}/redcsl
-    copy ${filespath}/runbootstrapreduce.sh ${destroot}${bindir}/bootstrapreduce
-    copy ${filespath}/runcsllisp.sh ${destroot}${bindir}/csl
-
-    foreach f {redcsl bootstrapreduce csl} {
-        file attributes ${destroot}${bindir}/${f} -permissions +x
-    }
-
-    copy ${cslbuilddir}/redfront/rfcsl ${destroot}${bindir}
-
-    # PSL files
-    copy {*}[glob ${pslbuilddir}/psl/*] ${destroot}${libexecdir}/psl/psl
-    copy {*}[glob ${pslbuilddir}/red/*] ${destroot}${libexecdir}/psl/red
-    copy ${filespath}/runpsl.sh ${destroot}${bindir}/redpsl
-    file attributes ${destroot}${bindir}/redpsl -permissions +x
-
-    # Note (ha ha) that rfpsl is built in the cslbuild part of the tree.
-    copy ${cslbuilddir}/redfront/rfpsl ${destroot}${bindir}
-
-    xinstall -d ${destroot}${docdir}
-    xinstall -m 0644 -W ${worksrcpath}/csl/reduce.doc \
-        BSD-LICENSE.txt                               \
-        LGPL-2.1.txt                                  \
-        ${destroot}${docdir}
-
-    # install breduce
-    copy ${worksrcpath}/generic/breduce/breduce.1 ${destroot}/${mandir}
-    copy ${worksrcpath}/generic/breduce/breduce.pdf ${destroot}${docdir}
-    copy ${worksrcpath}/generic/breduce/breduce     \
-        ${worksrcpath}/packages/breduce/breduce.red \
-        ${destroot}/${libexecdir}
-    ln -s ${prefix}/libexec/reduce/breduce ${destroot}${prefix}/bin/breduce
-
-    # Install documentation if requested
-    if {[variant_isset doc]} {
-        set docsrcdir       ${worksrcpath}/doc/manual
-        set docmiscdir      ${worksrcpath}/doc/misc
-        set docbasename     manual
-        set extradocimagebasenames {bild cmsy10 gnuplotex turtleeg}
-
-        xinstall -d ${destroot}${docdir}/html ${destroot}${docdir}/pdf
-
-        copy                                \
-            {*}[glob ${docmiscdir}/*.pdf]   \
-            ${docsrcdir}/${docbasename}.pdf \
-            ${destroot}${docdir}/pdf
-        copy                                            \
-            ${docsrcdir}/redlogo.png                    \
-            {*}[glob ${docsrcdir}/${docbasename}*.html] \
-            {*}[glob ${docsrcdir}/${docbasename}*.png]  \
-            ${docsrcdir}/${docbasename}.css             \
-            ${docsrcdir}/index.html                     \
-            ${destroot}${docdir}/html
-        foreach n ${extradocimagebasenames} {
-            copy {*}[glob ${docsrcdir}/${n}*.png] ${destroot}${docdir}/html
-        }
-    }
-}
+        ${libexecdir} \
+        ${libexecdir}/psl \
+        ${libexecdir}/psl/psl \
+        ${libexecdir}/psl/red \
+        ${appsdir}
 
-variant doc description {Install HTML and PDF documentation} {}
+    copy ${worksrcpath}/macbuild/README.for.distribution ${libexecdir}/README
+    
+    copy ${cslbuilddir}/csl/reduce.app ${appsdir}
+    xinstall -m a+rx ${worksrcpath}/macbuild/runcsl.sh ${appsdir}/redcsl
+    xinstall -m a+rx ${cslbuilddir}/redfront/rfcsl ${appsdir}
+    
+    copy {*}[glob ${pslbuilddir}/psl/*] ${libexecdir}/psl/psl
+    copy {*}[glob ${pslbuilddir}/red/*] ${libexecdir}/psl/red
+    xinstall -m a+rx ${worksrcpath}/macbuild/runpsl.sh ${libexecdir}/psl/redpsl
+    xinstall -m a+rx ${cslbuilddir}/redfront/rfpsl ${libexecdir}/psl
+
+    copy ${worksrcpath}/doc/manual/manual.pdf ${libexecdir}/reduce-manual.pdf
+
+    # link scripts to ${prefix}/bin
+    ln -s ${applications_dir}/${name}/redcsl ${bindir}/redcsl
+    ln -s ${prefix}/libexec/${name}/psl/redpsl ${bindir}/redpsl
+    ln -s ${applications_dir}/${name}/rfcsl ${bindir}/rfcsl
+    ln -s ${prefix}/libexec/${name}/psl/rfpsl ${bindir}/rfpsl
+}
 
 livecheck.version   ${version_dashes}
 livecheck.url       https://sourceforge.net/projects/reduce-algebra/files/
