# Tests by default. No tests: rpm -ba --define 'dotests 0' *.spec
%{!?dotests: %define dotests 1}

Summary: A text file browser similar to more, but better
Name: less
Version: 551 
Release: 1
License: GPL v3
Url: http://www.greenwoodsoftware.com/less/
Group: Applications/Text
Buildroot: /var/tmp/%{name}-root
Prefix: %{_prefix}
Source: http://www.greenwoodsoftware.com/less/%{name}-%{version}.tar.gz 

%description 
Less is a pager. A pager is a program that displays text files. Other
pagers commonly in use are more and pg. Pagers are often used in
command-line environments like the Unix shell and the MS-DOS command
prompt to display files. Windowed environments like the Windows and
Macintosh desktops don't need pagers as much, since they have other
methods for viewing files.

Less is not an editor. You can't change the contents of the file you're
viewing. Less is not a windowing system. It doesn't have fancy scroll
bars or other GUI (graphical user interface) elements. It was designed
to work on simple text-only terminals. 

%prep
%setup -q

# Duplicate source for 32 & 64 bits
rm -rf /tmp/%{name}-%{version}-32bit
mkdir  /tmp/%{name}-%{version}-32bit
mv *   /tmp/%{name}-%{version}-32bit
mkdir 32bit
mv     /tmp/%{name}-%{version}-32bit/* 32bit
rm -rf /tmp/%{name}-%{version}-32bit
mkdir 64bit
cp -rp 32bit/* 64bit/

%build

# first build the 64-bit version
cd 64bit

export CC="gcc -O2 -maix64"
export OBJECT_MODE=64

./configure --prefix=%{_prefix} --mandir=%{_mandir}
make

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

# Now build the 32-bit version
cd ../32bit

export CC="gcc -maix32 -O2 -D_LARGE_FILES"
export LDFLAGS="-Wl,-bmaxdata:0x80000000"
export OBJECT_MODE=32

./configure --prefix=%{_prefix} --mandir=%{_mandir}
make

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

%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

cd 64bit
export AR="/usr/bin/ar -X64"
export OBJECT_MODE=64
make install DESTDIR=$RPM_BUILD_ROOT
/usr/bin/strip ${RPM_BUILD_ROOT}%{_bindir}/* || :
(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in less lessecho lesskey
  do
    mv ${f} ${f}_64
  done
)

cd ../32bit
export AR="/usr/bin/ar -X32"
export OBJECT_MODE=32
make install DESTDIR=$RPM_BUILD_ROOT
/usr/bin/strip ${RPM_BUILD_ROOT}%{_bindir}/* || :
(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in less lessecho lesskey
  do
    mv ${f} ${f}_32
  done
)

# Make 64bit executable as default
(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in less lessecho lesskey
  do
    ln -sf ${f}_64 ${f}
  done
)

mkdir -p $RPM_BUILD_ROOT/usr/bin
cd $RPM_BUILD_ROOT/usr/bin
ln -sf ../..%{_prefix}/bin/* .
cd -

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,system,-)
%doc 32bit/README 32bit/NEWS 32bit/INSTALL 32bit/LICENSE 32bit/COPYING
%{_bindir}/less*
#%{_bindir}/lesskey
#%{_bindir}/lessecho
/usr/bin/*
%{_prefix}/man/man1/less.1
%{_prefix}/man/man1/lesskey.1
%{_prefix}/man/man1/lessecho.1

%changelog

* Tue Aug 06 2019 Baanu Tumma <btumma15@in.ibm.com> 551-1
-Updated to latest version 551

* Wed Sep 20 2017 Sushma M Bhat <susmbhat@in.ibm.com> 487-1
- Updated to latest version 487.

* Wed May 18 2016 Reshma V Kumar <reskumar@in.ibm.com> 481-1
- updated to latest version

* Thu Apr 28 2016 Michael Wilson <michael.wilson@atos.net> 481
- update to version 481 for AIX

* Wed Apr 28 2010 Jean Noel Cordenner <jean-noel.cordenner@bull.net> 4.36
- update to version 4.36 for AIX

* Wed Jun 24 2009 Jean Noel Cordenner <jean-noel.cordenner@bull.net> 429
- port of version 429 for AIX
