##
##  apg.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 information
Name:         apg
Summary:      Automated Password Generator
URL:          http://www.adel.nursat.kz/apg/
Vendor:       Adel I. Mirzazhanov
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        System
License:      GPL
Version:      2.2.3
Release:      20170414

#   list of sources
Source0:      http://www.adel.nursat.kz/apg/download/apg-%{version}.tar.gz
Patch0:       apg.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101

%description
    Automated Password Generator is a set of tools for random password
    generation including a standalone password generator, an RFC972
    password generation server, and a client for the password generation
    server. These feature a built-in X9.17 random number generator, and
    35 modes of password generation, including pronounceable password
    generation.

%track
    prog apg = {
        disabled
        comment   = "homepage is gone"
        version   = %{version}
        url       = http://www.adel.nursat.kz/apg/download.shtml
        regex     = apg-(\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q
    chmod 755 . */. */*/. */*/*/.
    %patch -p0
    %{l_shtool} subst -s -e 's/^#.*include.*syslog\.h.*$//' apg.c
    %{l_shtool} subst -s -e 's/syslog.*LOG_.*;\(.*\)$/;\1/' apg.c errors.c
    %{l_shtool} subst -s -e 's/openlog.*;\(.*\)$/;\1/' apg.c
    %{l_shtool} subst -s -e 's/closelog.*;\(.*\)$/;\1/' apg.c

%build
    libs=""
    defs=""
    case "%{l_platform -t}" in
        *-freebsd*  ) libs="" ;;
        *-linux*    ) libs="-lnsl" ;;
        *-sunos5.6* ) libs="-lnsl -lsocket"; defs="-DNEED_SOCKLEN_T" ;;
        *-sunos5*   ) libs="-lnsl -lsocket" ;;
        *-irix*     ) libs="-lnsl -lsocket"; defs="-DNEED_SOCKLEN_T" ;;
        *-darwin*   )
            libs=""
            %{l_shtool} subst \
                -e '/^LIBS =/s/-lcrypt//' \
                Makefile
            ;;
    esac
    %{l_make} %{l_mflags -O} all \
        CC="%{l_cc}" \
        FLAGS="%{l_cflags -O} $defs" \
        CS_LIBS="$libs"

%install
    CHOWNPROG=true \
    CHGRPPROG=true \
    %{l_make} ${l_mflags} install INSTALL_PREFIX=$RPM_BUILD_ROOT%{l_prefix}
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/*  >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

