Blob Blame Raw
# Bootstrap option, we have to build astrometry before we can generate index
# files, but later package will require them for tests at build time
%global bootstrap 1


Name:           astrometry
Version:        0.72
Release:        2%{?dist}
Summary:        Blind astrometric calibration of arbitrary astronomical images

# Software is BSD with some GPL code
# https://groups.google.com/forum/#!topic/astrometry/9GgP7rj4Y-g
# Here we asked to fix source headers:
# https://groups.google.com/forum/#!topic/astrometry/mCuyze3TOeM
# 
# Licensing breakdown
# ===================
#
# See also: file CREDITS in source folder
#
# General license for astrometry code: 3-clause BSD
#
# GPLv2+:
#    qfits-an/*
#    include/astrometry/qfits*
#    catalogs/ucac4-fits.h
#    libkd/an-fls.h
#    util/makefile.jpeg
#    util/md5.c
#    Makefile
#    doc/UCAC3_guide/* (not used for build and not shipped)
#    doc/UCAC4_guide/* (not used for build and not shipped)
#
# GPLv3+:
#    blind/an_mm_malloc.h
#    util/ctmf.c
#
License:        BSD and GPLv2+ and GPLv3+
URL:            http://www.astrometry.net

# Upstream sources contains nonfree stuff so we must clean them
# Download original sources from:
# Source0:        http://astrometry.net/downloads/%%{name}.net-%%{version}.tar.gz
# Then use the provided script to clean them with
# ./generate-tarball %%{version}
Source0:        %{name}.net-%{version}-clean.tar.xz
Source1:        %{name}-generate-tarball.sh

# Patches from Ole Streicher <olebole@debian.org> used on Debian to
#  * disable build of nonfree stuff removed from sources
#  * have a proper versioned soname
#  * use system libraries properly
#  * use dynamical linking
Patch0:         %{name}-Add-SONAME-to-libastrometry.so.patch
Patch1:         %{name}-Dynamically-link-to-libastrometry.so-when-possible.patch
Patch2:         %{name}-Fix-issues-when-using-Debian-libs-instead-of-convienience.patch
Patch3:         %{name}-Call-python-scripts-as-modules-instead-of-executables.patch
Patch4:         %{name}-Don-t-install-non-free-files-images-and-NGC2000.0-catalog.patch


BuildRequires:  netpbm-devel
BuildRequires:  python2-numpy
BuildRequires:  python2-astropy
BuildRequires:  python2-devel
BuildRequires:  swig
BuildRequires:  xorg-x11-proto-devel

BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(cairo)
BuildRequires:  pkgconfig(cfitsio)
BuildRequires:  pkgconfig(fontconfig)
BuildRequires:  pkgconfig(gsl)
BuildRequires:  pkgconfig(libjpeg)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(wcslib)
BuildRequires:  pkgconfig(xrender)
BuildRequires:  pkgconfig(zlib)

%if ! 0%{?bootstrap}
BuildRequires:  astrometry-tycho2
%endif

Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       netpbm-progs
Requires:       python2-%{name} = %{version}-%{release}

# User could use own set of index files or another set from upstream.
# Therefore we recommend and not require astrometry-tycho2 here
Recommends:     astrometry-tycho2

%description
The astrometry engine will take any image and return the astrometry
world coordinate system (WCS), a standards-based description of the
transformation between image coordinates and sky coordinates.

Other tools included in the astrometry package can do much more, like
plotting astronomic information over solved images, convertion utilities
or generate statistics from FITS images.


%package devel
Summary:        Development files for %{name}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description devel
%{summary}

%package libs
Summary:        Libraries for %{name}

%description libs
Libraries for %{name}

%package -n python2-%{name}
Summary:        Python modules from %{name}
Requires:       python2-astropy
Provides:       %{name}-python2 = %{version}-%{release}
Obsoletes:      %{name}-python2 < %{version}-%{release}

%description -n python2-%{name}
%{summary}


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

# Fix Wrong FSF address - reported upstream
# https://groups.google.com/forum/#!topic/astrometry/mCuyze3TOeM
grep -rl '59 Temple Place, Suite 330, Boston, MA  02111-1307  USA' * | xargs -i@ sed -i 's/59 Temple Place, Suite 330, Boston, MA  02111-1307  USA/51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA./g' @


%build
# Weird symlink required... (also in upstream git)
ln -sf . astrometry

# Astrometry doesn't automatically find netpbm
export NETPBM_INC=-I%{_includedir}/netpbm
export NETPBM_LIB="-L%{_libdir} -lnetpbm"

# Apply mandatory ld flags
export LDFLAGS="%__global_ldflags"

# Parallel make flags on break build
make SYSTEM_GSL=yes all py extra ARCH_FLAGS="%{optflags}"


%install
%{make_install} SYSTEM_GSL=yes \
                INSTALL_DIR=%{buildroot}%{_prefix} \
                PY_BASE_INSTALL_DIR=%{buildroot}%{python2_sitearch}/%{name} \
                INCLUDE_INSTALL_DIR=%{buildroot}%{_includedir}/%{name} \
                LIB_INSTALL_DIR=%{buildroot}%{_libdir} \
                BIN_INSTALL_DIR=%{buildroot}%{_bindir} \
                DATA_INSTALL_DIR=%{buildroot}%{_datadir}/%{name}/data \
                PY_BASE_LINK_DIR=%{python2_sitearch}/%{name} \
                ETC_INSTALL_DIR=%{buildroot}%{_sysconfdir} \
                MAN1_INSTALL_DIR=%{buildroot}%{_mandir}/man1 \
                DOC_INSTALL_DIR=%{buildroot}%{_docdir}/%{name} \
                EXAMPLE_INSTALL_DIR=%{buildroot}%{_datadir}/%{name}/examples

# We need to correct the data dir link in config file
sed -i \
    "s:%{buildroot}%{_prefix}/data:%{_datadir}/%{name}/data:" \
    %{buildroot}/etc/astrometry.cfg

# Rename generic named executables with known conflict
pushd %{buildroot}%{_bindir}
for exec in tabmerge tablist; do
        mv $exec astrometry-$exec
done
popd


# Remove unuseful file
rm -f %{buildroot}%{_docdir}/%{name}/report.txt

# We don't ship static libraries so we remove them
rm -f %{buildroot}%{_libdir}/*.a

# Fix wrong python interpreter
pushd %{buildroot}%{_bindir}
for exec in degtohms image2pnm removelines text2fits hmstodeg votabletofits uniformize merge-columns; do
        sed -i "s,/usr/bin/env python,%{__python2},g" $exec
done
popd
find %{buildroot}/%{python2_sitearch}/%{name} -name '*.py' | xargs sed -i '1s|^#!.*|#!%{__python2}|'

# LICENSE file is managed by %%license scriptlet
rm -f %{buildroot}%{_docdir}/%{name}/LICENSE


%check
make test ARCH_FLAGS="%{optflags}"


%post libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig


%files
%doc CREDITS README.md
%license LICENSE
%{_mandir}/man1/*
%{_bindir}/*
%exclude %{_bindir}/*.py
%dir %{_datadir}/astrometry
%dir %{_datadir}/astrometry/data
%{_datadir}/astrometry/examples
%config(noreplace) %{_sysconfdir}/astrometry.cfg

%files devel
%{_includedir}/*
%{_libdir}/*.so

%files libs
%license LICENSE
%{_libdir}/*.so.*

%files -n python2-%{name}
%{python2_sitearch}/*
%{_bindir}/*.py

%changelog
* Mon Sep 25 2017 Christian Dersch <lupinix@mailbox.org> - 0.72-2
- Move libs to subpackage to be multiarch compatible

* Tue Sep 12 2017 Christian Dersch <lupinix@mailbox.org> - 0.72-1
- Initial SCM import (#1470436)

* Wed Jul 12 2017 Christian Dersch <lupinix@mailbox.org> - 0.72-0.1
- initial spec (using the packaging effort from Mattia Verga, RHBZ  #1299139)