# Testsuite is CPU and disk space intensive, partially also just broken
%{!?testsuite: %global testsuite 1}

Summary:        Utility to clone and restore a partition
Name:           partclone
Version:        0.3.12
Release:        4
# Partclone itself is GPLv2+ but uses other source codes, breakdown:
# GPLv3+: fail-mbr/fail-mbr.S
# GPLv2 and GPLv2+: src/btrfs*
# GPL+ and GPLv2 and GPLv2+ and LGPLv2 and LGPLv2+: src/xfs*
# GPLv2 and GPLv2+: src/f2fs*
# GPLv2+: src/{dd,extfs,fat,hfsplus,minix,nilfs,ntfsclone-ng,part}clone*
# GPLv2+: src/{{fuseimg,info,main,ntfsfixboot,readblock}.c,progress*}
# LGPLv2+: src/gettext.h
# Unused source code (= not built): src/{exfat,jfs,reiser,ufs,vmfs}*
License:        GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2 and LGPLv2+
URL:            http://partclone.org/
Source0:        https://github.com/Thomas-Tsai/partclone/archive/%{version}/%{name}-%{version}.tar.gz
Patch0: 	partclone-0.3.12-gcc10.patch
#https://github.com/Thomas-Tsai/partclone/commit/5c2f2fc71e6d4569bc94c4d6c265a01a5ef6bf1a
Patch1:         Apply-suggestoin-about-wprintw-and-autoupdate-from-Geroges.pacth
BuildRequires:  gcc
BuildRequires:  libuuid-devel
BuildRequires:  fuse-devel
BuildRequires:  ncurses-devel
BuildRequires:  openssl-devel
BuildRequires:  e2fsprogs-devel
BuildRequires:  ntfs-3g-devel
BuildRequires:  libblkid-devel
%if 0%{?testsuite}
BuildRequires:  e2fsprogs
BuildRequires:  ntfsprogs
BuildRequires:  dosfstools
BuildRequires:  hfsplus-tools
%endif
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  gettext-devel

%description
Partclone provides utilities to clone and restore used blocks on a partition
and is designed for higher compatibility of the file system by using existing
libraries, e.g. e2fslibs is used to read and write the ext2 partition.

%prep
%autosetup -p1
autoreconf -i -f

%build
# /usr/include/asm/types.h:31 and xfs/platform_defs.h:50 try both to define
# umode_t, reported: https://github.com/Thomas-Tsai/partclone/issues/96

%configure \
  --enable-extfs \
  --enable-xfs \
  --disable-reiserfs \
  --disable-reiser4 \
  --enable-hfsp \
  --enable-fat \
  --disable-exfat \
  --enable-f2fs \
  --disable-nilfs2 \
  --enable-ntfs \
  --disable-ufs \
  --disable-vmfs \
  --disable-jfs \
  --enable-btrfs \
  --enable-minix \
  --enable-ncursesw \
  --enable-fs-test
# https://forum.slitaz.org/topic/parclone-needs-to-be-rebuilded
sed -i 's|exit 1|exit 0|' fail-mbr/compile-mbr.sh

%make_build

%install
%make_install

# Building fail-mbr.bin requires a compiler that can build x86 binaries
%ifnarch %{ix86} x86_64
rm -rf $RPM_BUILD_ROOT%{_datadir}/%{name}/
%endif

%find_lang %{name}

%if 0%{?testsuite}
%check
# Patch proposal submitted: https://github.com/Thomas-Tsai/partclone/issues/103
sed -e 's/256/1440/' -i tests/_common

# Tests for Btrfs, XFS and F2FS filesystems are broken on all architectures
sed -e 's/^\(am__append_2 = btrfs.test\)/#\1/' \
    -e 's/^\(am__append_6 = xfs.test\)/#\1/' \
    -e 's/^\(am__append_8 = f2fs.test\)/#\1/' \
    -e 's/^\(am__append_11 = btrfs.test\)/#\1/' \
    -i tests/Makefile

# NILFS2 tests must be run as root (mockbuild is unprivileged)
sed -e 's/^\(am__append_13 = nilfs2.test\)/#\1/' \
    -i tests/Makefile

# Tests for FAT and HFS+ filesystems are broken on ppc64 and s390x
%ifarch ppc64 s390x
sed -e 's/^\(am__append_3 = fat.test\)/#\1/' \
    -e 's/^\(am__append_5 = hfsplus.test\)/#\1/' \
    -i tests/Makefile
%endif


make check || (cat tests/test-suite.log; exit 1)
%endif

%files -f %{name}.lang
%license COPYING
%doc AUTHORS ChangeLog
%{_sbindir}/%{name}.*
%ifarch %{ix86} x86_64
%{_datadir}/%{name}/
%endif
%{_mandir}/man8/%{name}*.8*

%changelog
* Thu Mar 10 2022 liyanan <liyanan32@huawei.com> - 0.3.12-4
- Fix build error

* Tue Aug 3 2021 weidong <weidong@uniontech.com> - 0.3.12-3
- Fix link failuer with gcc-10

* Fri Nov 6 2020 weidong <weidong@uniontech.com> - 0.3.12-2
- Modify buildrequires 

* Fri Aug 7 2020 weidong <weidong@uniontech.com> - 0.3.12-1
- Initial release for OpenEuler
