##
##  glib.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_major  2.77
%define       V_minor  3

#   package information
Name:         glib
Summary:      The Gtk Utility Library
URL:          http://www.gtk.org/
Vendor:       The Gtk Project
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Algorithm
License:      GPL
Version:      %{V_major}.%{V_minor}
Release:      20230903

#   package options
%option       with_threads  yes

#   list of sources
Source0:      http://download.gnome.org/sources/glib/%{V_major}/glib-%{version}.tar.xz
Patch0:       glib.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, python, make, pkgconfig, meson, ninja
PreReq:       OpenPKG, openpkg >= 20160101, python
BuildPreReq:  gettext, libiconv, pcre, pcre::with_utf8 = yes, libffi, zlib
PreReq:       gettext, libiconv, pcre, pcre::with_utf8 = yes, libffi, zlib

%description
    GLib is the low-level core library that originally was split out
    from Gtk+. It provides data structure handling for C, portability
    wrappers, and interfaces for such runtime functionality as an event
    loop, threads, dynamic loading, and an object system.

%track
    prog glib = {
        version   = %{version}
        url       = http://download.gnome.org/sources/glib/%{V_major}/
        regex     = glib-(__VER__)\.tar\.(gz|bz2|xz)
    }

%prep
    %setup -q -n glib-%{version}
    %patch -p0

%build
    #   configure package
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    meson build \
        --prefix %{l_prefix} \
        --buildtype release \
        --default-library static \
        --backend ninja \
        -Dxattr=false \
        -Ddtrace=false \
        -Dlibmount=disabled \
        -Dinstalled_tests=false \
        -Dman=false \
        -Dnls=disabled \
        -Dselinux=disabled

    #   build package
    ninja -C build

%install
    #   install package
    DESTDIR=$RPM_BUILD_ROOT ninja -C build install

    #   strip down installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/glib-2.0
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/gdb
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/bash-completion
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

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

%files -f files

%clean

