From 60da8389480c97030df12de84d923cbd58e91a8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Persson?= <Bjorn@Rombobjörn.se>
Date: Sat, 19 Dec 2015 21:31:50 +0100
Subject: [PATCH 1/2] Added a -static subpackage for linking GPRbuild
 statically.

---
 xmlada-2015-disable_static.patch | 58 ----------------------------------------
 xmlada.spec                      | 54 ++++++++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 71 deletions(-)
 delete mode 100644 xmlada-2015-disable_static.patch

diff --git a/xmlada-2015-disable_static.patch b/xmlada-2015-disable_static.patch
deleted file mode 100644
index 655fb36..0000000
--- a/xmlada-2015-disable_static.patch
+++ /dev/null
@@ -1,58 +0,0 @@
-diff --git a/Makefile.in b/Makefile.in
-index 3ebb2d4..1cc50fd 100644
---- a/Makefile.in
-+++ b/Makefile.in
-@@ -1,7 +1,7 @@
- ## The type of library we want to build. Possible values:
- ##   relocatable
- ##   static
--LIBRARY_TYPE=static
-+LIBRARY_TYPE=relocatable
- 
- # Replace with the location for the installation directory
- PACKAGE_TARNAME=@PACKAGE_TARNAME@
-@@ -42,16 +42,8 @@ GPROPTS+=--target=${TARGET}
- IPREFIX=${prefix}/${TARGET}
- endif
- 
--ifeq (${BUILDS_SHARED},yes)
--all: static relocatable
--install: install-clean install-static install-relocatable
--else
--all: static
--install: install-clean install-static
--endif
--
--static:
--	${GPRBUILD} -m -p -XLIBRARY_TYPE=static ${GPROPTS} xmlada.gpr
-+all: relocatable
-+install: install-clean install-relocatable
- 
- shared relocatable:
- 	${GPRBUILD} -m -p -XLIBRARY_TYPE=relocatable ${GPROPTS} xmlada.gpr
-@@ -92,16 +84,6 @@ ifneq (,$(wildcard $(IPREFIX)/$(PSUB)/manifests/xmlada_schema))
- 		--project-subdir=$(PSUB) xmlada_unicode
- endif
- 
--## Do the installation for an explicit target
--install-static:
--	${GPRINSTALL} -f -p -XLIBRARY_TYPE=static ${GPROPTS} \
--		--prefix=${IPREFIX} --project-subdir=$(PSUB) \
--		--build-var=XMLADA_BUILD --build-name=static xmlada.gpr
--	${CP} distrib/xmlada.gpr ${IPREFIX}/$(PSUB)
--ifneq (${OS},Windows_NT)
--	${CHMOD} +x ${IPREFIX}/bin/xmlada-config
--	cd ${IPREFIX}/lib; ${CHMOD} a-w xmlada_*/*.ali
--endif
- 
- install-shared install-relocatable:
- 	${GPRINSTALL} -f -p -XLIBRARY_TYPE=relocatable ${GPROPTS} \
-@@ -112,7 +94,7 @@ clean_%: force
- 	gprclean -XLIBRARY_TYPE=$* -q xmlada.gpr
- 	gprclean -XLIBRARY_TYPE=$* -q -XTESTS_ACTIVATED=Yes xmlada.gpr
- 
--clean: clean_relocatable clean_static
-+clean: clean_relocatable 
- 	cd docs; ${MAKE} -e clean
- 
- distclean: clean
diff --git a/xmlada.spec b/xmlada.spec
index 82cffbf..9c6bd17 100644
--- a/xmlada.spec
+++ b/xmlada.spec
@@ -1,6 +1,6 @@
 Name:           xmlada
 Version:        2015
-Release:        7%{?dist}
+Release:        8%{?dist}
 Summary:        XML library for Ada
 Group:          System Environment/Libraries
 License:        GPLv2+
@@ -9,9 +9,8 @@ URL:            http://libre.adacore.com
 ## http://libre.adacore.com/libre/download/
 Source0:        xmlada-gpl-%{version}-src.tar.gz 
 ## Fedora-specific
-Patch1:         %{name}-%{version}-disable_static.patch
 Patch2:         %{name}-%{version}-gprinstall.patch
-BuildRequires:  chrpath  gprbuild
+BuildRequires:  gprbuild
 BuildRequires:  gcc-gnat
 BuildRequires:  fedora-gnat-project-common >= 2 
 # xmlada and gcc-gnat only available on these:
@@ -34,30 +33,47 @@ Requires:       fedora-gnat-project-common >= 2
 %description devel
 Xml library for ada devel package.
 
+
+%package static
+Summary:        XML library for Ada, static libraries
+Group:          Development/Libraries
+Requires:       %{name}-devel%{?_isa} = %{version}-%{release}
+
+%description static
+This package contains the XML/Ada libraries for static linking. It is needed
+for linking GPRbuild statically so that GPRbuild will remain functional when
+libraries are upgraded.
+
+Other Fedora packages shall require xmlada-devel rather than xmlada-static if
+possible.
+
+
 %prep
 %setup -q -n xmlada-gpl-%{version}-src
-%patch1 -p1 
 %patch2 -p1 
 
 %build
-%configure --disable-rpath --enable-shared --disable-static --enable-build=distrib
-make LIBRARY_TYPE=relocatable GPROPTS="%{Gnatmake_optflags}" prefix=%{buildroot}/%{_prefix}
+%configure --disable-rpath --enable-shared --enable-static --enable-build=distrib
+make GPROPTS="%{Gnatmake_optflags}" prefix=%{buildroot}/%{_prefix}
 
 
 %install
 rm -rf %{buildroot}
 ###export GPRINSTALL_OPTS="--build-name=relocatable --lib-subdir=%{buildroot}/%{_libdir}/%{name} --link-lib-subdir=%{buildroot}/%{_libdir} --sources-subdir=%{buildroot}/%{_includedir}/%{name}"
-export GPRINSTALL_OPTS="--build-name=relocatable --lib-subdir=%{buildroot}/%{_libdir}/%{name} --link-lib-subdir=%{buildroot}/%{_libdir} --prefix=%{buildroot}"
-make install LIBRARY_TYPE=relocatable  prefix=%{buildroot}/%{_prefix} GPROPTS="${GPRINSTALL_OPTS}" PSUB="share/gpr"
-## Installing main gpr file
-cp distrib/%{name}.gpr %{buildroot}/%{_GNAT_project_dir}
+export GPRINSTALL_OPTS="--lib-subdir=%{buildroot}/%{_libdir}/%{name} --link-lib-subdir=%{buildroot}/%{_libdir}"
+## Install the shared libraries first and then the static ones, because
+## apparently the variant that gprinstall sees first becomes the default in the
+## project files.
+OS=Windows_NT make install-relocatable install-static prefix=%{buildroot}/%{_prefix} GPROPTS="${GPRINSTALL_OPTS}" PSUB="share/gpr"
+# Setting OS to "Windows_NT" circumvents a hardcoded "lib" in the makefile.
+# This also skips the removal of write permission from the ALI files, so the
+# files section compensates for that.
+
 ## Revoke exec permissions
 find %{buildroot} -name '*.gpr' -exec chmod -x {} \;
 find %{buildroot}%{_docdir} -type f -exec chmod -x {} \;
 ## Delete old bash script (not needed now)
 rm -f %{buildroot}%{_bindir}/xmlada-config
-## delete rpath manually (#674793)
-chrpath --delete %{buildroot}%{_libdir}/%{name}/libxmlada*
 install -d -m 0755 %{buildroot}/%{_libdir}/%{name}/static/
 ## There is not GNAT programming studio in Fedora
 ## To enable GPS plugin delete this string and create subpackage
@@ -66,6 +82,12 @@ rm -f %{buildroot}/%{_libdir}/%{name}/static/*
 ## only-non-binary-in-usr-lib
 cd %{buildroot}/%{_libdir} && ln -s %{name}/lib%{name}*.so.* .
 
+
+%check
+## Verify that there are no runpaths in the compiled libraries.
+%{_rpmconfigdir}/check-rpaths
+
+
 %files 
 %defattr(-,root,root,-)
 %doc README TODO AUTHORS COPYING*
@@ -84,14 +106,20 @@ cd %{buildroot}/%{_libdir} && ln -s %{name}/lib%{name}*.so.* .
 %defattr(-,root,root,-)
 %{_includedir}/%{name}
 %{_GNAT_project_dir}/%{name}*.gpr
-%{_libdir}/%{name}/*.ali
+%attr(444,-,-) %{_libdir}/%{name}/*.ali
 %{_libdir}/%{name}/lib%{name}*.so
 %{_libdir}/lib%{name}*.so
 %{_GNAT_project_dir}/manifests
 
 
+%files static
+%{_libdir}/%{name}/*.a
+
 
 %changelog
+* Sat Dec 19 2015 Björn Persson <Bjorn@Rombobjörn.se> - 2015-8
+- Added a -static subpackage for linking GPRbuild statically.
+
 * Wed Jun 24 2015 Pavel Zhukov <<landgraf@fedoraproject.org>> - 2015-7
 - Remove temporary links
 
-- 
2.5.0

