##
##  mm.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_mm        1.4.2
%define       V_ipc_mm    0.03
%define       V_ipc_mma   0.59009

#   package information
Name:         mm
Summary:      Shared Memory Allocation Library
URL:          http://www.ossp.org/pkg/lib/mm/
Vendor:       Ralf S. Engelschall
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Libraries
License:      BSD
Version:      1.4.2
Release:      20181229

#   package options
%option       with_perl  no

#   list of sources
Source0:      http://www.ossp.org/pkg/lib/mm/mm-%{V_mm}.tar.gz
Source1:      http://www.cpan.org/authors/id/A/AC/ACHOUNG/IPC-MM-%{V_ipc_mm}.tar.gz
Source2:      http://www.cpan.org/authors/id/M/MA/MACKENNA/IPC-MMA-%{V_ipc_mma}.tar.gz
Patch0:       mm.patch

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

%description
    OSSP mm is a 2-layer abstraction library which simplifies the usage
    of shared memory between forked (and this way strongly related)
    processes under Unix platforms. On the first layer it hides all
    platform dependent implementation details (allocation and locking)
    when dealing with shared memory segments and on the second layer it
    provides a high-level malloc(3)-style API for a convenient and well
    known way to work with data-structures inside those shared memory
    segments.

%track
    prog mm = {
        version   = %{V_mm}
        url       = http://www.ossp.org/pkg/lib/mm/
        regex     = mm-(__VER__)\.tar\.gz
    }
    prog mm:IPC-MM = {
        version   = %{V_ipc_mma}
        url       = http://www.cpan.org/authors/id/A/AC/ACHOUNG/
        regex     = IPC-MM-(__VER__)\.tar\.gz
    }
    prog mm:IPC-MMA = {
        version   = %{V_ipc_mma}
        url       = http://www.cpan.org/authors/id/M/MA/MACKENNA/
        regex     = IPC-MMA-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %patch -p0
    %{l_shtool} subst \
        -e '/LINENO: error: C[+]* preprocessor/{N;N;N;N;s/.*/:/;}' \
        configure
%if "%{with_perl}" == "yes"
    %{l_shtool} subst \
        -e 's;`mm-config --cflags`;"-I..";' \
        -e 's;`mm-config --ldflags`;"-L../.libs";' \
        -e 's;`mm-config --libs`;"-lmm";' \
        IPC-MM-%{V_ipc_mm}/Makefile.PL
%endif

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    GREP="grep" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --disable-shared \
        --enable-batch
    %{l_make} %{l_mflags -O}
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_prefix}/bin/perl-openpkg -d IPC-MM-%{V_ipc_mm}   configure build
    %{l_prefix}/bin/perl-openpkg -d IPC-MMA-%{V_ipc_mma} configure build
%endif

%install
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -d IPC-MM-%{V_ipc_mm}   install
    %{l_prefix}/bin/perl-openpkg -d IPC-MMA-%{V_ipc_mma} install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

