##
##  tcl.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_major  9
%define       V_minor  0
%define       V_level  2

#   package information
Name:         tcl
Summary:      Tool Command Language (TCL)
URL:          http://www.tcl.tk/
Vendor:       John Ousterhout
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Language
License:      GPL
Version:      %{V_major}.%{V_minor}.%{V_level}
Release:      20250702

#   list of sources
Source0:      http://download.sourceforge.net/tcl/tcl%{V_major}.%{V_minor}.%{V_level}-src.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101

%description
    The Tool Command Language (TCL), optionally including the
    popular TCL Widget Toolkit (Tk).

%track
    prog tcl:tcl = {
        version   = %{version}
        url       = http://sourceforge.net/projects/tcl/files/
        regex     = tcl(\d+\.\d+(\.\d+)?)-src\.tar.gz
    }

%prep
    %setup -q -n tcl%{V_major}.%{V_minor}.%{V_level}

%build
    #   build Tcl
    ( cd unix
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --includedir=%{l_prefix}/include/tcl
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install

    #   install Tcl
    ( cd unix
      %{l_shtool} subst \
          -e 's;-L[^ ]*;%{l_ldflags};g' \
          -e "s;\\(TCL_BUILD_STUB_LIB_PATH=\\).*;\\1'%{l_prefix}/lib/libtclstub%{V_major}.%{V_minor}\${TCL_DBGX}.a';" \
          tclConfig.sh
      %{l_make} %{l_mflags} install INSTALL_ROOT=$RPM_BUILD_ROOT
    ) || exit $?
    ( cd $RPM_BUILD_ROOT%{l_prefix}
      mv bin/tclsh%{V_major}.%{V_minor} bin/tclsh
      ln lib/libtcl%{V_major}.%{V_minor}.a lib/libtcl.a
      ln lib/libtclstub%{V_major}.%{V_minor}.a lib/libtclstub.a
      cd man/mann
      for mo in *.n; do
          mn=`echo $mo | sed -e 's;\.n$;.3;'`
          mv $mo ../man3/$mn
      done
      cd ../man3
      chmod u+w *
      for mp in *.3; do
          if [ ".`echo $mp | grep '^Tcl_'`" = . ]; then
              mv $mp Tcl_$mp
          fi
      done
    ) || exit $?

    #   post-process installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

