##
##  apt.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_base 0.5.15
%define       V_rev  3.2

#   package information
Name:         apt
Summary:      Advanced Packaging Tool
URL:          http://apt-rpm.org/
Vendor:       Jason Gunthorpe et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Bootstrapping
License:      GPL
Version:      %{V_base}.%{V_rev}
Release:      20080101

#   list of sources
Source0:      http://apt-rpm.org/releases/apt-%{V_base}lorg%{V_rev}.tar.bz2
Source1:      apt.conf
Source2:      sources.list
Source3:      vendors.list
Source4:      translate.list
Source5:      rpmpriorities
Source6:      preferences
Source7:      apt-man.tar
Patch0:       apt.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, autoconf, pkgconfig
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  ncurses, readline, libxml
PreReq:       ncurses, readline, libxml

%description
    This is Connectiva's port of the Debian's Advanced Packaging Tool
    (APT), running on top of the OpenPKG RPM packaging infrastructure.
    APT is an advanced package management utility front-end which allows
    you to easily perform package installation, upgrading and removal.
    Dependencies are automatically handled.

%track
    prog apt = {
        version   = %{V_base}lorg%{V_rev}
        url       = http://apt-rpm.org/releases/
        regex     = apt-(__VER__lorg__VER__)\.tar\.bz2
    }

%prep
    %setup -q -n apt-%{V_base}lorg%{V_rev}
    %patch -p0

    #   replace hard-coded paths with OpenPKG ones
    l_rpmlibs_base="`%{l_rpm_config} --libs`"
    l_rpmlibs_extra=""
    case "%{l_platform -t}" in
        *sunos* ) l_rpmlibs_extra="${l_rpmlibs_extra} -lsocket" ;;
    esac
    find . -type f ! -name "*.orig" -print | \
    xargs %{l_shtool} subst -s \
        %{l_value -s l_prefix} \
        -e "s;@l_rpmlibs_base@;${l_rpmlibs_base};g" \
        -e "s;@l_rpmlibs_extra@;${l_rpmlibs_extra};g"

    #   regenerate GNU autoconf based files
    %{l_prefix}/bin/autoconf

%build
    #   configure package
    defines="-DOLD_FLATSCHEME"
    case "%{l_platform -t}" in
        *sunos* ) defines="$defines -DOPENPKG_SOLARIS" ;;
    esac
    CC="%{l_cc}" \
    CPPFLAGS="%{l_cppflags} `%{l_rpm_config} --cppflags` $defines" \
    CFLAGS="%{l_cflags} `%{l_rpm_config} --cflags`" \
    LDFLAGS="%{l_ldflags} `%{l_rpm_config} --ldflags`" \
    RPM_PATH="%{l_rpm}" \
    ./configure \
        --prefix=%{l_prefix} \
        --libdir=%{l_prefix}/lib \
        --localstatedir=%{l_prefix}/var/apt \
        --disable-shared \
        --enable-static \
        --disable-nls \
        --disable-docs

    #   disable localization stuff
    %{l_shtool} subst \
        -e 's;^POFILES =.*$;POFILES =;g' \
        -e 's;^GMOFILES =.*$;GMOFILES =;g' \
        -e 's;^DUMMYPOFILES =.*$;DUMMYPOFILES =;g' \
        -e 's;^CATALOGS =.*$;CATALOGS =;g' \
        po/Makefile

    #   disable some libtool specials
    %{l_shtool} subst \
        -e "s;--tag=CC;;g" \
        -e "s;--tag=CXX;;g" \
        apt-pkg/Makefile \
        cmdline/Makefile \
        lua/Makefile \
        methods/Makefile \
        tools/Makefile

    #   build package
    %{l_make} %{l_mflags}

%install

    #   install package
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT

    #   create still missing directories
    %{l_shtool} mkdir -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/apt/scripts \
        $RPM_BUILD_ROOT%{l_prefix}/var/apt/lib/lists/partial \
        $RPM_BUILD_ROOT%{l_prefix}/var/apt/cache/archives/partial

    #   install pre-generated manual pages
    %{l_tar} xf %{SOURCE apt-man.tar}
    %{l_shtool} mkdir -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man5 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8
    %{l_shtool} install -c -m 644 \
        apt-man/*.5 $RPM_BUILD_ROOT%{l_prefix}/man/man5/
    %{l_shtool} install -c -m 644 \
        apt-man/*.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/

    #   install default configuration files
    %{l_shtool} mkdir -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/apt.conf.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/vendor.list.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/sources.list.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/translate.list.d
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE apt.conf} %{SOURCE rpmpriorities} %{SOURCE preferences} \
        %{SOURCE sources.list} %{SOURCE vendors.list} %{SOURCE translate.list} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/
    %{l_shtool} install -c -m 644 \
        doc/examples/configure-index \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apt/apt.conf.idx

    #   strip down installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/charset.alias
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/lib/apt/methods/* >/dev/null 2>&1 || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/apt/apt.conf*' \
        '%config %{l_prefix}/etc/apt/rpmpriorities' \
        '%config %{l_prefix}/etc/apt/preferences' \
        '%config %{l_prefix}/etc/apt/*.list'

%files -f files

%clean

