##
##  emacs.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_emacs  24.5
%define       V_subdir 24.5
%define       V_leim   21.4

#   package information
Name:         emacs
Summary:      GNU Emacs Text Editor
URL:          http://www.gnu.org/software/emacs/
Vendor:       Richard Stallmann et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Editor
License:      GPL
Version:      %{V_emacs}
Release:      20150823

#   package options
%option       with_leim      no

#   list of sources
Source0:      http://ftp.gnu.org/gnu/emacs/emacs-%{V_emacs}.tar.gz
Source1:      http://ftp.gnu.org/gnu/emacs/leim-%{V_leim}.tar.gz
Patch0:       emacs.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, binutils, texinfo
PreReq:       OpenPKG, openpkg >= 20160101

%description
    The popular GNU Emacs text editor, an extensible, customizable,
    self-documenting real-time display editor. GNU Emacs at its core
    is powered by an interpreter for Emacs Lisp, a dialect of the Lisp
    programming language with extensions to support text editing.

%track
    prog emacs = {
        version   = %{V_emacs}
        url       = http://ftp.gnu.org/gnu/emacs/
        regex     = emacs-(__VER__)\.tar\.gz
    }
    prog emacs:leim = {
        version   = %{V_leim}
        url       = http://ftp.gnu.org/gnu/emacs/
        regex     = leim-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n emacs-%{V_subdir}
%if "%{with_leim}" == "yes"
    %setup -q -n emacs-%{V_subdir} -T -D -b 1
%endif
    %patch -p0

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;/${version}/;/;g' \
        -e 's;/${version};;g' \
        -e 's;/${configuration};;g' \
        configure
%if "%{with_leim}" == "yes"
    %{l_shtool} subst \
        -e 's;/${version}/;/;g' \
        leim/Makefile.in
%endif
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --infodir=%{l_prefix}/info \
        --with-x-toolkit=no \
        --without-file-notification \
        --without-compress-install \
        --without-dbus \
        --without-xml2 \
        --without-gnutls \
        --without-zlib \
        --without-x

    #   build program
    cmd="%{l_make} %{l_mflags -O}"
    if [ ".`uname -s`" = .Linux ] && %{l_shtool} path -s setarch; then
        #   work-around conflicting Exec-shield security feature
        cmd="setarch i386 $cmd"
    fi
    eval $cmd

%install
    #   install program
    %{l_make} %{l_mflags} install DESTDIR="$RPM_BUILD_ROOT"

    #   strip down installation files
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/emacs-%{version}
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/rcs-checkin
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/[ce]tags
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/[ce]tags.1
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/b2m
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/var
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/icons
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/applications
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/libexec/emacs/* >/dev/null 2>&1 || true

    #   rearrange and strip down info pages
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    mv $RPM_BUILD_ROOT%{l_prefix}/info $RPM_BUILD_ROOT%{l_prefix}/info.old
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/info
    mv $RPM_BUILD_ROOT%{l_prefix}/info.old/emacs* $RPM_BUILD_ROOT%{l_prefix}/info/
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/info.old

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

