# Tests by default. No tests: rpm -ba --define 'dotests 0' slang*.spec
%{!?dotests: %define dotests 1}
Summary: The shared library for the S-Lang extension language.
Name: slang
%define version 2.3.2
Version: %{version}
Release: 1
License: GPL V2.0 
Group: System Environment/Libraries
Source0: https://www.jedsoft.org/releases/slang/%{name}-%{version}.tar.bz2
Url:  https://www.jedsoft.org/releases/slang
Patch0: slang-2.3.1a-aix.patch
Patch1: slang-2.3.2-iconv.patch
Patch2: slang-2.3.2-Makefile.patch

Prefix: %{_prefix}
%ifarch ia64
%define DEFCCIA gcc
%define DEFCC %{DEFCCIA}
%else
%define DEFCC gcc
%endif

%ifarch ia64
  %define stdlib lib/ia64l32
  %define liblink ../../..
%else
  %define stdlib lib
  %define liblink ../..
%endif

Requires:  zlib >= 1.2.11, pcre >= 8.42, libpng >= 1.6.27
Requires:  libgcc >= 8.3.0, libiconv >= 1.16

%description
S-Lang is an interpreted language and a programming library.  The
S-Lang language was designed so that it can be easily embedded into
a program to provide the program with a powerful extension language.
The S-Lang library, provided in this package, provides the S-Lang
extension language.  S-Lang's syntax resembles C, which makes it easy
to recode S-Lang procedures in C if you need to.

%package devel
Summary: The static library and header files for development using S-Lang.
Group: Development/Libraries
Requires: slang = %{version}-%{release}

%description devel
This package contains the S-Lang extension language static libraries
and header files which you'll need if you want to develop S-Lang based
applications.  Documentation which may help you write S-Lang based
applications is also included.

Install the slang-devel package if you want to develop applications
based on the S-Lang extension language.

%prep
%setup -q
%patch0
%patch1
%patch2

rm -rf   /tmp/%{name}-%{version}-32bit
cp -pr . /tmp/%{name}-%{version}-32bit
rm -fr *
mv       /tmp/%{name}-%{version}-32bit 32bit
cp -pr 32bit 64bit

%build
# Use the default compiler for this platform - gcc otherwise
if [[ -z "$CC" ]]
then
    if test "X`type %{DEFCC} 2>/dev/null`" != 'X'; then
       export CC=%{DEFCC}
    else 
       export CC=gcc
    fi
fi
if test "X$CC" != "Xgcc"
then
       export RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's:-fsigned-char::'`
       export CFLAGS="$RPM_OPT_FLAGS"
%ifarch ia64
   if test "X$CC" != "Xgcc"
   then
       export RPM_OPT_FLAGS=""
   fi
%endif
fi
export CC="/opt/freeware/bin/gcc"
export CXX="/opt/freeware/bin/g++"
# build on 64bit mode
cd 64bit
export OBJECT_MODE=64
export CFLAGS="$RPM_OPT_FLAGS -maix64 -D_LARGE_FILES"
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"
export LIBPATH="%{_builddir}/slang-2.3.2/64bit/src/elfobjs:/opt/freeware/lib/pthread:/opt/freeware/lib"

./configure --prefix=%{_prefix} --libdir=%{_libdir}64  --mandir=%{_mandir} --includedir=%{_prefix}/include/slang  \
	--with-iconv=%{_prefix}	 
make all
if [ "%{dotests}" == 1 ]
then
    (gmake -k check || true)
fi


# build on 32bit mode
cd ../32bit
export OBJECT_MODE=32
export CFLAGS="$RPM_OPT_FLAGS -maix32 -D_LARGE_FILES"
export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000"
export LIBPATH="%{_builddir}/slang-2.3.2/32bit/src/elfobjs:/opt/freeware/lib/pthread:/opt/freeware/lib"

./configure --prefix=%{_prefix} --libdir=%{_libdir} --mandir=%{_mandir} --includedir=%{_prefix}/include/slang  \
	--with-iconv=%{_prefix}

make all
if [ "%{dotests}" == 1 ]
then
    (gmake -k check || true)
fi

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_prefix}/include/slang

export AR="/usr/bin/ar -X32_64"

# install on 64bit mode
cd 64bit
export OBJECT_MODE=64
make DESTDIR=$RPM_BUILD_ROOT install


(
    cd  ${RPM_BUILD_ROOT}/%{prefix}/bin
    for fic in $(ls -1| grep -v -e _32 -e _64)
    do
	mv $fic "$fic"_64
    done
)


# install on 32bit mode 
cd ../32bit
export OBJECT_MODE=32

make DESTDIR=$RPM_BUILD_ROOT install

(
    cd  ${RPM_BUILD_ROOT}/%{prefix}/bin
    for fic in $(ls -1| grep -v -e _32 -e _64)
    do
	mv $fic "$fic"_32
	ln -sf "$fic"_64 $fic
    done
)

# add the 64-bit shared object to the shared library containing already the
# 32-bit shared objects

${AR} -x ${RPM_BUILD_ROOT}%{_libdir}64/libslang.a
${AR} -q ${RPM_BUILD_ROOT}%{_libdir}/libslang.a *.so*

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,system)
%doc 32bit/COPYING 32bit/doc/README 32bit/changes.txt
%doc 32bit/doc/*/slang*.txt 32bit/doc/*.txt
%{_libdir}/*.a
%{_libdir}64/*.a

%doc 32bit/slsh/doc/html/slsh*.html
%config(noreplace) %{_sysconfdir}/slsh.rc
%{_bindir}/*
%{_mandir}/man1/*
%{_libdir}/%{name}
%{_libdir}64/%{name}
%{_datadir}/slsh


%files devel
%defattr(-,root,system)
%doc 32bit/doc/*/cslang*.txt 32bit/doc/*/cref.txt
%{_includedir}/*

%changelog
* Wed Oct 7 2020 Ashwini Chandrappa <ashwic22@in.ibm.com> - 2.3.2
- Updated to version 2.3.2
- Stop shipping files in /usr directory

* Mon Apr 24 2017 Reshma V Kumar <reskumar@in.ibm.com>
- Version 2.3.1a

* Mon May 21 2001 Marc Stephenson <marc@austin.ibm.com>
- Version 1.4.4

* Tue Feb 20 2001 aixtoolbox <aixtoollbox-l@austin.ibm.com>
- Account for different standard lib location in IA64 32-bit ABI

* Fri Oct 27 2000 pkgmgr <pkgmgr@austin.ibm.com>
- Modify for AIX Freeware distribution

* Tue Mar  7 2000 Jeff Johnson <jbj@redhat.com>
- rebuild for sparc baud rates > 38400.

* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com> 
- auto rebuild in the new build environment (release 4)

* Wed Oct 21 1998 Bill Nottingham <notting@redhat.com>
- libslang.so goes in -devel

* Sun Jun 07 1998 Prospector System <bugs@redhat.com>

- translations modified for de

* Sat Jun  6 1998 Jeff Johnson <jbj@redhat.com>
- updated to 1.2.2 with buildroot.

* Tue May 05 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Sat Apr 18 1998 Erik Troan <ewt@redhat.com>
- rebuilt to find terminfo in /usr/share

* Tue Oct 14 1997 Donnie Barnes <djb@redhat.com>
- spec file cleanups

* Mon Sep 1 1997 Donnie Barnes <djb@redhat.com>
- upgraded to 0.99.38 (will it EVER go 1.0???)
- all patches removed (all appear to be in this version)

* Thu Jun 19 1997 Erik Troan <ewt@redhat.com>
- built against glibc

