# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id$
PortSystem      1.0
PortGroup       compilers 1.0

name            eso-itcl84
conflicts       eso-itcl84-devel
version         3.4.3
revision        12

set _name       itcl
categories      lang
maintainers     eso.org:usd-help
description     iTcl Tool Kit
long_description \
  itck

platforms           darwin
homepage            http://incrtcl.sourceforge.net/
master_sites        sourceforge:project/incrtcl/%5BIncr%20Tcl_Tk%5D-source/Itcl%20${version}:ITCL \
                    sourceforge:tcl:TCL


set _tcl_version            8.4.20
set _itk_name               itk
set _itk_version            3.4.2
set _itk_wk_version         3.4
set _iwidgets_name          iwidgets
set _iwidgets_version       4.1.0

dist_subdir    eso-tcltk
distname            ${_name}${version}
distfiles           ${_name}${version}${extract.suffix}:ITCL \
                    tcl${_tcl_version}-src${extract.suffix}:TCL

checksums           itcl3.4.3.tar.gz \
                    rmd160  5962369d19cebb2355c93eaabc1bbb410dcbbcc9 \
                    sha256  28b55f44a2fd450862a6f12982c00c1d03d767f62a834d83945a616e06068887 \
                    tcl8.4.20-src.tar.gz \
                    md5     b57ecc6540026fd4a83288ac6bf2b02b \
                    sha1    a9b7836aa5a1de31fde2738e2c15033d731f2aba \
                    rmd160  27abfdd9d8d518cfc3beff85ca782144710b13e2 \
                    sha256  fcb317b65c69f1d6962057c5622a80980bc22ffadf25c1cc50b6d02ff6c2cf40


compilers.choose    cc cxx
compilers.setup     gcc 

default_variants  +${compilers.gcc_default}
use_parallel_build      no


prefix              /opt/local/libexec/eso/tcltk-8.4
configure.args      \
        --exec_prefix=${prefix} \
        --mandir=${prefix}/share/man \
		    --with-tcl=${prefix}/lib \
		    --with-tclinclude=${prefix}/include \
		    --enable-shared
if { [gcc_variant_isset] && [compilers::get_current_gcc_version] >= 14 } {
  configure.cflags-append  \
          -Wno-incompatible-pointer-types \

}
depends_lib         port:eso-tcl84

configure.cppflags-append \
  -I${workpath}/tcl${_tcl_version}/generic -I${workpath}/tcl${_tcl_version}/unix -I${prefix}/include


variant itk description {add in itk} {
  master_sites-append         sourceforge:project/incrtcl/%5BIncr%20Tcl_Tk%5D-source/Itk%20${_itk_version}:ITK
  distfiles-append            ${_itk_name}${_itk_version}${extract.suffix}:ITK
  checksums-append            itk3.4.2.tar.gz \
                              rmd160  4c7f70a9c77b2390d41071777dfb47c0599da36e \
                              sha256  8e5746de402d4ac9920f35793a1d328cf084b0c3d6af8b057e00fd37c82ad2ec
  depends_lib-append port:eso-tk84
  post-destroot {
    system "echo 'configure, build and install itk...'"
    configure.args-append \
		    --with-itcl=${prefix}/lib \
		    --with-tk=${prefix}/lib \
		    --with-tkinclude=${prefix}/include \
        --with-itcl=${workpath}/${_name}${version} \
		    --x-includes=/opt/local/include \
		    --x-libraries=/opt/local/lib
    system "cd ${workpath}/${_itk_name}${_itk_wk_version} ;\
      ./configure \
          CC=${configure.cc} CFLAGS='${configure.cflags}' \
          CXX=${configure.cxx} CPPFLAGS='${configure.cppflags}' \
          ${configure.args} \
      ;\
      make all ;\
      make -w install DESTDIR=${destroot}"
    delete ${destroot}${prefix}/share/man/mann/Toplevel.n
    system "\
      for _n in ${_itk_name} ; do \
        install_name_tool -id ${prefix}/lib/\${_n}3.4/lib\${_n}3.4.dylib ${destroot}${prefix}/lib/\${_n}3.4/lib\${_n}3.4.dylib ; \
      done"
  }
}

variant iwidgets description {add in iwidgets} {
  master_sites-append         sourceforge:project/incrtcl/%5BIncr%20Widgets%5D/${_iwidgets_version}:IW
  distfiles-append            ${_iwidgets_name}-${_iwidgets_version}${extract.suffix}:IW
  checksums-append            iwidgets-4.1.0.tar.gz \
                              rmd160  0efd665ee12a6cbc9b57521632e5eb161440b9bf \
                              sha256  e1f96dbda32570fd772bbe7fe41be9d521477f546f69748e8cc9e57f6c4bc393
  depends_lib-append port:eso-tk84
  post-destroot {
    system "echo 'configure, build and install iwidgets...'"
    configure.args-append \
		    --with-itk=${workpath}/${_itk_name}${_itk_wk_version}
    system "cd ${workpath}/${_iwidgets_name}-${_iwidgets_version} ;\
      ./configure \
          CC=${configure.cc} CFLAGS='${configure.cflags}' \
          CXX=${configure.cxx} CPPFLAGS='${configure.cppflags}' \
          ${configure.args} \
      ;\
      make all ;\
      make -w install DESTDIR=${destroot}"
  }
}

default_variants-append +itk +iwidgets

post-destroot {
  delete ${destroot}${prefix}/share/man/mann/Toplevel.n
  system "\
    for _n in ${_name} ; do \
      install_name_tool -id ${prefix}/lib/\${_n}3.4/lib\${_n}3.4.dylib ${destroot}${prefix}/lib/\${_n}3.4/lib\${_n}3.4.dylib ; \
    done"
}
