File antlr4.spec of Package antlr4

#
# spec file for package antlr4
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 https://bugs.opensuse.org/
#


%define libver 4_7_2
%define runtime_cpp_lib libantlr4-runtime
%define runtime_cpp_libver %{runtime_cpp_lib}%{libver}

Name:           antlr4
Version:        4.7.2
Release:        0
Summary:        Java parser generator
# C# runtime is MIT-licensed, but currently it is not used in this package
License:        BSD-3-Clause
URL:            https://www.antlr.org/
Source0:        https://github.com/antlr/antlr4/archive/%{version}.tar.gz#/antlr4-%{version}.tar.gz
Patch0:         antlr4-install-path.patch
BuildRequires:  cmake >= 3.3.0
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  libstdc++-devel
BuildRequires:  maven-local
BuildRequires:  pkg-config
BuildRequires:  mvn(com.ibm.icu:icu4j)
BuildRequires:  mvn(com.webguys:string-template-maven-plugin)
BuildRequires:  mvn(org.abego.treelayout:org.abego.treelayout.core)
BuildRequires:  mvn(org.antlr:ST4)
BuildRequires:  mvn(org.antlr:antlr-runtime)
BuildRequires:  mvn(org.antlr:antlr3-maven-plugin)
BuildRequires:  mvn(org.apache.felix:maven-bundle-plugin)
BuildRequires:  mvn(org.apache.maven.plugin-tools:maven-plugin-annotations)
BuildRequires:  mvn(org.apache.maven.plugins:maven-plugin-plugin)
BuildRequires:  mvn(org.apache.maven.plugins:maven-source-plugin)
BuildRequires:  mvn(org.apache.maven:maven-plugin-api)
BuildRequires:  mvn(org.apache.maven:maven-project)
BuildRequires:  mvn(org.codehaus.mojo:build-helper-maven-plugin)
BuildRequires:  mvn(org.codehaus.plexus:plexus-compiler-api)
BuildRequires:  mvn(org.codehaus.plexus:plexus-utils)
BuildRequires:  mvn(org.glassfish:javax.json)
BuildRequires:  mvn(org.sonatype.oss:oss-parent:pom:)
BuildRequires:  mvn(org.sonatype.plexus:plexus-build-api)
BuildRequires:  mvn(org.twdata.maven:mojo-executor)
BuildRequires:  pkgconfig(uuid)
#!BuildRequires: stringtemplate4 antlr3-tool

%description
ANTLR (ANother Tool for Language Recognition) is a parser
generator for reading, processing, executing, or translating
structured text or binary files.  It can be used to build languages,
tools, and frameworks. From a grammar, ANTLR generates a parser that
can build and walk parse trees.

%package java
Summary:        ANTLR 4 Java runtime
Provides:       %{name}-runtime = %{version}-%{release}
Obsoletes:      %{name}-runtime < %{version}-%{release}
BuildArch:      noarch

%description java
This package provides Java runtime library used by parsers generated by
ANTLR 4.

%package tool
Summary:        ANTLR 4 Tool
# Explicit requires for javapackages-tools since antlr4-script
# uses /usr/share/java-utils/java-functions
Requires:       javapackages-tools
Provides:       %{name} = %{version}-%{release}
Obsoletes:      %{name} < %{version}-%{release}
BuildArch:      noarch

%description tool
ANTLR (ANother Tool for Language Recognition) is a parser
generator for reading, processing, executing, or translating
structured text or binary files.  It can be used to build languages,
tools, and frameworks. From a grammar, ANTLR generates a parser that
can build and walk parse trees.

This package provides the ANTLR 4 grammar compiler.

%package maven-plugin
Summary:        ANTLR 4 plugin for Apache Maven
BuildArch:      noarch

%description maven-plugin
This package provides plugin for Apache Maven which can be used to
generate ANTLR parsers during build.

%package javadoc
Summary:        API documentation for %{name}
BuildArch:      noarch

%description javadoc
This package contains %{summary}.

%package -n %{runtime_cpp_libver}
Summary:        Runtime C++ ANTRL libraries

%description -n %{runtime_cpp_libver}
ANTLR runtime libraries for C++.
ANTLR (ANother Tool for Language Recognition) is a parser generator
for reading, processing, executing, or translating structured text or
binary files.

%package -n %{runtime_cpp_lib}-devel
Summary:        Development files for the ANTRL libraries
Requires:       %{runtime_cpp_libver} = %{version}

%description -n %{runtime_cpp_lib}-devel
ANTLR runtime libraries for C++.
ANTLR (ANother Tool for Language Recognition) is a parser generator
for reading, processing, executing, or translating structured text or
binary files.

%prep
%setup -q
%patch0 -p1

find -name \*.jar -delete
perl -pi -e 's#\\>#>#g' tool/resources/org/antlr/v4/tool/templates/unicodedata.st

# Missing test deps: org.seleniumhq.selenium:selenium-java
%pom_disable_module runtime-testsuite
%pom_disable_module runtime-testsuite/annotations
%pom_disable_module runtime-testsuite/processors
%pom_disable_module tool-testsuite

# Don't bundle dependencies
%pom_remove_plugin :maven-shade-plugin tool
# There are no grammars to process
%pom_remove_plugin :antlr4-maven-plugin runtime/Java
# Don't use the takari lifecycle, use the usual maven lifecycle instead
%pom_remove_plugin :takari-lifecycle-plugin antlr4-maven-plugin

%{mvn_package} :antlr4-master antlr4-runtime

%build
%{mvn_build} -s -f -- -Dsource=7

pushd runtime/Cpp
%cmake -DWITH_DEMO=False
make %{?_smp_mflags}
popd

%install
%mvn_install
%fdupes -s %{buildroot}%{_javadocdir}

%jpackage_script org.antlr.v4.Tool "" "" antlr4/antlr4:antlr3-runtime:antlr4/antlr4-runtime:stringtemplate4:treelayout %{name} true

pushd runtime/Cpp
%cmake_install
popd
# drop static library as unused
rm %{buildroot}/%{_libdir}/lib%{name}-runtime.a

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

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

%files tool -f .mfiles-antlr4
%{_bindir}/%{name}
%doc tool/MIGRATION.txt

%files java -f .mfiles-antlr4-runtime
%doc CHANGES.txt README.md
%license LICENSE.txt

%files maven-plugin -f .mfiles-antlr4-maven-plugin

%files javadoc -f .mfiles-javadoc
%license LICENSE.txt

%files -n %{runtime_cpp_libver}
%license LICENSE.txt
%doc runtime/Cpp/README.md runtime/Cpp/VERSION
%{_libdir}/lib%{name}-runtime.so.%{version}

%files -n %{runtime_cpp_lib}-devel
%{_libdir}/lib%{name}-runtime.so
%{_includedir}/%{name}-runtime/

%changelog