Name:			supernovas-libs
Version:		1.0.1
Release:		1%{?dist}
Summary:		The Naval Observatory's NOVAS C astronomy library, made better 
Group:			Development/Libraries
License:		Unlicense
URL:			https://smithsonian.github.io/SuperNOVAS/
Source0:		https://github.com/Smithsonian/SuperNOVAS/archive/refs/tags/v%{version}.tar.gz
BuildRequires:		gcc

BuildRequires:		gcc-gfortran
BuildRequires:		sed

%description

Runtime libraries and data for the SuperNOVAS C/C++ astronomy library.

SuperNOVAS is a C/C++ astronomy software library, providing high-precision 
astronomical calculations such as one might need for running an observatory or 
a precise planetarium program. It is a fork of the Naval Observatory Vector 
Astrometry Software (NOVAS) C version 3.1, providing bug fixes and making it 
easier to use overall.

The main goal of SuperNOVAS is to improve usability, add new features, promote 
best practices, and provide accessible documentation -- all while retaining 
100% API compatibility with NOVAS C 3.1. Thus, if you have written code for 
NOVAS C 3.1, it should readily work with SuperNOVAS also.

SuperNOVAS is entirely free to use without licensing restrictions. Its source 
code is compatible with the C90 standard, and hence should be suitable for old 
and new platforms alike. It is light-weight and easy to use, with full support 
for the IAU 2000/2006 standards for sub-micro-arc-second position calculations.



%prep
%setup -q -n SuperNOVAS-%{version}

%build

CIO_LOCATOR_FILE=%{_datadir}/supernovas/cio_ra.bin

# ----------------------------------------------------------------------------
# Future build for SuperNOVAS > 1.0.1
#
#make lib/supernovas.so
#make lib/solsys1.so
#make lib/solsys2.so
#
# ----------------------------------------------------------------------------
# BEGIN is build for v1.0.1

# We'll modify the build configuration, saving the original first
cp config.mk config.bak

# Specify where the cio_ra.bin file will be installed
sed -i "s:/user/share/novas/cio_ra.bin:%{_datadir}/supernovas/cio_ra.bin:g" config.mk

# Use externally defined CFLAGS
sed -i "s:CFLAGS = -Os -Wall -I$(INC):CFLAGS += -I$(INC):g " config.mk

# Set soname to 'libsupernovas.so.1.x.x'
sed -i "s:-shared -fPIC:-shared -fPIC -Wl,-soname,libsupernovas.so.%{version} $(LDFLAGS):g" Makefile

# build lib/novas.so
make %{?_smp_mflags} shared
mv lib/novas.so lib/supernovas.so

# solsys1 and solsys2 legacy libs
echo "CFLAGS += -shared -fPIC" >> config.mk
make %{?_smp_mflags} solsys

# Manual build solsys1.so and solsys2.so for packaging
gcc -o lib/solsys1.so obj/solsys1.o obj/eph_manager.o -shared -fPIC -Wl,-soname,libsolsys1.so.%{version} $(LDFLAGS)
gcc -o lib/solsys2.so obj/solsys2.o obj/jplint.o -shared -fPIC -Wl,-soname,libsolsys2.so.%{version} $(LDFLAGS)

mv config.bak config.mk

# END is build for v1.0.1
# ----------------------------------------------------------------------------

# make share/cio_ra.bin
make %{?_smp_mflags} bin/cio_file
mkdir -p share
bin/cio_file data/CIO_RA.TXT share/cio_ra.bin


%install
rm -rf %{buildroot}

# Install libsupernovas.so.1 runtime library
mkdir -p %{buildroot}/%{_libdir}

# libsupernovas.so...
install -m 755 lib/supernovas.so %{buildroot}/%{_libdir}/libsupernovas.so.%{version}

# Link libsopernovas.so.1.x.x -> libsupernovas.so.1
( cd %{buildroot}/%{_libdir} ; ln -sf libsupernovas.so.{%version} libsupernovas.so.1 )

# libsolsys1.so
install -m 755 lib/solsys1.so %{buildroot}/%{_libdir}/libsolsys1.so.%{version}

# Link libsolsys1.so.1.x.x -> libsolsys1.so.1
( cd %{buildroot}/%{_libdir} ; ln -sf libsolsys1.so.{%version} libsolsys1.so.1 )

# libsolsys2.so
install -m 755 lib/solsys2.so %{buildroot}/%{_libdir}/libsolsys2.so.%{version}

# Link libsolsys2.so.1.x.x -> libsolsys2.so.1
( cd %{buildroot}/%{_libdir} ; ln -sf libsolsys2.so.{%version} libsolsys2.so.1 )

# Install runtime CIO locator data 
mkdir -p %{buildroot}/%{_datadir}/supernovas
install -m 644 share/cio_ra.bin %{buildroot}/%{_datadir}/supernovas/cio_ra.bin


%files
%license LICENSE
%{_libdir}/libsupernovas.so.1{,.*}
%{_libdir}/libsolsys1.so.1{,.*}
%{_libdir}/libsolsys2.so.1{,.*}
%{_datadir}/supernovas/*

%changelog
%autochangelog