%define  MAJOR 8.6

Name:          tcl
Version:       8.6.8
Release:       3
Epoch:         1
Summary:       The Tool Command Language implementation
License:       BSD
URL:           https://sourceforge.net/projects/tcl/
Source0:       http://downloads.sourceforge.net/sourceforge/tcl/tcl-core%{version}-src.tar.gz

BuildRequires: autoconf zlib-devel systemtap-sdt-devel
Provides:      tcl(abi) = %{MAJOR}
Obsoletes:     tcl-tcldict <= %{version}
Provides:      tcl-tcldict = %{version}

#patch0000~0002 come from fedora
Patch0000:     tcl-8.6.3-autopath.patch
Patch0001:     tcl-8.6.8-conf.patch
Patch0002:     tcl-8.6.8-hidden.patch
#patch0003 backport from https://core.tcl.tk/tcl/tktview/7d0db7c388f52de81faf12da332bc97a24f7b9e5
Patch0003:     tcl-8.6.5-parallel-make-fix.patch

Patch6000:     stay-out-of-internals-when-nice-interfaces-are-avail.patch
Patch6001:     oops.patch
Patch6002:     Fix-for-issue-9fd5c629c1-TclOO-aborts-when-a-trace-o.patch
Patch6003:     Fix-bug-3c32a3f8bd-segmentation-fault-in-TclOO.c-Rel.patch
Patch6004:     Fix-error-message-for-min-math-functions-to-for-for-.patch
Patch6005:     Fix-behavior-of-Tcl_GetRange-and-string-range-regard.patch
Patch6006:     Fix-11ae2be95d-tip-389-branch-string-range-errors-wi.patch
Patch6007:     Improved-overflow-prevention-1.patch
Patch6008:     Improved-overflow-prevention-2.patch
Patch6009:     27b682284974d0cd-command-file-delete-avoid-possible-.patch
Patch6010:     Fix-handling-of-surrogates-when-TCL_UTF_MAX-3-in-Tcl.patch
Patch6011:     Bug-fix-in-Tcl_UtfAtIndex-for-TCL_UTF_MAX-4-only-.-W.patch
Patch6012:     new-package.patch
Patch6013:     Plug-leak-in-TclSetEnv.patch
Patch6014:     closes-d051b77fc18d7340-fixed-segfault-by-integer-ov.patch
Patch6015:     amend-after-merge-8.6th-provide-additionally-an-erro.patch
Patch6016:     In-registry-protect-keyName-from-being-NULL-This-act.patch
Patch6017:     fixes-segfault-00d04c4f12-unfulfilled-base64-strict-.patch
Patch6018:     fixes-4ee9b4f3e965a7da5133-result-of-command-time-ov.patch

Patch9000:     fix-exec-test-error.patch

%description
Tcl(Tool Command Language) provides a powerful platform for creating integration applications
that tie together diverse applications, protocols, devices, and frameworks. When paired with
the Tk toolkit, Tcl provides the fastest and most powerful way to create GUI applications that
run on linux, Unix, and Mac OS X. Tcl can also be used for a variety of web-related tasks and
for creating powerful command languages for applications.

%package help
Summary: help document for tcl
Requires: %{name} = %{epoch}:%{version}-%{release}
BuildArch: noarch

%description help
Help document for tcl.

%package devel
Summary: The development files for tcl
Requires: %{name} = %{epoch}:%{version}-%{release}

%description devel
The development files for tcl.

%prep
%autosetup -n %{name}%{version} -p1

%build
cd unix
autoconf
%configure --enable-threads --enable-symbols --enable-shared --enable-dtrace
%make_build CFLAGS="%{optflags}" TCL_LIBRARY=%{_datadir}/%{name}%{MAJOR}

%install
cd unix
make INSTALL_ROOT=$RPM_BUILD_ROOT TCL_LIBRARY=%{_datadir}/%{name}%{MAJOR} install
cd ..
mv $RPM_BUILD_ROOT%{_bindir}/tclsh%{MAJOR} $RPM_BUILD_ROOT%{_bindir}/tclsh
ln -s lib%{name}%{MAJOR}.so $RPM_BUILD_ROOT%{_libdir}/lib%{name}.so

mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{name}%{MAJOR}
ln -s %{_libdir}/%{name}Config.sh $RPM_BUILD_ROOT%{_libdir}/%{name}%{MAJOR}/%{name}Config.sh

mv license.terms COPYING
mkdir -p $RPM_BUILD_ROOT%{_includedir}/%{name}-private/generic
mkdir -p $RPM_BUILD_ROOT%{_includedir}/%{name}-private/unix

find generic unix -name "*.h" -exec cp -p '{}' %{buildroot}/%{_includedir}/%{name}-private/'{}' ';'
cd %{buildroot}/%{_includedir}
for header in *.h ; do
    if [ -f %{buildroot}/%{_includedir}/%{name}-private/generic/$header ]; then
        ln -sf ../../$header %{buildroot}/%{_includedir}/%{name}-private/generic
    fi
done

sed -i -e "s|$PWD/unix|%{_libdir}|; s|$PWD|%{_includedir}/%{name}-private|" %{buildroot}/%{_libdir}/%{name}Config.sh
rm -rf %{buildroot}/%{_datadir}/%{name}%{MAJOR}/ldAix

%check
cd unix
make test

%pre

%preun

%post
/sbin/ldconfig

%postun
/sbin/ldconfig

%files
%defattr(-,root,root)
%doc README changes COPYING
%{_bindir}/tclsh
%{_datadir}/%{name}%{MAJOR}
%{_datadir}/%{name}8
%{_libdir}/lib%{name}%{MAJOR}.so
%exclude %{_datadir}/%{name}%{MAJOR}/tclAppInit.c

%files devel
%{_includedir}/*
%{_libdir}/lib%{name}stub%{MAJOR}.a
%{_libdir}/lib%{name}.so
%{_libdir}/%{name}Config.sh
%{_libdir}/%{name}ooConfig.sh
%{_libdir}/%{name}%{MAJOR}/%{name}Config.sh
%{_libdir}/pkgconfig/tcl.pc
%{_datadir}/%{name}%{MAJOR}/tclAppInit.c

%files help
%{_mandir}/man3/*
%{_mandir}/man1/*
%{_mandir}/mann/*

%changelog
* Mon Sep 09 2019 Huiming Xie <xiehuiming@huawei.com> - 1:8.6.8.3
- Package init

