Name:		anthy
Version:	9100h
Release:	40
Summary:	Anthy is a system for Japanese input method.
License:	LGPLv2+ and GPLv2 and Public Domain	
URL:		http://sourceforge.jp/projects/anthy/
Source0:	http://osdn.dl.sourceforge.jp/anthy/37536/anthy-%{version}.tar.gz
Source1: 	https://github.com/gooselinux/anthy/raw/master/%{name}-init.el

BuildRequires:	emacs gcc
Requires:	emacs-filesystem >= %{_emacs_version} 
Provides: 	emacs-anthy-el <= 9100h-27 emacs-anthy <= 9100h-27
Obsoletes: 	emacs-anthy-el <= 9100h-27 emacs-anthy <= 9100h-27

Patch0001: 	%{name}-aarch64.patch
Patch0002: 	%{name}-fix-segfault.patch

%description
Anthy is a system for Japanese input method.
It converts Hiragana text to Kana Kanji mixed text.

%package 	devel
Summary: 	Files for developing programs
Requires: 	%{name} = %{version}-%{release} pkgconfig

%description 	devel
Files for developing programs

%package_help

%prep
%autosetup -p1

for file in ChangeLog doc/protocol.txt; 
do
    iconv -f ISO-8859-1 -t UTF-8 -o $file.new $file && \
    touch -r $file $file.new && \
    mv $file.new $file
done

cd alt-cannadic
for file in gcanna.ctd gcannaf.ctd gtankan.ctd; 
do
iconv -f euc-jp -t utf-8 $file > $file.utf8
done

cd extra
for file in g-jiritu-34.t gc-fullname-34.t gf-fuzoku-34.t gt-tankanji_hikanji-34.t gt-tankanji_kanji-34.t; 
do
 sed -e 's/^\([^  ]*\)t[  ]*\(#[A-Z0-9\*]*\)[  ]*\([^  ]*\)$/\1 \2 \3/g' $file > $file.norm
done
cd ../../
cd mkworddic
for file in adjust.t compound.t extra.t udict zipcode.t;
do
iconv -f euc-jp -t utf-8 $file > $file.utf8
done

if ! test -f $RPM_BUILD_DIR/%{name}-%{version}/mkworddic/dict.args.in-orig; then
  cp -a $RPM_BUILD_DIR/%{name}-%{version}/mkworddic/dict.args.in{,-orig}
fi

install -Dd -m 0755 %{buildroot}/%{name}-%{version}/mkworddic
touch %{buildroot}/%{name}-%{version}/mkworddic/dict.args.in
cat > %{buildroot}/%{name}-%{version}/mkworddic/dict.args.in << eof
# Generated by rpm script
set_input_encoding utf8
read @top_srcdir@/alt-cannadic/gcanna.ctd.utf8
read @top_srcdir@/alt-cannadic/gcannaf.ctd.utf8
read @top_srcdir@/alt-cannadic/gtankan.ctd.utf8
read @top_srcdir@/alt-cannadic/extra/g-jiritu-34.t.norm
read @top_srcdir@/alt-cannadic/extra/gc-fullname-34.t.norm
read @top_srcdir@/alt-cannadic/extra/gt-tankanji_kanji-34.t.norm
read @top_srcdir@/alt-cannadic/extra/gt-tankanji_hikanji-34.t.norm
read @top_srcdir@/alt-cannadic/extra/gf-fuzoku-34.t.norm
read @top_srcdir@/mkworddic/adjust.t.utf8
read @top_srcdir@/mkworddic/compound.t.utf8
read @top_srcdir@/mkworddic/extra.t.utf8
read @top_srcdir@/alt-cannadic/g_fname.t
#
build_reverse_dict
set_dict_encoding utf8
read_uc @top_srcdir@/mkworddic/udict.utf8
write anthy.wdic
done

eof
touch -r $RPM_BUILD_DIR/%{name}-%{version}/mkworddic/dict.args.in{-orig,}

%build
%configure --disable-static
sed -ie 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/' libtool

#LD_LIBRARY_PATH=%{_builddir}/%{name}-%{version}/src-main/.libs:%{_builddir}/ \
#			%{name}-%{version}/src-worddic/.libs 
LD_LIBRARY_PATH=$RPM_BUILD_DIR/%{name}-%{version}/src-main/.libs:$RPM_BUILD_DIR/%{name}-%{version}/src-worddic/.libs %make_build

%install
%make_install 

%delete_la_and_a

install -d %{buildroot}%{_datadir}/emacs/site-lisp/site-start.d
install -m 644 %{SOURCE1} %{buildroot}%{_datadir}/emacs/site-lisp/site-start.d

%ldconfig_scriptlets
cp -a %{_builddir}/%{name}-%{version}/doc %{buildroot}/

%files
%defattr(-,root,root)
%doc AUTHORS 
%doc /doc/ELISP
%license COPYING
%{_bindir}/*
%{_libdir}/lib*.so.*
%{_datadir}/anthy/
%{_sysconfdir}/*
%{_datadir}/emacs/site-lisp/anthy/*.el*
%{_datadir}/emacs/site-lisp/site-start.d/*.el

%files devel
%defattr(-,root,root)
%doc /doc/*
%exclude /doc/ELISP
%{_includedir}/*
%{_libdir}/lib*.so
%{_libdir}/pkgconfig/*.pc

%files help
%defattr(-,root,root)
%doc ChangeLog DIARY NEWS README

%changelog
* Wed Dec 16 2020 Ge Wang<wangge20@huawei.com> - 9100h-40
- Modify Source url

* Fri Feb 14 2020 gulining<gulining1@huawei.com> - 9100h-39
- Package init
