##
##  tcl.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  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  8
%define       V_minor  4
%define       V_level  1

#   package information
Name:         tcl
Summary:      Tool Command Language (TCL)
URL:          http://tcl.activestate.com/
Vendor:       John Ousterhout
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        Language
License:      GPL
Version:      %{V_major}.%{V_minor}.%{V_level}
Release:      20030103

#   package options
%option       with_x11 %{l_test -p x11}

#   list of sources
Source0:      ftp://ftp.scriptics.com/pub/tcl/tcl%{V_major}_%{V_minor}/tcl%{V_major}.%{V_minor}.%{V_level}-src.tar.gz
Source1:      ftp://ftp.scriptics.com/pub/tcl/tcl%{V_major}_%{V_minor}/tk%{V_major}.%{V_minor}.%{V_level}-src.tar.gz

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103
PreReq:       OpenPKG, openpkg >= 20030103
%if "%{with_x11}" == "yes"
BuildPreReq:  X11
PreReq:       X11
%endif
AutoReq:      no
AutoReqProv:  no

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

%prep
    %setup0 -q -c -n tcl-%{V_major}.%{V_minor}.%{V_level}
    %setup1 -q -T -D -a 1

%build
    #   build Tcl
    ( cd tcl%{V_major}.%{V_minor}.%{V_level}/unix
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix} \
          --includedir=%{l_prefix}/include/tcl \
          --disable-shared
      %{l_make} %{l_mflags -O}
    )

    #   build Tk (optional)
%if "%{with_x11}" == "yes"
    ( cd tk%{V_major}.%{V_minor}.%{V_level}/unix
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix} \
          --includedir=%{l_prefix}/include/tcl \
          --disable-shared \
          --with-tcl=../../tcl%{V_major}.%{V_minor}.%{V_level}/unix
          --with-x \
          --x-includes=`%{l_prefix}/etc/rc --query x11_incdir` \
          --x-libraries=`%{l_prefix}/etc/rc --query x11_libdir`
      %{l_make} %{l_mflags -O}
    )
%endif

%install
    rm -rf $RPM_BUILD_ROOT

    #   install Tcl
    ( cd tcl%{V_major}.%{V_minor}.%{V_level}/unix
      %{l_make} %{l_mflags} install INSTALL_ROOT=$RPM_BUILD_ROOT
    )
    ( 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
    )
    %{l_shtool} subst \
        -e "s;-L$RPM_BUILD_DIR[^ ]*;-L%{l_prefix}/lib;" \
        $RPM_BUILD_ROOT%{l_prefix}/lib/tclConfig.sh

    #   install Tk (optional)
%if "%{with_x11}" == "yes"
    ( cd tk%{V_major}.%{V_minor}.%{V_level}/unix
      %{l_make} %{l_mflags} install INSTALL_ROOT=$RPM_BUILD_ROOT
    )
    ( cd $RPM_BUILD_ROOT%{l_prefix}
      mv bin/wish%{V_major}.%{V_minor} bin/wish
      ln lib/libtk%{V_major}.%{V_minor}.a lib/libtk.a
      ln lib/libtkstub%{V_major}.%{V_minor}.a lib/libtkstub.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_'`" = . ] && \
             [ ".`echo $mp | grep '^Tk_'`"  = . ]; then
              mv $mp Tk_$mp
          fi
      done
    )
%endif

    #   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
    rm -rf $RPM_BUILD_ROOT

