%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}

%global obsolete_ver 2.0.14-3

Name: guile
Summary: A GNU implementation of Scheme for application extensibility.
Summary(ja): アプリケーション拡張用 Scheme の GNU な実装
Version: 2.2.7
Release: 1%{?_dist_release}

Group: Development/Languages
License: GPLv2+ and LGPLv2+ and GFDL and OFSFDL
URL: https://www.gnu.org/software/guile/

Source: https://ftp.gnu.org/gnu/guile/guile-%{version}.tar.xz

# following patchs are imported from fedora-dev 
Patch1: guile-multilib.patch

Buildroot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: libtool libtool-ltdl-devel >= 2.2.6a
BuildRequires: gmp-devel readline-devel emacs
BuildRequires: libunistring-devel
BuildRequires: libffi-devel
BuildRequires: gc-devel
Requires(post): /sbin/install-info
Requires(preun): /sbin/install-info
Requires: coreutils

Provides: guile = %{version}-%{release}
Obsoletes: guile < %{obsolete_ver}

Vendor:		Project Vine
Distribution:	Vine Linux
Packager:	yasumichi

%global mver %(echo '%{version}' | sed -e 's/\.[0-9]*$//')
%global majorver %(echo '%{mver}' | sed -e 's/\.[0-9]*$//')
%global minorver %(echo '%{mver}' | sed -e 's/^[0-9]*\.//')
%global alt_priority %(printf "%%d%%02d" "%{majorver}" "%{minorver}")

%description
GUILE (GNU's Ubiquitous Intelligent Language for Extension) is a library
implementation of the Scheme programming language, written in C.  GUILE
provides a machine-independent execution platform that can be linked in
as a library during the building of extensible programs.

Install the guile package if you'd like to add extensibility to programs
that you are developing.


%package devel
Summary: Libraries and header files for the GUILE extensibility library.
Summary(ja): GUILE 用の開発ライブラリおよびヘッダファイル
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: gmp-devel
Requires: gc-devel
Provides: guile-devel = %{version}-%{release}
Obsoletes: guile-devel < %{obsolete_ver}

%description devel
The guile-devel package includes the libraries, header files, etc.,
that you'll need to develop applications that are linked with the
GUILE extensibility library.


%package -n compat32-%{name}
Summary: A GNU implementation of Scheme for application extensibility.
Summary(ja): アプリケーション拡張用 Scheme の GNU な実装
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}
Provides: compat32-guile = %{version}-%{release}
Obsoletes: compat32-guile < %{obsolete_ver}

%description -n compat32-%{name}
GUILE (GNU's Ubiquitous Intelligent Language for Extension) is a library
implementation of the Scheme programming language, written in C.  GUILE
provides a machine-independent execution platform that can be linked in
as a library during the building of extensible programs.

Install the guile package if you'd like to add extensibility to programs
that you are developing.


%package -n compat32-%{name}-devel
Summary: Libraries and header files for the GUILE extensibility library.
Summary(ja): GUILE 用の開発ライブラリおよびヘッダファイル
Group: Development/Libraries
Requires: %{name}-devel = %{version}-%{release}
Requires: compat32-%{name} = %{version}-%{release}
Requires: compat32-gmp-devel
Requires: compat32-gc-devel
Provides: compat32-guile-devel = %{version}-%{release}
Obsoletes: compat32-guile-devel < %{obsolete_ver}

%description -n compat32-%{name}-devel
The guile-devel package includes the libraries, header files, etc.,
that you'll need to develop applications that are linked with the
GUILE extensibility library.

You need to install the guile-devel package if you want to develop
applications that will be linked to GUILE.  You'll also need to
install the guile package.


%prep
%setup -q -n guile-%{version}
%patch1 -p1 -b .multilib

%build
%configure \
	--disable-static \
	--disable-error-on-warning \
	--program-suffix=%{?mver}

# Remove RPATH
sed -i 's|" $sys_lib_dlsearch_path "|" $sys_lib_dlsearch_path %{_libdir} "|' \
    libtool

make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT

make DESTDIR=$RPM_BUILD_ROOT install

mkdir -p $RPM_BUILD_ROOT%{_datadir}/guile/site/%{mver}

rm -f $RPM_BUILD_ROOT%{_libdir}/libguile*.la
rm -f $RPM_BUILD_ROOT%{_infodir}/dir

for i in $(seq 1 10); do
  mv $RPM_BUILD_ROOT%{_infodir}/guile{,-%{mver}}.info-$i
  sed -i -e 's/guile\.info/guile-%{mver}.info/' $RPM_BUILD_ROOT%{_infodir}/guile-%{mver}.info-$i
  sed -i -e 's/\* Guile Reference: (guile)/* Guile %{mver} Reference: (guile-%{mver})/' $RPM_BUILD_ROOT%{_infodir}/guile-%{mver}.info-$i
done
mv $RPM_BUILD_ROOT%{_infodir}/guile{,-%{mver}}.info
sed -i -e 's/guile\.info/guile-%{mver}.info/' $RPM_BUILD_ROOT%{_infodir}/guile-%{mver}.info
sed -i -e 's/\* Guile Reference: (guile)/* Guile %{mver} Reference: (guile-%{mver})/' $RPM_BUILD_ROOT%{_infodir}/guile-%{mver}.info
mv $RPM_BUILD_ROOT%{_infodir}/r5rs{,-%{mver}}.info
mv $RPM_BUILD_ROOT%{_datadir}/aclocal/guile{,-%{mver}}.m4

# Our gdb doesn't support guile yet
rm -f ${RPM_BUILD_ROOT}%{_libdir}/libguile*gdb.scm

# Compress large documentation
bzip2 NEWS

for i in ${RPM_BUILD_ROOT}%{_infodir}/goops.info; do
    iconv -f iso8859-1 -t utf-8 < $i > $i.utf8 && mv -f ${i}{.utf8,}
done

touch $RPM_BUILD_ROOT%{_datadir}/guile/site/%{mver}/slibcat

# Remove Libtool archive
rm $RPM_BUILD_ROOT%{_libdir}/guile/%{mver}/extensions/guile-readline.la


%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/ldconfig
/sbin/install-info  %{_infodir}/guile-%{mver}.info.gz %{_infodir}/dir
/sbin/install-info  %{_infodir}/r5rs-%{mver}.info.gz %{_infodir}/dir

if [ $1 -eq 1 ]; then
    %{_sbindir}/update-alternatives \
        --install \
                %{_bindir}/guile \
                guile \
                %{_bindir}/guile%{?mver} \
                %{alt_priority} \
        --slave \
                %{_bindir}/guild \
                guild \
                %{_bindir}/guild%{?mver} \
        --slave \
                %{_bindir}/guile-tools \
                guile-tools \
                %{_bindir}/guile-tools%{?mver} \
        --slave \
                %{_mandir}/man1/guile.1.gz \
                guile.1 \
                %{_mandir}/man1/guile%{?mver}.1.gz
fi

%triggerpostun -- guile < 2.0.14-3
if [ ! -e %{_bindir}/guile ]; then
    rm -f %{_sysconfdir}/alternatives/{guile,guild,guile-tools,guile.1}
    rm -f %{_sharedstatedir}/rpm/alternatives/{guile,guild,guile-tools,guile.1}
fi
%{_sbindir}/update-alternatives \
        --install \
                %{_bindir}/guile \
                guile \
                %{_bindir}/guile%{?mver} \
                %{alt_priority} \
        --slave \
                %{_bindir}/guild \
                guild \
                %{_bindir}/guild%{?mver} \
        --slave \
                %{_bindir}/guile-tools \
                guile-tools \
                %{_bindir}/guile-tools%{?mver} \
        --slave \
                %{_mandir}/man1/guile.1.gz \
                guile.1 \
                %{_mandir}/man1/guile%{?mver}.1.gz

%postun -p /sbin/ldconfig

%preun
if [ "$1" = 0 ]; then
    /sbin/install-info --delete %{_infodir}/guile-%{mver}.info.gz %{_infodir}/dir
    /sbin/install-info --delete %{_infodir}/r5rs-%{mver}.info.gz %{_infodir}/dir

    %{_sbindir}/update-alternatives \
        --remove \
                guile \
                %{_bindir}/guile%{?mver}
fi
:

%post devel
if [ $1 -eq 1 -o ! -e %{_libdir}/pkgconfig/guile.pc ]; then
    %{_sbindir}/update-alternatives \
        --install \
                %{_bindir}/guile-config \
                guile-config \
                %{_bindir}/guile-config%{?mver} \
                %{alt_priority} \
        --slave \
                %{_bindir}/guile-snarf \
                guile-snarf \
                %{_bindir}/guile-snarf%{?mver} \
        --slave \
                %{_libdir}/pkgconfig/guile.pc \
                guile.pc \
                %{_libdir}/pkgconfig/guile-%{?mver}.pc
fi

%triggerpostun -- guile-devel < 2.0.14-4
if [ ! -e %{_bindir}/guile-config ]; then
    rm -f %{_sysconfdir}/alternatives/{guile-config,guile-snarf,guile.pc}
    rm -f %{_sharedstatedir}/rpm/alternatives/{guile-config,guile-snarf,guile.pc}
fi
%{_sbindir}/update-alternatives \
        --install \
                %{_bindir}/guile-config \
                guile-config \
                %{_bindir}/guile-config%{?mver} \
                %{alt_priority} \
        --slave \
                %{_bindir}/guile-snarf \
                guile-snarf \
                %{_bindir}/guile-snarf%{?mver} \
        --slave \
                %{_libdir}/pkgconfig/guile.pc \
                guile.pc \
                %{_libdir}/pkgconfig/guile-%{?mver}.pc

%preun devel
if [ "$1" = 0 ]; then
    %{_sbindir}/update-alternatives \
        --remove \
                guile-config \
                %{_bindir}/guile-config%{?mver}
fi

%if %{build_compat32}
%post -n compat32-%{name} -p /sbin/ldconfig

%postun -n compat32-%{name} -p /sbin/ldconfig
%endif


%files
%defattr(-,root,root,-)
%license COPYING*
%doc AUTHORS ChangeLog HACKING NEWS.bz2 README THANKS
%{_bindir}/guild%{?mver}
%{_bindir}/guile%{?mver}
%{_bindir}/guile-tools%{?mver}
%{_libdir}/libguile*.so.*
%dir %{_libdir}/guile
%dir %{_libdir}/guile/%{mver}
%{_libdir}/guile/%{mver}/ccache
%{_libdir}/guile/%{mver}/extensions
%dir %{_datadir}/guile
%dir %{_datadir}/guile/%{mver}
%{_datadir}/guile/%{mver}/*.scm
%{_datadir}/guile/%{mver}/ice-9
%{_datadir}/guile/%{mver}/language
%{_datadir}/guile/%{mver}/oop
%{_datadir}/guile/%{mver}/rnrs
%{_datadir}/guile/%{mver}/scripts
%{_datadir}/guile/%{mver}/srfi
%{_datadir}/guile/%{mver}/sxml
%{_datadir}/guile/%{mver}/system
%{_datadir}/guile/%{mver}/texinfo
%{_datadir}/guile/%{mver}/web
%{_datadir}/guile/%{mver}/guile-procedures.txt
%dir %{_datadir}/guile/site
%ghost %{_datadir}/guile/site/%{mver}/slibcat
%{_infodir}/*
%{_mandir}/man1/guile%{?mver}*


%files devel
%defattr(-,root,root,-)
%{_bindir}/guile-config%{?mver}
%{_bindir}/guile-snarf%{?mver}
%{_datadir}/aclocal/*
%{_libdir}/libguile-%{mver}.so
%{_libdir}/pkgconfig/*.pc
%dir %{_includedir}/guile
%{_includedir}/guile/%{mver}


# compat32
%if %{build_compat32}
%files -n compat32-%{name}
%defattr(-,root,root,-)
%{_libdir}/libguile*.so.*
%dir %{_libdir}/guile
%dir %{_libdir}/guile/%{mver}
%{_libdir}/guile/%{mver}/ccache
%{_libdir}/guile/%{mver}/extensions


%files -n compat32-%{name}-devel
%defattr(-,root,root,-)
%{_libdir}/libguile-%{mver}.so
%endif


%changelog
* Thu Apr 16 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.2.7-1
- new upstream release.

* Wed Sep 11 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.2.6-2
- made guile-devel alternatives-ready.

* Mon Sep 09 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.2.6-1
- updated to 2.2.6.
- made alternatives-ready.

* Wed Sep 04 2019 Toshiaki Ara <ara_t@384.jp> 2.0.14-2
- rebuild with readline-8.0

* Wed Mar 29 2017 IWAI, Masaharu <iwaim.sub@gmail.com> 2.0.14-1
- update to 2.0.14

* Fri Jul 22 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.0.12-1
- update to 2.0.12

* Tue Mar 24 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 2.0.11-2
- rebuilt with readline 6.3

* Sun Jan 25 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.0.11-1
- update to 2.0.11
- add BuildRequires: libunistring-devel, libffi-devel, gc-devel
- remove Patch2,4

* Tue Nov 05 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.8.8-1
- update to 1.8.8
- remove Patch3,5,6 (guile-1.8.7-ia64jmp.patch)

* Sat Oct 09 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.8.7-2
- rebuilt with rpm-4.8.1
- added Patch1, 2, 3, 5 and 6 from Fedora 

* Tue Nov 03 2009 Yasumichi Akahoshi <yasumichi@vinelinux.org> 1.8.7-1
- new upstream release.
- comment out Patch11,12.

* Fri Jul 24 2009 NAKAMURA Kenta <kenta@vinelinux.org> 1.8.6-4
- added Requires: gmp-devel to guile-devel

* Sat Jun 27 2009 NAKAMURA Kenta <kenta@vinelinux.org> 1.8.6-3
- added compat32 package for x86_64 arch support

* Wed Apr 15 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.8.6-2
- rebuild with libtool-2.2.6a

* Mon Jan 12 2009 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.8.6-1
- new upstream release
- import some patches from fedora development
- drop some old patches
- update spec based on fedora package
- spec in utf-8

* Tue May 13 2008 Yasumichi Akahoshi <yasumichi@vinelinux.org> 1.6.7-6vl5
- use macro for Release

* Sat May 10 2008 Yasumichi Akahoshi <yasumichi@vinelinux.org> 1.6.7-5vl5
- apply new virsioning policy.
- remove *.la

* Sun Apr 23 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6.7-4vl2
- rebuilt with readline 5.1

* Sun Oct 23 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6.7-4vl1
- added Patches from Fedora
  * Fri Sep 02 2005 Phil Knirsch <pknirsch@redhat.com> 5:1.6.7-4
  - Fix dynamic linking on 64bit archs (#159971)
  * Tue Dec 21 2004 Phil Knirsch <pknirsch@redhat.com> 5:1.6.4-16
  - Moved info files to base package as they are not devel related (#139948)
  - Moved static guilereadline and guile-srfi-srfi libs to devel package (#140893)
  - Fixed guile-tools not finding guile lib dir (#142642)
  - Added some nice tools (#142642)
  - Removed smp build, seems to be broken atm

* Fri Jan  7 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6.7-0vl1
- new upstream release
- dropped patch2, 4, 6
- added BuildPrereq: perl

* Fri Jan  2 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6.4-0vl2
- rebuild with new toolchains
- s/Copyright/License/
- added srfi libs
- patch for ppc64 from Fedora package

* Thu May 15 2003 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6.4-0vl1
- update to 1.6.4

* Wed Apr 02 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 1.6.3-0vl3
- rebuild with readline-4.3

* Thu Feb 13 2003 Ryoichi INAGAKI <ryo1i@bc.wakwak.com> 1.6.3-0vl2
- based on Rawhide 1.6.0-4
  - Included s390 as working arch as well, switch to general unknown arch patch
  - rebuild to fix broken deps
  - fix continuations.h on ia64
- new upstream 1.6.3

* Mon Mar 26 2001 Kazuhisa TAKEI <takei@vinelinux.org> 1.3.4-9vl1
- porting for Vine Linux
- remove 1.3 patches( not required  so that upstream upgrade )

* Fri Jul 14 2000 Nalin Dahyabhai <nalin@redhat.com>
- Add version number to prereq for umb-scheme to get the post-install to
  work properly.

* Thu Jul 13 2000 Nalin Dahyabhai <nalin@redhat.com>
- Add an Epoch = 1 in case anyone happened to have 1.4 installed.

* Thu Jul 13 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Tue Jul 11 2000 Nalin Dahyabhai <nalin@redhat.com>
- Back down to 1.3.4.
- Fix to actually link against the version of libguile in the package.

* Sun Jun  4 2000 Nalin Dahyabhai <nalin@redhat.com>
- FHS fixups using the %%{makeinstall} macro.

* Sun Mar 26 2000 Florian La Roche <Florian.LaRoche@redhat.com>
- fix preun-devel
- call ldconfig directly in postun

* Fri Mar 24 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- rebuild with new readline
- update to 1.3.4

* Mon Feb 28 2000 Nalin Dahyabhai <nalin@redhat.com>
- using the same catalog as umb-scheme makes umb-scheme a prereq

* Thu Feb 17 2000 Florian La Roche <Florian.LaRoche@redhat.com>
- readline is needed for %post

* Tue Feb  8 2000 Nalin Dahyabhai <nalin@redhat.com>
- use the same catalog as umb-scheme

* Thu Sep  2 1999 Jeff Johnson <jbj@redhat.com>
- fix broken %postun

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

* Wed Mar 17 1999 Michael Johnson <johnsonm@redhat.com>
- added .ansi patch to fix #endif

* Wed Feb 10 1999 Cristian Gafton <gafton@redhat.com>
- add patch for the scm stuff

* Sun Jan 17 1999 Jeff Johnson <jbj@redhat.com>
- integrate changes from rhcn version (#640)

* Tue Jan 12 1999 Cristian Gafton <gafton@redhat.com>
- call libtoolize first to get it to compile on the arm

* Sat Jan  9 1999 Todd Larason <jtl@molehill.org>
- Added "Requires: guile" at suggestion of Manu Rouat <emmanuel.rouat@wanadoo.fr>

* Fri Jan  1 1999 Todd Larason <jtl@molehill.org>
- guile-devel does depend on guile
- remove devel dependancy on m4
- move guile-snarf from guile to guile-devel
- Converted to rhcn

* Wed Oct 21 1998 Jeff Johnson <jbj@redhat.com>
- update to 1.3.
- don't strip libguile.so.*.0.0. (but set the execute bits).

* Thu Sep 10 1998 Cristian Gafton <gafton@redhat.com>
- spec file fixups

* Wed Sep  2 1998 Michael Fulbright <msf@redhat.com>
- Updated for RH 5.2

* Mon Jan 26 1998 Marc Ewing <marc@redhat.com>
- Started with spec from Tomasz Koczko <kloczek@idk.com.pl>
- added slib link

* Thu Sep 18 1997 Tomasz Koczko <kloczek@idk.com.pl>          (1.2-3)
- added %attr(-, root, root) for %doc, 
- in %post, %postun ldconfig runed as parameter "-p",
- removed /bin/sh from requires,
- added %description,
- changes in %files.

* Fri Jul 11 1997 Tomasz Koczko <kloczek@rudy.mif.pg.gda.pl>  (1.2-2)
- all rewrited for using Buildroot,
- added %postun,
- removed making buid logs,
- removed "--inclededir", added "--enable-dynamic-linking" to configure
  parameters,
- added striping shared libs and /usr/bin/guile,
- added "Requires: /bin/sh" (for guile-snarf) in guile package and
  "Requires: m4" for guile-devel,
- added macro %{PACKAGE_VERSION} in "Source:" and %files,
- added %attr macros in %files.
