File unicorn.spec of Package unicorn

#
# spec file for package unicorn
#
# Copyright (c) 2017 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 http://bugs.opensuse.org/
#


%define _lver   1
Name:           unicorn
Version:        1.0.1
Release:        0
Summary:        Multi-CPU emulator engine based on QEMU
License:        GPL-2.0
Group:          System/Emulators/Other
Url:            http://www.unicorn-engine.org
Source0:        https://github.com/unicorn-engine/unicorn/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Patch2:         unicorn.gcc.patch
BuildRequires:  fdupes
BuildRequires:  gcc
BuildRequires:  libcmocka-devel
BuildRequires:  make
BuildRequires:  python-devel
BuildRequires:  python-setuptools
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Temporarily excluded until (gh#unicorn-engine/unicorn#766) is fully addressed
ExcludeArch:    ppc ppc64 s390x

%description
Unicorn is a lightweight multi-platform, multi-architecture CPU emulator
framework.

Highlight features:

   * Multi-architectures: Arm, Arm64 (Armv8), M68K, Mips, Sparc
     & X86 (X86_64 included).
   * Clean/simple/lightweight/intuitive architecture-neutral API.
   * Implemented in pure C language, with bindings for Rust, Haskell,
     Ruby, Python, Java, Go, .NET, Delphi/Pascal & MSVC available.
   * Native support for Windows & *nix (with Mac OSX, Linux, *BSD
     & Solaris confirmed).
   * High performance by using Just-In-Time compiler technique.
   * Support fine-grained instrumentation at various levels.
   * Thread-safe by design.
   * Distributed under free software license GPLv2.

%package        devel
Summary:        Development files for package %{name}
Group:          Development/Libraries/C and C++
Requires:       lib%{name}%{_lver} = %{version}

%description    devel
This package contains development files for %{name}

%package -n     lib%{name}%{_lver}
Summary:        Support library for %{name}
Group:          System/Libraries

%description -n lib%{name}%{_lver}
This package contains the support library for %{name}

%package -n     python-%{name}
Summary:        Python bindings for %{name}
Group:          Development/Languages/Python
Requires:       lib%{name}%{_lver} = %{version}
BuildArch:      noarch

%description -n python-%{name}
This package contains the Python bindings for %{name}

%package -n     python3-%{name}
Summary:        Python3 bindings for %{name}
Group:          Development/Languages/Python
Requires:       lib%{name}%{_lver} = %{version}
BuildArch:      noarch

%description -n python3-%{name}
This package contains the Python3 bindings for %{name}

%prep
%setup -q
%patch2 -p1

sed -e 's|libdir=$(LIBDIR)|libdir=%{_libdir}|' \
    -e 's|includedir=$(INCDIR)|includedir=%{_includedir}|' \
    -e '/^LIBDIRARCH/s/lib/%{_lib}/' \
    -e 's/qemu -j 4/qemu %{?_smp_mflags}/' \
    -e 's|ifeq ($(UNICORN_DEBUG),yes)|ifneq ($(UNICORN_DEBUG),yes)|g' \
    -e 's|-O3|-O2|g' \
    -i Makefile
sed -e 's|-O3|-O2|g' \
    -e 's|-g ||g' \
    -i qemu/configure
sed -e '/^UNICORN_DEBUG/s/yes/no/' \
    -e '/^UNICORN_STATIC/s/yes/no/' \
    -i config.mk
cp -a bindings/python bindings/python3
# hopefully temporary until bugs #763 is fixed
%if 0%{?suse_version} == 1315
sed -e '/unit test/d' -i Makefile
%endif
# hopefully temporary until bug #765 is fixed
%ifarch %arm ppc ppc64 ppc64le s390x
sed -e '/unit test/d' -i Makefile
%endif
# hopefully temporary until bug #766 is fixed
%ifarch ppc ppc64 s390x
sed -e '/DIFF.*py\.test/d' -i bindings/Makefile
sed -e '/bindings test/d' -i Makefile
%endif

%build
export CFLAGS="%{optflags}"
make %{?_smp_mflags}
pushd bindings/python
python setup.py build
popd
pushd bindings/python3
python3 setup.py build
popd

%install
%make_install
pushd bindings/python
python setup.py install --prefix=%{_prefix} --root=%{buildroot}
mkdir -pv %{buildroot}%{_datadir}/doc/packages/python-%{name}/samples
install -m 644 sample* shellcode.py -t %{buildroot}%{_datadir}/doc/packages/python-%{name}/samples
popd
pushd bindings/python3
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}
mkdir -pv %{buildroot}%{_datadir}/doc/packages/python3-%{name}/samples
install -m 644 sample* shellcode.py -t %{buildroot}%{_datadir}/doc/packages/python3-%{name}/samples
popd
mkdir -pv %{buildroot}%{_datadir}/doc/packages/%{name}-devel/samples
install -m 644 samples/*.c -t %{buildroot}%{_datadir}/doc/packages/%{name}-devel/samples
rm -rf %{buildroot}%{python_sitelib}/%{name}/include %{buildroot}%{python_sitelib}/%{name}/lib
rm -rf %{buildroot}%{python3_sitelib}/%{name}/include %{buildroot}%{python3_sitelib}/%{name}/lib
sed -e '/libunicorn\.a/d' -i %{buildroot}%{_libdir}/pkgconfig/%{name}.pc
%fdupes -s %{buildroot}%{python_sitelib}
%fdupes -s %{buildroot}%{python3_sitelib}

%check
make %{?_smp_mflags} test

%post -n lib%{name}%{_lver} -p /sbin/ldconfig
%postun -n lib%{name}%{_lver} -p /sbin/ldconfig

%files devel
%defattr(-,root,root)
%doc ChangeLog COPYING CREDITS.TXT README.md
%doc %{_datadir}/doc/packages/%{name}-devel
%dir %{_includedir}/%{name}
%{_includedir}/%{name}/arm.h
%{_includedir}/%{name}/arm64.h
%{_includedir}/%{name}/m68k.h
%{_includedir}/%{name}/mips.h
%{_includedir}/%{name}/sparc.h
%{_includedir}/%{name}/unicorn.h
%{_includedir}/%{name}/x86.h
%{_libdir}/lib%{name}.so
%{_libdir}/pkgconfig/%{name}.pc

%files -n lib%{name}%{_lver}
%defattr(-,root,root)
%doc ChangeLog COPYING CREDITS.TXT README.md
%{_libdir}/libunicorn.so.%{_lver}

%files -n python-%{name}
%defattr(-,root,root)
%doc ChangeLog COPYING CREDITS.TXT bindings/README README.md
%doc %{_datadir}/doc/packages/python-%{name}
%{python_sitelib}/%{name}
%{python_sitelib}/%{name}-%{version}-py%{py_ver}.egg-info

%files -n python3-%{name}
%defattr(-,root,root)
%doc ChangeLog COPYING CREDITS.TXT bindings/README README.md
%doc %{_datadir}/doc/packages/python3-%{name}
%{python3_sitelib}/%{name}
%{python3_sitelib}/%{name}-%{version}-py%{py3_ver}.egg-info

%changelog
openSUSE Build Service is sponsored by