%{!?make_build:   %global make_build   make %{?_smp_mflags}}
%{!?make_install: %global make_install make install DESTDIR=%{buildroot} INSTALL="/usr/bin/install -p"}

%if 0%{?rhel} && 0%{?rhel} < 7
%global dts devtoolset-7-
%endif

Name:           m4acut
Version:        0.1.2
Release:        0%{?dist}.2sunshine
Summary:        Losslessly & gaplessly cut m4a (AAC in MP4) files
License:        zlib and BSD with advertising
URL:            https://github.com/nu774/m4acut
Source0:        https://github.com/nu774/m4acut/archive/v%{version}.tar.gz#/m4acut-%{version}.tar.gz
Patch0:         https://github.com/nu774/m4acut/commit/ef9083beea6b8268d011932a93233f0dc48e2a01.patch
Patch1:         https://github.com/nu774/m4acut/commit/01815e910d705b3a057519ec54c0bb4cc9de5b96.patch
Patch2:         https://github.com/nu774/m4acut/commit/aab0f02721f3f3bf5debfc2da2de25d603f69078.patch
BuildRequires:  %{?dts}gcc, %{?dts}gcc-c++
BuildRequires:  autoconf, automake
BuildRequires:  make
BuildRequires:  l-smash-devel >= 1.10.0

%description
m4acut reads M4A files and extracts a portion of the audio into a new file.
When chapter mode is specified, it can automatically extract each chapter
into files, setting title tag and track tag from chapter title/number.

Since m4acut takes priming/padding samples into account and writes
iTunSMPB tag properly, m4acut allows any cut point (not restricted to
AAC frame boundaries) and the resulting files can be played gaplessly.

%prep
%if 0%{?autosetup}
%autosetup
%else
%setup -q
%patch0 -p1
%patch1 -p1
%endif

%build
autoreconf --install

%if 0%{?rhel} && 0%{?rhel} < 7
%{?dts:. /opt/rh/devtoolset-7/enable}
%endif

%configure
%make_build

%install
%make_install

%files
%{!?_licensedir:%global license %%doc}
%doc README
%license COPYING
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1*

%changelog
* Mon Feb 22 2021 Moritz Barsnick <moritz+rpm@barsnick.net> 0.1.2-0.2sunshine
- BR: devtoolset-7 for RHEL6, for proper C++11 support

* Sun Feb 21 2021 Moritz Barsnick <moritz+rpm@barsnick.net> 0.1.2-0.1sunshine
- initial RPM