# Build with Emacs support
%bcond_without libidn_enables_emacs
%bcond_with java

Name:     libidn
Version:  1.36
Release:  3
Summary:  GNU IDN Library - Libidn
License:  LGPLv2+ and GPLv3+ and GFDL-1.3-or-later
URL:	  http://www.gnu.org/software/libidn/
Source0:  http://ftp.gnu.org/gnu/libidn/libidn-%{version}.tar.gz

# Allow disabling Emacs support
Patch0:   libidn-emacsopt.patch

BuildRequires: autoconf autoconf-archive automake libtool texinfo
BuildRequires: gcc gettext gettext-devel pkgconfig help2man
%if %{with libidn_enables_emacs}
BuildRequires: emacs
%endif

Provides:  bundled(gnulib)
%if %{with libidn_enables_emacs}
Obsoletes: emacs-libidn < 1.30-4
Provides:  emacs-libidn < 1.30-4
Requires:  emacs-filesystem >= %{_emacs_version}
%endif

%description
GNU Libidn is a fully documented implementation of the Stringprep, Punycode and IDNA 2003 specifications.
Libidn's purpose is to encode and decode internationalized domain names.

%package  devel
Summary:  Development files for the libidn library
Requires: %{name} = %{version}-%{release}
Requires: pkgconfig

%description devel
This package includes header files and libraries necessary for
developing programs which use the GNU libidn library.

%if %{with java}
%package java
Summary:       Java port of the GNU Libidn library
BuildRequires: java-devel javapackages-local
BuildRequires: mvn(com.google.code.findbugs:annotations)
BuildRequires: mvn(com.google.guava:guava)
BuildRequires: mvn(junit:junit)
BuildArch:     noarch

%description java
This package contains the native Java port of the library.

%package       javadoc
Summary:       Javadoc for %{name}-java
BuildArch:     noarch

%description javadoc
This package contains javadoc for %{name}-java.
%endif

%package_help

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

autoreconf -vif
touch src/idn_cmd.c src/idn_cmd.h

%build
%configure --disable-csharp \
%if %{with libidn_enables_emacs}
    --enable-emacs \
    --with-lispdir=%{_emacs_sitelispdir}/%{name} \
%else
    --disable-emacs \
%endif
%if %{with java}
    --enable-java
%else
    --disable-java
%endif

%disable_rpath
export LD_LIBRARY_PATH=$(pwd)/lib/.libs

%make_build

%check
# without RPATH this needs to be set to test the compiled library
export LD_LIBRARY_PATH=$(pwd)/lib/.libs
%make_build -C tests check VALGRIND=env

%install
%make_install

rm -rf %{buildroot}%{_datadir}/info/dir
rm -rf %{buildroot}%{_libdir}/*.la \
       %{buildroot}%{_datadir}/info/*.png

%if %{with libidn_enables_emacs}
%{_emacs_bytecompile} $RPM_BUILD_ROOT%{_emacs_sitelispdir}/%{name}/*.el
%endif

%if %{with java}
rm -rf doc/java/*
%javadoc -source 1.6 -d doc/java $(find java/src/main/java -name "*.java")
rm -rf $RPM_BUILD_ROOT%{_javadir}/libidn*.jar
%mvn_artifact java/pom.xml java/libidn-%{version}.jar
%mvn_file org.gnu.inet:libidn libidn
%mvn_install -J doc/java
%endif

%find_lang %{name}

%ldconfig_scriptlets

%files -f %{name}.lang
%license COPYING*
%doc AUTHORS NEWS FAQ THANKS README
%{_bindir}/idn
%{_libdir}/libidn.so.12*
%if %{with libidn_enables_emacs}
%{_emacs_sitelispdir}/%{name}
%endif

%files devel
%{_libdir}/libidn.so
%{_libdir}/*.a
%{_includedir}/*.h
%{_libdir}/pkgconfig/*.pc

%if %{with java}
%files java -f .mfiles
%license COPYING* java/LICENSE-2.0.txt

%files javadoc -f .mfiles-javadoc
%license COPYING* java/LICENSE-2.0.txt
%endif

%files help
%{_mandir}/man1/idn.1*
%{_mandir}/man3/*
%{_infodir}/%{name}.info.gz

%changelog
* Sat May 27 2023 yanglongkang <yanglongkang@h-partners.com> - 1.36-3
- enable check and correct the license

* Tue Feb 15 2022 fuanan <fuanan3@h-partners.com> - 1.36-2
- Add build-conditions disabling Emacs

* Thu Aug 6 2020 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 1.36-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update version to 1.36

* Wed Jan 8 2020 chengquan <chengquan3@huawei.com> - 1.35-9
- Type:NA
- ID:NA
- SUG:NA
- DESC:remove useless patch

* Mon Dec 23 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.35-8
- Type:NA
- ID:NA
- SUG:NA
- DESC:change the directory of lispdir and remove rpath

* Thu Oct 17 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.35-7
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add bcondwith java 

* Thu Oct 17 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.35-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add libidn_enables_java

* Mon Sep 23 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.35-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: Fix build failure in csharp

* Mon Sep 2 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.35-1
- Package init

