# By default, dotests are run.
# No tests: rpmbuild -ba --without dotests *.spec
%bcond_without dotests

%global python3_version 3.12

%define _libdir64 %{_prefix}/lib64

%define python64_sitearch %(/opt/freeware/bin/python%{python3_version} -c "import sysconfig; print(sysconfig.get_path('platlib'))")
%define python32_sitearch %(/opt/freeware/libexec/python%{python3_version}_32 -c "import sysconfig; print(sysconfig.get_path('platlib'))")

Name:           libcomps
Version:        0.1.22
Release:        100
Summary:        Comps XML file manipulation library

License:        GPLv2+
Source0:        https://github.com/rpm-software-management/libcomps/archive/refs/tags/libcomps-%{version}.tar.gz

#Source100: %{name}-%{version}-%{release}.build.log

# FNM_CASEFOLD isn't supported on AIX.
Patch0:		%{name}-0.1.11-remove-FNM_CASEFOLD.patch

BuildRequires:  gcc-c++ >= 10.3.0
BuildRequires:  cmake >= 3.31.4
BuildRequires:  gcc >= 10.3.0
BuildRequires:  libxml2-devel >= 2.12.9
BuildRequires:  check-devel >= 0.13.0
BuildRequires:  expat-devel >= 2.6.3
BuildRequires:  zlib-devel >= 1.2.13
Requires:  libxml2 >= 2.12.9
Requires:  expat >= 2.6.3
Requires:   zlib >= 1.2.13
Requires:   libgcc >= 10.3.0

%description
Libcomps is library for structure-like manipulation with content of
comps XML files. Supports read/write XML file, structure(s) modification.

%package devel
Summary:        Development files for libcomps library
Requires:       %{name} = %{version}-%{release}

%description devel
Development files for libcomps library.

%package -n python%{python3_version}-%{name}
Summary:        Python 3 bindings for libcomps library
BuildRequires:  python%{python3_version}-devel >= %{python3_version}.11
BuildRequires:  python%{python3_version} >= %{python3_version}.11
BuildRequires: make
%{?python_provide:%python_provide python3-%{name}}
Requires:       %{name} = %{version}-%{release}
Requires: python%{python3_version} >= %{python3_version}.11
Obsoletes: python3.9-libcomps <= 0.1.15-101 

%description -n python%{python3_version}-%{name}
Python3 bindings for libcomps library.

%package -n python3-%{name}
Summary:        Meta package for Python 3 bindings for libcomps library
Requires:       python%{python3_version}-%{name} = %{version}-%{release}

%description -n python3-%{name}
Meta package for Python3 bindings for libcomps library.

%prep
%autosetup -p1 -n %{name}-%{version}

# Duplicate source for 32 & 64 bits
rm -rf   /tmp/%{name}-%{version}-32bit
cp -pr . /tmp/%{name}-%{version}-32bit
rm -rf ..?* .[!.]* *
mv       /tmp/%{name}-%{version}-32bit 32bit
cp -pr 32bit 64bit

%build


# setup environment for 32-bit and 64-bit builds
export AR="/usr/bin/ar -X32_64"
export NM="/usr/bin/nm -X32_64"

build_libcomps32() {
    mkdir build
    cd build
    cmake ../libcomps \
          -DCMAKE_INSTALL_PREFIX="%{_prefix}" \
          -DCMAKE_INSTALL_LIBDIR="%{_libdir}" \
          -DENABLE_DOCS=OFF \
          -DPYTHON_EXECUTABLE=/opt/freeware/libexec/python%{python3_version}_32 \
          -DPYTHON_DESIRED="3" -DPYTHON_VERSION_MAJOR="3"

    gmake V=1
    cd .. # cd build
}


build_libcomps64() {
    mkdir build
    cd build
    cmake ../libcomps \
          -DCMAKE_INSTALL_PREFIX="%{_prefix}" \
          -DCMAKE_INSTALL_LIBDIR="%{_libdir64}" \
          -DENABLE_DOCS=OFF \
          -DPYTHON_EXECUTABLE=/opt/freeware/bin/python%{python3_version} \
          -DPYTHON_DESIRED="3" -DPYTHON_VERSION_MAJOR="3"

    gmake V=1
    cd .. # cd build
}

cd 64bit
# first build the 64-bit version
export CC="gcc"
export CXX="g++"
export CFLAGS="$CFLAGS_COMMON -maix64 -pthread"
export CXXFLAGS="$CXXFLAGS_COMMON -maix64 -pthread"
export OBJECT_MODE=64
export OBJECT_MODE_LIB=64

export LDFLAGS="-Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib "


build_libcomps64

cd ../32bit
# now build the 32-bit version
export CC="gcc"
export CXX="g++"
export CFLAGS="$CFLAGS_COMMON -D_LARGE_FILES -maix32 -pthread"
export CXXFLAGS="$CXXFLAGS_COMMON -D_LARGE_FILES -maix32 -pthread"
export OBJECT_MODE=32
export OBJECT_MODE_LIB=

export LDFLAGS="-Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000 "

build_libcomps32

%install

# setup environment for 32-bit and 64-bit builds
export AR="/usr/bin/ar -X32_64"
export NM="/usr/bin/nm -X32_64"

cd 64bit
export OBJECT_MODE=64
(
    cd build
    gmake V=1 DESTDIR=${RPM_BUILD_ROOT} install
)

cd ../32bit
export OBJECT_MODE=32
(
    cd build
    gmake V=1 DESTDIR=${RPM_BUILD_ROOT} install
)
cd ..

(
    #%define libsoversion 0.1.15

    # Extract .so from 64bit .a libraries
    cd ${RPM_BUILD_ROOT}%{_libdir64}
    ${AR} -x %{name}.a

    # Create 32 bits libraries with 32/64bit members
    cd ${RPM_BUILD_ROOT}%{_libdir}
    ${AR} -q %{name}.a ${RPM_BUILD_ROOT}%{_libdir64}/%{name}.so.0
    rm ${RPM_BUILD_ROOT}%{_libdir64}/%{name}.so.0

    # Create links for 64 bits libraries
    cd ${RPM_BUILD_ROOT}%{_libdir64}
    rm -f %{name}.a
    ln -sf ../lib/%{name}.a %{name}.a

    cd ${RPM_BUILD_ROOT}%{python64_sitearch}/%{name}/    
    ar -X64 -x _libpycomps.a _libpycomps.so
    rm _libpycomps.a

    cd ${RPM_BUILD_ROOT}%{python32_sitearch}/%{name}/
    ar -X32 -x _libpycomps.a _libpycomps.so
    rm _libpycomps.a
 
)

%check
%if %{without dotests}
echo "*** Skipping tests"
exit 0
%endif # without dotests

run_tests(){
    cd build/tests
    for f in `ls test_*`; do
	./${f}
    done
    cd -
}

cd 64bit
run_tests

cd ../32bit
run_tests

%clean
#[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(-,root,system,-)
%doc 64bit/COPYING 64bit/README.md
%{_libdir}/%{name}.a

%files devel
%defattr(-,root,system,-)
%{_includedir}/%{name}/

%files -n python%{python3_version}-%{name}
%defattr(-,root,system,-)
%{python64_sitearch}/%{name}/
%{python32_sitearch}/%{name}/

%files -n python3-%{name}

%changelog
* Sun Oct 19 2025 Lakshmi Surekha Kovvuri <Lakshmi.Kovvuri@ibm.com> - 0.1.22-100
- Update to latest version 0.1.22.
- Rebuild with Python3.12.

* Tue Jan 24 2023 Sangamesh Mallayya <smallayy@in.ibm.com> - 0.1.15-101
- Rebuild with python3.9.

* Tue Mar 1 2022 Sangamesh Mallayya <smallayy@in.ibm.com> - 0.1.11-100
- Use Release as 100 so that 32 & 64-bit static dependencies can be
- update to this dynamic version.

* Tue Jun 15 2021 Pavla Kratochvilova <pkratoch@redhat.com> - 0.1.17-1
- Update to 0.1.17
- Fix a crash when clearing COMPS_ObjRTree (RhBug:1888343)
- Don't print empty requires
- Fix memory leaks and resource leaks
- Remove Python 2 support

* Thu Jun 03 2021 Python Maint <python-maint@redhat.com> - 0.1.15-7
- Rebuilt for Python 3.10

* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.15-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Fri Aug 07 2020 Nicola Sella <nsella@redhat.com> - 0.1.15-5
- spec: Fix building with new cmake macros

* Sat Aug 01 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.15-4
- Second attempt - Rebuilt for
  https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.15-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Fri May 22 2020 Miro Hrončok <mhroncok@redhat.com> - 0.1.15-2
- Rebuilt for Python 3.9

* Wed Apr 01 2020 Ales Matej <amatej@redhat.com> - 0.1.15-1
- Update to 0.1.15
- Do not skip type=mandatory in xml output (RhBug:1771224)

* Fri Jan 31 2020 Ales Matej <amatej@redhat.com> - 0.1.14-4
- Fix global header variable defined without extern for gcc-10

* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.14-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Sat Dec 14 2019 Jeff Law <law@redhat.com> - 0.1.14-2
- Fix inline vs static inline issue for gcc-10

* Fri Nov 29 2019 Ales Matej <amatej@redhat.com> - 0.1.14-1
- Update to 0.1.14

* Fri Nov 29 2019 Ales Matej <amatej@redhat.com> - 0.1.12-1
- Update to 0.1.12

* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 0.1.11-5
- Rebuilt for Python 3.8.0rc1 (#1748018)

* Thu Aug 15 2019 Miro Hrončok <mhroncok@redhat.com> - 0.1.11-4
- Rebuilt for Python 3.8

* Wed Jul 31 2019 Miro Hrončok <mhroncok@redhat.com> - 0.1.11-3
- Fix Python method descriptors for Python 3.8 (#1734777)

* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.11-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Mon Mar 11 2019 Pavla Kratochvilova <pkratoch@redhat.com> - 0.1.11-1
- Update to 0.1.11

* Wed Feb 13 2019 Pavla Kratochvilova <pkratoch@redhat.com> - 0.1.10-1
- Update to 0.1.10

* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.9-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Tue Nov 27 2018 Marek Blaha <mblaha@redhat.com> - 0.1.8-15
- Disable Python 2 bindings for Fedora >= 30

* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-14
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Fri Jun 15 2018 Miro Hrončok <mhroncok@redhat.com> - 0.1.8-13
- Rebuilt for Python 3.7

* Tue Feb 20 2018 Iryna Shcherbina <ishcherb@redhat.com> - 0.1.8-12
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)

* Wed Feb 07 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Wed Jan 31 2018 Igor Gnatenko <ignatenko@redhat.com> - 0.1.8-10
- Switch to %%ldconfig_scriptlets

* Tue Nov 07 2017 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 0.1.8-9
- Use better Obsoletes for platform-python

* Fri Nov 03 2017 Igor Gnatenko <ignatenko@redhat.com> - 0.1.8-8
- Remove platform-python subpackage

* Fri Sep 01 2017 Igor Gnatenko <ignatenko@redhat.com> - 0.1.8-7
- Disable platform python on old releases

* Thu Aug 10 2017 Lumír Balhar <lbalhar@redhat.com> - 0.1.8-6
- Add Platform Python subpackage (https://fedoraproject.org/wiki/Changes/Platform_Python_Stack)

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

* Wed Jul 26 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Fri Feb 10 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Tue Dec 13 2016 Stratakis Charalampos <cstratak@redhat.com> - 0.1.8-2
- Rebuild for Python 3.6

* Thu Sep 22 2016 Igor Gnatenko <ignatenko@redhat.com> - 0.1.8-1
- Update to 0.1.8

* Tue Aug 09 2016 Igor Gnatenko <ignatenko@redhat.com> - 0.1.7-6
- Add %%{?system_python_abi}

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.1.7-5
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Tue Apr 12 2016 Igor Gnatenko <ignatenko@redhat.com> - 0.1.7-4
- Adopt to new packaging guidelines
- Use %%license macro
- Fix file ownerships

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.7-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Wed Oct 14 2015 Robert Kuska <rkuska@redhat.com> - 0.1.7-2
- Rebuilt for Python3.5 rebuild

* Thu Jul 02 2015 Jindrich Luza <jluza@redhat.com> 0.1.7
- added langpacks to union process
- comps DOCTYPE read-write-read fix
- support biarchonly attribute
- fixed rhbz#1073885 rhbz#1073890 rhbz#1073907 rhbz#1073979
- fix rhbz#1073079
- comps_*_match() now support fnmatching
- added libpycomps.MATCH_IGNORECASE as matching flag
- added group.packages_match
- added comps.groups_match, comps.categories_match, comps.entironments_match
- PyCOMPS_Package hash
- cmake-2.6, python-2.6, RHEL-6 compatible
- '_arch' attribute change to 'arch'
- empty 'arch' attribute will be ommited from output from now

* Wed Jan 29 2014 Jindrich Luza <jluza@redhat.com> 0.1.6
- version bumped
- added libcomps.MDict.keys()
-         libcomps.MDict.values()
-         libcomps.MDict.items()
-         libcomps.MDict.clear()
-         libcomps.MDict.update()
-         libcomps.MDict.copy()
- COMPS_List replaced with COMPS_HSList
- added missing basearchonly to DocGroupPackage
- python3/CMakeLists.txt fixed
- added explicit attributes support for xml options
- added arch_filter test for python
- insert method in libcomps.Sequence
- Unioning is now accomplished with replace x append policy
- Weaker package equality check (comparing only name now)
- Fixed leeks in unioning
- modified test_merge_comps test_libcomps
- dictionaries are now storing keys in alphabetical order
- comps parser redesigned
- change python/tests directory composition
- added elem attributes check in parser
- xml output '_arch' attribute support
- parser and xml output defaults options for specify defaults values
- comps object validation in python
- added validity checker before append/set object to list (python only)
- .validate() method
- added libcomps.Dict.keys
-         libcomps.Dict.values
-         libcomps.Dict.items
-         libcomps.Dict.clear
-         libcomps.Dict.update
-         libcomps.Dict.copy
- added xml output options (comps.xml_str([options = {}]), comps.xml_f(options = {}))

* Wed Oct 23 2013 Jindrich Luza <jluza@redhat.com> 0.1.4-4
- group.uservisible is true by default now.
- fixed comps_mobjradix parent node problem
- implemented bindings for blacklist, whiteout and langpacks
- COMPS_Logger redesigned

* Tue Oct 08 2013 Jindrich Luza <jluza@redhat.com> 0.1.5
- version bump
- PyCOMPS_Sequence.__getitem__["objectid"] implemented for libcomps.GroupList, libcomps.CategoryList, libcomps.EnvList
- added missing files
- missing display_order fix for libcomps.Environment

* Tue Oct 01 2013 Jindrich Luza <jluza@redhat.com> 0.1.4
- added missing files
- architectural redesign finished
- fixed #1003986 by Gustavo Luiz Duarte guidelines (but not tested on ppc)
- fixed bug #1000449
- fixed bug #1000442
- added GroupId.default test
- some minor unreported bugs discovered during testing fixed
- finished default attribute support in groupid object
- Comps.get_last_parse_errors and Comps.get_last_parse_log has been renamed
-   as Comps.get_last_errors and Comps.get_last_log
- version bumped. Python bindings is now easier.
- added missing files

* Tue Aug 20 2013 Jindrich Luza <jluza@redhat.com> 0.1.3
- finished default attribute support in groupid object
- Comps.get_last_parse_errors and Comps.get_last_parse_log has been renamed
-   as Comps.get_last_errors and Comps.get_last_log
- finished default attribute support in groupid object
- Comps.get_last_parse_errors and Comps.get_last_parse_log has been renamed
-   as Comps.get_last_errors and Comps.get_last_log

* Thu Jul 18 2013 Jindrich Luza <jluza@redhat.com> 0.1.2
- automatic changelog system
- fixed issue #14
- libcomps.Dict is now behave more like python dict. Implemented iter(libcomps.Dict)
- libcomps.iteritems() and libcomps.itervalues()
- remaked error reporting system.
-     libcomps.Comps.fromxml_f and libcomps.Comps.fromxml_str now return
-     -1, 0 or 1. 0 means parse procedure completed without any problem,
-     1 means there's some errors or warnings but not fatal. -1 indicates
-     fatal error problem (some results maybe given, but probably incomplete
-     and invalid)
- errors catched during parsing can be obtained by calling
-     libcomps.Comps.get_last_parse_errors
- all log is given by
-     libcomps.Comps.get_last_parse_log
- prop system complete
- fixed issue 1
- fixed issue 3
- added <packagereq requires=...> support
- new prop system in progress....
- separated doc package
- some minor fixes in CMakeFiles
- improved integrated tests

* Tue Jun 25 2013 Jindrich Luza <jluza@redhat.com> 0.1.1-1
- Automatic commit of package [libcomps] release [0.1.1-1].


