# This SPEC file come from GNU Parted Project(git://git.savannah.gnu.org/parted.git)
# Default to disabling device-mapper and SELinux
%define use_devmapper 0
%define use_selinux 0
%define use_sepol 0

# Enable device-mapper support if we find devmapper
%define use_devmapper %(pkg-config --libs devmapper >/dev/null 2>&1; [ $? -eq 0 ] && echo 1)

# Enable SELinux if we find libselinux and libsepol
%define use_selinux %([ -r %{_libdir}/libselinux.a ] && echo 1)
%define use_sepol %([ -r %{_libdir}/libsepol.so ] && echo 1)

Summary:   The GNU disk partition manipulation program
Name:      parted
Version:   3.3
Release:   7
URL:       https://www.gnu.org/software/parted/
Source0:   ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz
Source1:   ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz.sig
License:   GPLv3+

BuildRequires: e2fsprogs-devel e2fsprogs xfsprogs readline-devel ncurses-devel gettext-devel python3 gperf
BuildRequires: autoconf automake libtool gettext-devel texinfo pkgconfig gcc make bc dosfstools gnupg2 device-mapper-devel
BuildRequires: libblkid-devel >= 2.17
BuildRequires: device-mapper-devel, libselinux-devel libsepol-devel

Patch0000: 0000-Switch-gpt-header-move-and-msdos-overlap-to-python3.patch 
Patch6000: 6000-add-support-of-gpt_sync_mbr.patch
Patch9000: 9000-Add-extra-judgment-for-a-partition-created-success.patch
Patch9001: 9001-bugfix-parted-fix-failure-of-mklabel-gpt_sync_mbr.patch
Patch9002: 9002-Fix-end_input-usage-in-do_resizepart.patch
Patch9003: 9003-parted-remove-patch-which-modifid-cyl-size.patch
Patch9004: 9004-libparted-Fix-potential-NULL-dereference-in-ped_disk.patch

%description
The GNU Parted program allows you to create, destroy, resize, move,
and copy hard disk partitions. Parted can be used for creating space
for new operating systems, reorganizing disk usage, and copying data
to new hard disks.

%package devel
Summary:  Files for developing apps which will manipulate disk partitions
Requires: %{name} = %{version}-%{release}
%description devel
The GNU Parted library is a set of routines for hard disk partition
manipulation. If you want to develop programs that manipulate disk
partitions and filesystems using the routines provided by the GNU
Parted library, you need to install this package.

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

%build
autoreconf
autoconf
%configure \
   --enable-shared \
%if "%{use_devmapper}" == "1"
   --enable-device-mapper \
%else
   --disable-devmapper \
%endif
%if "%{use_selinux}" == "1" && "%{use_sepol}" == "1"
   --enable-selinux \
%else
   --disable-selinux \
%endif
   --enable-part-static \
   --enable-Werror=no \
   --disable-dynamic-loading \
   --disable-gcc-warnings

%{disable_rpath}
%{__make} %{?_smp_mflags}

%install
%{__rm} -rf %{buildroot}
%{__make} install DESTDIR=%{buildroot}
%{delete_la_and_a}
%{__rm} -rf %{buildroot}%{_infodir}/dir
%find_lang %{name}

%clean
%{__rm} -rf %{buildroot}

%check
export LD_LIBRARY_PATH=$(pwd)/libparted/.libs:$(pwd)/libparted/fs/.libs
make check

%post
if [ -f %{_infodir}/parted.info.gz ]; then
    /sbin/install-info %{_infodir}/parted.info.gz %{_infodir}/dir || :
fi

%preun
if [ $1 = 0 ]; then
    /sbin/install-info --delete %{_infodir}/parted.info.gz %{_infodir}/dir >/dev/null 2>&1 || :
fi

%postun -p /sbin/ldconfig

%files -f %{name}.lang
%license COPYING
%doc README doc/API doc/FAT
%{_sbindir}/parted
%{_sbindir}/partprobe
%{_libdir}/libparted*.so.*
%{_mandir}/man8/parted.8.gz
%{_mandir}/man8/partprobe.8.gz
%{_infodir}/parted.info.gz

%files devel
%{_includedir}/parted
%{_libdir}/libparted*.so
%{_libdir}/pkgconfig/libparted*.pc

%changelog
* Fri Mar 29 2024 Deyuan Fan  <fandeyuan@kylinos.cn> - 3.3-7
- libparted: Fix potential NULL dereference in ped_disk_next_partition

* Tue May 18 2021 wuguanghao<wuguanghao3@huawei.com> - 3.3-6
- remove patch which modifid cyl-size

* Tue Feb 9 2021 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 3.3-5
- fix end input usage in do_resizepart

* Tue Feb 9 2021 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 3.3-4
- set release num to 4 for CI

* Sat Jun 20 2020 fuyangqing<fuyangqing@huawei.com> - 3.3-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: add parted.gz.sig file in source tag

* Sat Mar 14 2020 hy-euler <eulerstoragemt@huawei.com> - 3.3-2
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: delete -Sgit in %autosetup

* Wed Feb 19 2020 hy-euler <eulerstoragemt@huawei.com> - 3.3-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:Add check part and enable pc98 in spec file

* Sat Jan 11 2020 openEuler Buildteam <buildteam@openeuler.org> - 3.3-0
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update package from 3.2 to 3.3

* Tue Dec 31 2019 openEuler Buildteam <buildteam@openeuler.org> - 3.2-39
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:delete unused file

* Sat Sep 21 2019 suweifeng <suweifeng1@huawei.com> - 3.2-38
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:License update

* Mon Sep 09 2019 suweifeng <suweifeng1@huawei.com> - 3.2-37
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:openEuler Debranding

* Tue Aug 20 2019 luoshijie<luoshijie1@huawei.com> - 3.2-36.h5
- Type:bugfix
- ID:NA
- SUG:restart
- DESC:change name of patch.

* Wed May 8 2019 louhongxiang<louhongxiang@huawei.com> - 3.2-36.h4
- Type:bugfix
- ID:NA
- SUG:restart
- DESC:change name of patch.

* Thu Mar 21 2019 louhongxiang<louhongxiang@huawei.com> - 3.2-36.h3
- Type:bugfix
- ID:NA
- SUG:restart
- DESC:add support for gpt_sync_mbr and fix failure of it.

* Wed Mar 20 2019 yanghua<yanghua21@huawei.com> - 3.2-36.h2
- Type:bugfix
- ID:NA
- SUG:restart
- DESC:parted fix crash due to improper partition number in
       parted fix wrong error label jump in mkpart
       clean the disk information when commands fail in int
       libparted Fix ending CHS address in PMBR
       Fix the length of several strncpy calls
       parted.c Always free peek_word
       parted.c Make sure dev_name is freed
       Fix potential command line buffer overflow

* Fri Jan 25 2019 Xiaoqi Guo<guoxiaoqi2@huawei.com> - 3.2-36.h1
- Type:new-packages
- ID:NA
- SUG:NA
- DESC:add patches, include
  huawei-bugfix-Add-extra-judgment-for-a-partition-created-success.patch
  huawei-bugfix-add-support-of-gpt_sync_mbr.patch


* Tue Mar 13 2007 David Cantrell <dcantrell@redhat.com>
- Updated spec file

* Mon Mar 13 2000 Fabian Emmes <fab@orlen.de>
- changed "unset LINGUAS" line
- reintroduced %build section ;)
- started changelog
