%bcond_with check

Summary:        Common Lisp (ANSI CL) implementation
Summary(ja):    関数型言語 Common Lisp (ANSI CL) の実装
Name:           clisp
Version:        2.49.93
Release:        1%{?_dist_release}
Group:          Development/Languages

Vendor:         Project Vine
Distribution:   Vine Linux

License:        GPL
URL:            http://www.clisp.org/
#Source0:         https://ftp.gnu.org/pub/gnu/clisp/release/%{version}/%{name}-%{version}.tar.bz2
Source0:        clisp-dd40369.tar.xz

# https://sourceforge.net/p/clisp/patches/35/
Patch0:         %{name}-db.patch
# https://sourceforge.net/p/clisp/patches/32/
Patch1:         %{name}-format.patch
# The encrypt and setkey functions are no longer available from glibc
Patch2:         %{name}-setkey.patch
# Adapt to changes in pari 2.11.0
Patch3:         %{name}-pari.patch
# The combination of register and volatile is nonsensical
Patch4:         %{name}-register-volatile.patch

Provides:     clisp, ansi-cl
BuildRoot:    %{_tmppath}/%{name}-%{version}-root
BuildRequires:	imake
BuildRequires:	libsigsegv-devel
BuildRequires:	readline-devel
BuildRequires:  dbus-devel
BuildRequires:  diffutils
BuildRequires:  fcgi-devel
BuildRequires:  ffcall
BuildRequires:  gdbm-devel
BuildRequires:  gettext
BuildRequires:  gtk2-devel
BuildRequires:  libICE-devel
BuildRequires:  libSM-devel
BuildRequires:  libX11-devel
BuildRequires:  libXaw-devel
BuildRequires:  libXext-devel
BuildRequires:  libXft-devel
BuildRequires:  libXmu-devel
BuildRequires:  libXrender-devel
BuildRequires:  libXt-devel
BuildRequires:  libglade2-devel
BuildRequires:  pcre-devel
BuildRequires:  libpq-devel
BuildRequires:  openssl-devel
BuildRequires:  zlib-devel

Requires:  vim-common

%description
Common Lisp is a high-level, general-purpose, object-oriented, dynamic,
functional programming language.

CLISP is a Common Lisp implementation by Bruno Haible, then of Karlsruhe
University, and Michael Stoll, then of Munich University, both in Germany. 
It supports the Lisp described in the ANSI Common Lisp standard plus many
extensions.

CLISP includes an interpreter, a compiler, a debugger, CLOS, MOP, a foreign
language interface, i18n, regular expressions, a socket interface, and more. 
An X11 interface is available through CLX, Garnet and CLUE/CLIO. Command line
editing is provided by readline. CLISP runs Maxima, ACL2 and many other
Common Lisp packages.

CLISP runs on most GNU and Unix systems (Linux, FreeBSD, NetBSD, OpenBSD, 
Solaris, Tru64, HP-UX, BeOS, NeXTstep, IRIX, AIX and others) and on other
systems (Windows NT/2000/XP, Windows 95/98/ME) and needs only 4 MB of RAM.

CLISP is Free Software and may be distributed under the terms of GNU GPL.
You may distribute commercial proprietary applications compiled with CLISP,
see file COPYRIGHT in the CLISP distribution.

The user interface comes in English, German, French, Spanish, Dutch, Russian
and Danish, and can be changed at run time.

%prep
%setup -q -n clisp-dd40369

%patch0 -p0
%patch1 -p0
%patch2 -p0
%patch3 -p0
%patch4 -p0

# Change URLs not affected by the --hyperspec argument to configure
sed -i.orig 's|lisp.org/HyperSpec/Body/chap-7.html|lispworks.com/documentation/HyperSpec/Body/07_.htm|' \
    src/clos-package.lisp
touch -r src/clos-package.lisp.orig src/clos-package.lisp
rm -f src/clos-package.lisp.orig
for f in src/_README.*; do
  sed -i.orig 's|lisp.org/HyperSpec/FrontMatter|lispworks.com/documentation/HyperSpec/Front|' $f
  touch -r ${f}.orig $f
  rm -f ${f}.orig
done

# We only link against libraries in system directories, so we need -L dir in
# place of -Wl,-rpath -Wl,dir
cp -p src/build-aux/config.rpath config.rpath.orig
sed -i -e 's/${wl}-rpath ${wl}/-L/g' src/build-aux/config.rpath

# Fix modules that need access to symbols in libgnu.a
sed -i 's/\(${GLLIB_A}\) \(${LIBS}\)/-Wl,--whole-archive \1 -Wl,--no-whole-archive \2 -ldl/' src/makemake.in

# Enable firefox to be the default browser for displaying documentation
sed -i 's/;; \((setq \*browser\* .*)\)/\1/' src/cfgunix.lisp

# Unpack the CLX manual
tar -C modules/clx -xzf modules/clx/clx-manual.tar.gz
chmod -R go+r modules/clx/clx-manual
chmod a-x modules/clx/clx-manual/html/doc-index.cgi


%build
ulimit -s unlimited
export LC_ALL=C.UTF-8

# Do not need to specify base modules: i18n, readline, regexp, syscalls.
# The dirkey module currently can only be built on Windows/Cygwin/MinGW.
# The editor module is not in good enough shape to use.
# The matlab, netica, and oracle modules require proprietary code to build.
# The queens module is intended as an example only, not for actual use.
./configure --prefix=%{_prefix} \
            --libdir=%{_libdir} \
            --mandir=%{_mandir} \
            --docdir=%{_docdir}/clisp-%{version} \
            --fsstnd=redhat \
            --hyperspec=http://www.lispworks.com/documentation/HyperSpec/ \
            --with-module=bindings/glibc \
            --with-module=clx/new-clx \
            --with-module=dbus \
            --with-module=fastcgi \
            --with-module=gdbm \
            --with-module=gtk2 \
            --with-module=pcre \
            --with-module=postgresql \
            --with-module=rawsock \
            --with-module=zlib \
            --cbcx \
            build \
            CFLAGS="%{optflags} -Wa,--noexecstack" \
            LDFLAGS="-Wl,--as-needed -Wl,-z,relro -Wl,-z,noexecstack" \
%if %{with check}
            %{nil}
%else
            ||:
%endif

make -C build

%install
ulimit -s unlimited
rm -rf %{buildroot}
make -C build DESTDIR=%{buildroot} install
rm -f %{buildroot}%{_docdir}/clisp-%{version}/doc/clisp.{dvi,1,ps}
cp -p doc/mop-spec.pdf %{buildroot}%{_docdir}/clisp-%{version}/doc
cp -p doc/*.png %{buildroot}%{_docdir}/clisp-%{version}/doc
cp -p doc/Why-CLISP* %{buildroot}%{_docdir}/clisp-%{version}/doc
cp -p doc/regexp.html %{buildroot}%{_docdir}/clisp-%{version}/doc
find %{buildroot}%{_libdir} -name '*.dvi' | xargs rm -f
%find_lang %{name}
%find_lang %{name}low
cat %{name}low.lang >> %{name}.lang

## ad-hoc fix <BTS:VineLinux:825>: '--vimdir' option is broken...
%__mkdir_p %{buildroot}%{_sysconfdir}/vim
%__mv %{buildroot}%{_datadir}/vim/vimfiles/after %{buildroot}%{_sysconfdir}/vim

%clean
rm -rf %{buildroot}


%files -f %{name}.lang
%defattr(-,root,root,-)
%{_bindir}/%{name}
%{_bindir}/%{name}-link
%{_mandir}/man1/*
%{_libdir}/%{name}-%{version}+
%{_datadir}/aclocal/*.m4
%{_datadir}/emacs/site-lisp/*
%{_sysconfdir}/vim
%doc %{_docdir}/clisp-%{version}

%changelog
* Sat Nov 02 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.49.93-1
- updated tarball from git (2.49.93+).
- replaced patches from rawhide.

* Fri Jul 31 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 2.49-3
- rebuild with readline-6.3
- add Patch0,1,2 from suse
- remove BuildRequires: postgresql-devel
- add BuildRequires: libpq-devel, openssl-devel

* Fri Mar 23 2012 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.49-2
- rebuild with current ffcall

* Tue Apr 19 2011 IWAI, Masaharu <iwai@alib.jp> 2.49-1
- new upstream release
- ad-hoc fix <BTS:VineLinux:825>: but '--vimdir' option is broken...

* Tue Apr 12 2011 Shu KONNO <owa@bg.wakwak.com> 2.48-2
- rebuilt with postgresql-9.0.3

* Sat Mar  6 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.48-1
- new upstream release
- built with new toolchain, libsigsegv-2.8
- updated build dependencies

* Sun Sep 21 2008 Shu KONNO <owa@bg.wakwak.com> 2.43-1vl5
- applied new versioning policy, spec in utf-8

* Mon Nov 26 2007 Shu KONNO <owa@bg.wakwak.ne.jp> 2.43-0vl1
- version up to 2.43
- updated source url
- changed %%{_libdir}/clisp to %%{_libdir}/clisp-%%{version}
- added option "--libdir=%%{_libdir}" to configure for lib64

* Sun Mar 18 2007 USAMI Kosuke <usami-k@yc5.so-net.ne.jp> 2.41-0vl1
- version up to 2.41
- add BuildRequires : readline-devel, gettext, libsigsegv-devel
- update %%description, %%files, configure options
- drop hfs patch

* Tue Jan  6 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.32-0vl1
- version up to 2.32
- rebuild with new toolchains
- updated hfs patch

* Sun Aug 25 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- version up to 2.29

* Sat Mar 9 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- version up to 2.28
- added BuildRequires : ncurses-devel and removed groff patch

* Fri Jan 18 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- create rpm for release 2.27
