##
##  geoip.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_api_c   1.6.12
%define       V_api_pl  1.51

#   package information
Name:         geoip
Summary:      Geographic IP Resolution
URL:          http://www.maxmind.com/app/geolitecity
Vendor:       MaxMind
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Mapping
License:      GPL
Version:      %{V_api_c}
Release:      20180118

#   package options
%option       with_perl   no

#   list of sources
Source0:      https://github.com/maxmind/geoip-api-c/releases/download/v%{V_api_c}/GeoIP-%{V_api_c}.tar.gz
Source1:      http://www.cpan.org/modules/by-module/Geo/Geo-IP-%{V_api_pl}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  zlib
PreReq:       zlib
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-openpkg
PreReq:       perl
%endif

%description
    Geo-IP enables you to easily lookup countries by IP addresses, even
    when Reverse DNS entries don't exist. The Geo-IP database contains
    IP Network Blocks as keys and countries as values, covering every
    public IP address.

%track
    prog geoip = {
        version   = %{version}
        url       = https://github.com/maxmind/geoip-api-c/releases
        regex     = GeoIP-(__VER__)\.tar\.gz
    }
    prog geoip:perl = {
        version   = %{V_api_pl}
        url       = http://www.cpan.org/modules/by-module/Geo/
        regex     = Geo-IP-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n GeoIP-%{V_api_c}
%if "%{with_perl}" == "yes"
    %setup -q -T -D -a 1 -n GeoIP-%{V_api_c}
%endif
    %{l_shtool} subst \
        -e 's;-Wall;;g' \
        -e 's;-ansi;;g' \
        Makefile.in */Makefile.in

%build
    echo "ac_cv_func_gethostbyname_r=no" >config.cache
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-lz" \
    AUTOCONF="true" \
    AUTOMAKE="true" \
    AUTOHEADER="true" \
    ACLOCAL="true" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/geoip \
        --mandir=$RPM_BUILD_ROOT%{l_prefix}/man \
        --disable-shared
    %{l_make} %{l_mflags}
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_prefix}/bin/perl-openpkg -d Geo-IP-%{V_api_pl} --verbose \
        --args LIBS="-L../libGeoIP/.libs" \
        --args INC="-I../libGeoIP" \
        configure build
%endif

%install
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix} \
        $RPM_BUILD_ROOT%{l_prefix}/man \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -d Geo-IP-%{V_api_pl} install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/etc/geoip/GeoIP.conf.default
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

