File mapserver.spec of Package mapserver

# spec file for package mapserver 7.0 series
# this build respect python,java,perl,php,ruby openSUSE package naming convention
# Copyright (c) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2016 Ioda-Net Sàrl, Charmoille, Switzerland. Bruno Friedmann (tigerfoot)
# Copyright (c) 2016 Angelos Tzotsos (kalxas)
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

#SONAME has been pushed to 2
%define libname libmapserver2
%define soversion 2
%define python_sitearch %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")
%define _cgibindir /srv/www/cgi-bin

# tricks to remove the --no-as-needed -Wl flag on 13.1+
%if 0%{?suse_version} >= 1320

Name:           mapserver
Version:        7.0.4
Release:        0
Summary:        Environment for building spatially-enabled internet applications
License:        MIT
Group:          Productivity/Networking/Web/Servers
# wget
# get ride of any trouble created by GMT in App:Geo
%if 0%{?suse_version} >= 1330
BuildRequires:  libpsl-devel
BuildRequires:  FastCGI-devel
BuildRequires:  cairo-devel
BuildRequires:  chrpath
BuildRequires:  cmake >= 2.4
BuildRequires:  freetype2
BuildRequires:  freetype2-devel
BuildRequires:  fribidi-devel
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  gd-devel >= 2.0.16
BuildRequires:  giflib-devel
BuildRequires:  harfbuzz-devel
BuildRequires:  krb5-devel
BuildRequires:  libcurl-devel
BuildRequires:  libcurl4
BuildRequires:  libexpat-devel
# BuildRequires:  libgcj-devel
BuildRequires:  gdal-devel
BuildRequires:  geos-devel
BuildRequires:  libjpeg-devel
BuildRequires:  libpng-devel
BuildRequires:  libproj-devel
BuildRequires:  librsvg-devel
BuildRequires:  libtiff-devel
BuildRequires:  libxml2-devel
BuildRequires:  libxslt-devel
BuildRequires:  mysql-devel
# BuildRequires:  libjpeg8-devel I've normally use that one ?
BuildRequires:  openjpeg2-devel
BuildRequires:  pam
BuildRequires:  pam-devel
BuildRequires:  perl(ExtUtils::MakeMaker)
BuildRequires:  postgresql-devel >= 9.1
BuildRequires:  postgis-devel >= 9.1
BuildRequires:  readline-devel
BuildRequires:  rpm
BuildRequires:  swig
BuildRequires:  update-alternatives
# BuildRequires:  v8-devel upstream dependency are too strict
# see
BuildRequires:  zlib-devel
Requires:       %{libname} = %{version}-%{release}
Requires:       FastCGI
Requires:       fribidi
# Added proj due to missing espg tools for shp2img for example
# Let try with rpm smarter :-)
# Requires:       libproj
#@TODO : we should normally only require client & libs for database
Requires:       mysql-client
Requires:       postgresql >= 9.1
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} != 1010
BuildRequires:  xorg-x11-libXpm-devel

Mapserver is an internet mapping program that converts GIS data to
map images in real time. With appropriate interface pages,
Mapserver can provide an interactive internet map based on
custom GIS data.

%package -n %{libname}
Summary:        Mapsserver library for mapserver or mapscript module
Group:          Development/Libraries/C and C++

%description -n %{libname}
Mapserver library for mapserver or mapscript module. you need this lib to run
mapserver or any of the mapscript module (php, java, python, ruby)

# We don't require apache2_mod-php5 users could have php5 running
# with other modes (cgi, php-fpm etc)

%package -n php-mapscript
Summary:        PHP/Mapscript map making extensions to PHP
Group:          Development/Libraries/PHP
Requires:       %{libname} = %{version}-%{release}
Provides:       php-mapserver = %{version}-%{release}
Obsoletes:      php-mapserver < %{version}-%{release}
%if 0%{?sles_version} >= 11
BuildRequires:  php53-devel
Requires:       php53
Requires:       php53-gd
BuildRequires:  php-devel
Requires:       php
Requires:       php-gd

%description -n php-mapscript
The PHP/Mapscript extension provides full map customization capabilities within
the PHP scripting language.

%package -n perl-mapscript
Summary:        Perl/Mapscript map making extensions to Perl
Group:          Development/Languages/Perl
BuildRequires:  perl(ExtUtils::MakeMaker)
BuildRequires:  perl-base
Requires:       %{libname} = %{version}-%{release}
Requires:       perl-base
Provides:       mapserver-perl = %{version}-%{release}
Obsoletes:      mapserver-perl < %{version}-%{release}

%description -n perl-mapscript
The Perl/Mapscript extension provides full map customization capabilities
within the Perl programming language.

%package -n python-mapscript
Summary:        Python/Mapscript map making extensions to Python
Group:          Development/Languages/Python
BuildRequires:  python-devel
Requires:       %{libname} = %{version}-%{release}
Requires:       python-base
Provides:       mapserver-python = %{version}-%{release}
Obsoletes:      mapserver-python < %{version}-%{release}

%description -n python-mapscript
The Python/Mapscript extension provides full map customization capabilities
within the Python programming language.

%package -n libjavamapscript
Summary:        Java/Mapscript map making extensions to Java
Group:          Development/Languages/Java
BuildRequires:  java >= 1.6
BuildRequires:  java-devel >= 1.6
BuildRequires:  swig
Requires:       %{libname} = %{version}-%{release}
Requires:       java >= 1.6
Requires:       swig
Provides:       java-mapscript = %{version}-%{release}
Provides:       mapserver-java = %{version}-%{release}
Obsoletes:      mapserver-java < %{version}-%{release}
Obsoletes:      java-mapscript < %{version}-%{release}
%if 0%{?sles_version} == 10
%ifarch i586
BuildRequires:  java-1_5_0-ibm-alsa

%description -n libjavamapscript
The Java/Mapscript extension provides full map customization capabilities
within the Java programming language.

%package -n ruby-mapscript
Summary:        Ruby/Mapscript map making extensions to Ruby
Group:          Development/Languages/Ruby
BuildRequires:  ruby-devel
BuildRequires:  ruby-macros
Requires:       %{libname} = %{version}-%{release}
Requires:       ruby
Provides:       mapserver-ruby = %{version}-%{release}
Obsoletes:      mapserver-ruby < %{version}-%{release}

%description -n ruby-mapscript
The Ruby/Mapscript extension provides full map customization capabilities
within the Ruby programming language.

#%%package -n v8-mapscript
#Summary:        V8 Javascript/Mapscript map making extensions to Javascript
#Group:          Development/Languages/Javascript
#BuildRequires:  v8-devel
#Requires:       %%{libname} = %%{version}-%%{release}
#Requires:       v8
#Provides:       mapserver-v8 = %%{version}-%%{release}
#Obsoletes:      mapserver-v8 < %%{version}-%%{release}
#%%description -n v8-mapscript
#The V8 Javascript Mapscript extension provides full map customization
#capabilities within the javascript programming language.

%package	devel
Summary:        Mapserver development files
Group:          Development/Libraries/Other
Requires:       %{name} = %{version}-%{release}

%description	devel
The Mapserver development package provides necessary files to build
against the C Mapserver library.

%setup -q -n %{name}-%{version}
# Now cleanup rights and chmod
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;

%build -n %{name}-%{version}

#Pre export the PREFIX ( having it on the command line doesn't expand correctly for
# dynamic postgresql location
export CMAKE_PREFIX_PATH="%{_includedir}:%{_includedir}/fastcgi:%(pg_config --includedir):%(pg_config --includedir-server):%(pg_config --libdir)"
export CFLAGS="%{optflags} -fno-strict-aliasing"
export CXXFLAGS="%{optflags} -fno-strict-aliasing"

%if 0%{?suse_version} == 1310
# Make things more secure, but only on 13.1 (by default on 13.2+)
export LDFLAGS="-Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro,-z,now -pie"
export CFLAGS="%{optflags} -fno-strict-aliasing -fPIE -pie"
export CXXFLAGS="%{optflags} -fno-strict-aliasing -fPIE -pie"


# specify all options and play with true/false
# so we always know which option are included in our build.

%cmake \
  -DLOCALSTATEDIR=%{_localstatedir} \
  -DINSTALL_LIB_DIR=%{_libdir} \
  -DCMAKE_C_FLAGS_RELEASE="%{optflags} -fno-strict-aliasing" \
  -DCMAKE_CXX_FLAGS_RELEASE="%{optflags} -fno-strict-aliasing" \
  -DCMAKE_BUILD_TYPE="Release" \
  -DCUSTOM_PERL_SITE_ARCH_DIR="%{perl_vendorarch}" \

make VERBOSE=1 %{?_smp_mflags}

# Can't be run msautotest is another git subrepo
# make test


mkdir -p %{buildroot}%{_sbindir}
mkdir -p %{buildroot}%{_cgibindir}
mkdir -p %{buildroot}%{_libdir}/php5/extensions
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{python_sitearch}/
mkdir -p %{buildroot}%{_includedir}/%{name}

# fix some exec bits essentially on examples to make rpmlint happy
# and avoid rpm adding require
find ./mapscript/ -type f -iname "*.p[ly]" -exec chmod -x {} \;
find ./mapscript/ -type f -iname "*.rb" -exec chmod -x {} \;
find ./mapscript/ -type f -iname "*.dist" -exec chmod -x {} \;

pushd build
make DESTDIR="%{buildroot}" install %{?_smp_mflags}

mkdir -p %{buildroot}%{_sysconfdir}/php5/conf.d/
cat > %{buildroot}%{_sysconfdir}/php5/conf.d/mapscript.ini <<EOF
; Enable %{name} extension module
; For 7.x we name the symlink here

# Install our links
#@ todo : check
# Having them as link is good for bytes, but httpd_daemon should allow
# reading those symlinks which is not the default

cd %{buildroot}%{_cgibindir}
ln -s ../../..%{_bindir}/mapserv mapserv
ln -s ../../..%{_bindir}/legend legend
ln -s ../../..%{_bindir}/scalebar scalebar

# remove vera fonts, these are provided system wide
#@TODO then we should patch the fonts file example
rm -rfv ./tests/vera

%post -n %{libname} -p /sbin/ldconfig

%postun -n %{libname} -p /sbin/ldconfig

%doc symbols
%doc fonts

%files -n %{libname}

%files -n php-mapscript
%doc mapscript/php/README
%doc mapscript/php/examples
%config(noreplace) %{_sysconfdir}/php5/conf.d/mapscript.ini

%files -n perl-mapscript
%doc mapscript/perl/examples
%dir %{perl_vendorarch}/auto/mapscript

%files -n python-mapscript
%doc mapscript/python/README
%doc mapscript/python/examples
%doc mapscript/python/tests

%files -n libjavamapscript
%doc mapscript/java/README
%doc mapscript/java/examples
%doc mapscript/java/tests

%files -n ruby-mapscript
%doc mapscript/ruby/README
%doc mapscript/ruby/examples

#%%files -n v8-mapscript
#%%doc mapscript/v8/README
#%%doc mapscript/v8/examples

%files devel
%dir %{_includedir}/mapserver
%dir %{_datadir}/mapserver