## START: Set by rpmautospec
## (rpmautospec version 0.2.6)
%define autorelease(e:s:pb:) %{?-p:0.}%{lua:
    release_number = 36;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{?dist}
## END: Set by rpmautospec

Name:           e00compr
Version:        1.0.1
# Unless upstream accepts Source1, we will need to maintain an soversion
# downstream.
%global downstream_soversion 0.1
%global soversion %{downstream_soversion}
Release:        %autorelease
Summary:        Library to compress and uncompress E00 files

License:        MIT
URL:            http://avce00.maptools.org/e00compr
Source0:        http://avce00.maptools.org/dl/e00compr-%{version}.tar.gz
# Build a shared library instead of a static one, and version it with an
# appropriate SONAME.
#
# New account creation is broken on upstream bug tracker
# http://bugzilla.maptools.org/; Makefile.shared sent upstream by email
# 2022-01-05.
Source1:        Makefile.shared

# Fix possible buffer overflow due to strncpy() not null-terminating when it
# truncates:
#
# New account creation is broken on upstream bug tracker
# http://bugzilla.maptools.org/; patch sent upstream by email 2022-01-05.
Patch:          e00compr-1.0.1-strncpy-null-term.patch

# Unused variable
#
# New account creation is broken on upstream bug tracker
# http://bugzilla.maptools.org/; patch sent upstream by email 2022-01-05.
Patch:          e00compr-1.0.1-nDigits-unused.patch

BuildRequires:  gcc
BuildRequires:  make

BuildRequires:  dos2unix

Requires:       e00compr-libs%{?_isa} = %{version}-%{release}
Requires:       e00compr-tools%{?_isa} = %{version}-%{release}

%global common_description %{expand:
E00compr is an ANSI C library that reads and writes Arc/Info compressed E00
files. Both “PARTIAL” and “FULL” compression levels are supported.

This package can be divided in three parts:

  • The ‘e00conv’ command-line program. This program takes a E00 file as input
    (compressed or not) and copies it to a new file with the requested
    compression level (NONE, PARTIAL or FULL).

  • A set of library functions to read compressed E00 files. These functions
    read a E00 file (compressed or not) and return a stream of uncompressed
    lines, making the E00 file appear as if it was not compressed.

  • A set of library functions to write compressed E00 files. These functions
    take one line after another from what should be a uncompressed E00 file,
    and write them to a file with the requested compression level, either NONE,
    PARTIAL or FULL.}

%description %{common_description}

This is a metapackage that installs both the command-line tools
(e00compr-tools) and the libraries (e00compr-libs).


%package libs
Summary:        Libraries for e00compr

%description libs %{common_description}

The e00compr-libs package contains the e00compr libraries.


%package devel
Summary:        Development files for e00compr

Requires:       e00compr-libs%{?_isa} = %{version}-%{release}

%description devel %{common_description}

The e00compr-devel package contains libraries and header files for developing
applications that use e00compr.


%package tools
Summary:        Command-line tools associated with e00compr

Requires:       e00compr-libs%{?_isa} = %{version}-%{release}

%description tools
This package provides the ‘e00conv’ command-line program, which takes a E00
file as input (compressed or not) and copies it to a new file with the
requested compression level (NONE, PARTIAL or FULL).


%prep
%autosetup
dos2unix *.TXT *.txt
# Nothing in this package is a script; nothing should be executable.
find . -type f -perm /0111 -exec chmod -v a-x '{}' '+'

# Header name conflict with cpl (cpl_error.h)
# http://bugzilla.maptools.org/show_bug.cgi?id=2367
# Use actual header file locations in examples.
# Leave the upstream locations in the documentation since it assumes developers
# will use a static library or possibly copy sources into a dependent project’s
# source tree.
sed -r -i 's@"(e00compr)\.h"@<\1/\1.h>@' ex_*.c

# New account creation is broken on upstream bug tracker
# http://bugzilla.maptools.org/; suggested creation of a separate file by email
# to upstream on 2022-01-05.
awk 'toupper($0) ~ /(COPYRIGHT|LICENSE)/ { o=1 }; /[-]{3,}/ { o=0 }; o' \
    README.TXT | tee LICENSE

# Unless upstream accepts Source1, we will need to maintain an soversion
# downstream. Replace the suggested “1” with an “earlier” downstream version.
cp -p '%{SOURCE1}' Makefile.shared
sed -r -i 's/(SOVER=[[:blank:]]*)1/\1%{downstream_soversion}/' Makefile.shared


%build
%set_build_flags
%make_build \
    CC="${CC-gcc}" \
    CFLAGS="${CFLAGS}" \
    LFLAGS="${LDFLAGS}" \
    -f Makefile.shared


%install
# Upstream Makefile lacks an “install” target.
# Header name conflict with cpl (cpl_error.h)
# http://bugzilla.maptools.org/show_bug.cgi?id=2367
install -t '%{buildroot}%{_includedir}/e00compr' -D -p -m 0644 *.h
install -t '%{buildroot}%{_mandir}/man1' -D -p -m 0644 e00conv.1
install -d '%{buildroot}%{_libdir}'
# Use cp with an extra option, instead of install, to preserve symlinks
cp -p --no-dereference *.so *.so.* '%{buildroot}%{_libdir}'
install -t '%{buildroot}%{_bindir}' -D -p e00conv


%files
# Metapackage


%files libs
%license LICENSE
%doc README.TXT
%doc HISTORY.TXT
%{_libdir}/libe00compr.so.%{soversion}


%files tools
%doc e00compr.txt
%doc e00compr.html
%{_bindir}/e00conv
%{_mandir}/man1/e00conv.1.*

%files devel
# Examples:
%doc ex_*.c
%{_includedir}/e00compr
%{_libdir}/libe00compr.so


%changelog
* Fri Jul 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-36
- Fix duplicate, rather than symlinked, shared library

* Fri Jul 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-35
- Fix extra newline in description

* Fri Jul 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-34
- Output LICENSE contents when creating it

* Fri Jul 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-33
- Fix a typo in a spec file comment

* Fri Jul 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-32
- Stop numbering patches

* Tue Feb 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-31
- Initial EPEL9 package (no static library)

* Tue Feb 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> 1.0.1-30
- Add a note about when to drop the static library

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 1.0.1-29
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Wed Jan 05 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.0.1-26
- Build a shared library in addition to the static one; add a build conditional
  to disable the static library when dependent packages are ready
- Re-organize the contents into subpackages (add -libs and -tools, and let the
  base package be a metapackage).
- Better respect distribution build flags
- Fix a possible buffer overflow and patch an unused variable

* Wed Jul 21 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-25
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

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

* Mon Jul 27 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-23
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Tue Jan 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-22
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Wed Jul 24 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-21
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Thu Jan 31 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-20
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Mon Jul 23 2018 Volker Fröhlich <volker27@gmx.at> - 1.0.1-19
- Add BR gcc in the wake of the removal of gcc from the builroot

* Thu Jul 12 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-18
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

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

* Wed Aug 02 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-16
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

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

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

* Wed Feb 03 2016 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Wed Jun 17 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Sat Aug 16 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Wed Feb 13 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Wed Jul 18 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Tue Feb 28 2012 Volker Fröhlich <volker27@gmx.at> - 1.0.1-6
- Solve header name conflicts with cpl
- Update header location in example files and documentation

* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.1-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Sat Nov 05 2011 Volker Fröhlich <volker27@gmx.at> - 1.0.1-4
- Remove isa macro from virtual provide
- Devel doesn't require the base package, and ships the license text too

* Thu Oct 30 2011 Volker Fröhlich <volker27@gmx.at> - 1.0.1-3
- Build with fPIC

* Thu Oct 27 2011 Volker Fröhlich <volker27@gmx.at> - 1.0.1-2
- Add isa macro to provide

* Mon Oct 17 2011 Volker Fröhlich <volker27@gmx.at> - 1.0.1-1
- Initial package for Fedora