%define _repository standard

Patterntype: rpm-md comps 
Release: <CI_CNT>.<B_CNT>
Support: build build-compare 

#####################################
Substitute: gettext gettext-tools
Ignore: pkg-config
#####################################

%ifarch armv7el
Substitute: libncurses ncurses-libs 
Substitute: libncurses-devel ncurses-devel
Preinstall: nss
Ignore: bash:libncurses
%endif

Support: util-linux
VMinstall: util-linux  libblkid libuuid

ExportFilter: \.armv7hl\.rpm$ armv8el
ExportFilter: \.armv7thl*\.rpm$ armv8el
ExportFilter: \.armv7tnh*\.rpm$ armv8el
ExportFilter: \.armv7h*\.rpm$ armv8el
ExportFilter: \.armv7nh*\.rpm$ armv8el
ExportFilter: \.x86_64\.rpm$ x86_64
ExportFilter: \.i586\.rpm$ i586
ExportFilter: \.armv5el\.rpm$ armv5el
ExportFilter: \.armv5tel\.rpm$ armv5el
ExportFilter: \.armv6el\.rpm$ armv6el
ExportFilter: \.armv6l\.rpm$ armv6el
ExportFilter: \.armv6vl\.rpm$ armv6el
ExportFilter: \.armv7el\.rpm$ armv7el
ExportFilter: \.armv7l\.rpm$ armv7el
ExportFilter: \.armv7vl\.rpm$ armv7el
# filter out packages of cross setup on ia32
ExportFilter: .*vanish\.rpm
PublishFilter: .*vanish\.rpm
ExportFilter: .*dontuse\.rpm
PublishFilter: .*dontuse\.rpm

Prefer: coreutils
Prefer: gdbm
#
# ARM Start
#
%ifarch %arm
# arm land
Hostarch: i586

%define cross_5 1
%define cross_7 1
%define native 1

%define cross_7h 1

%ifarch armv8el
Changetarget: armv7hl-tizen-linux
%define _gnu gnueabi
%if %{cross_7h}
Prefer: cross-armv7hl-binutils-accel-armv7hl
Prefer: cross-armv7hl-gcc-accel-armv7hl
%define speedcommon 1
%define speedbash 1
%define speedbinutils 1
%define speedgcc 1
%define native 0
%define speedtools 1
Support: cross-armv7tnhl-platformfile
%endif
%endif


########################
# preselect rpm targets  
# more ifs for _repository possible as needed  
#########################  
%ifarch armv5el
Changetarget: armv5tel-tizen-linux
%define _gnu gnueabi
%if %{cross_5}
%define speedcommon 1
%define speedbash 1
%define speedbinutils 1
%define speedgcc 1
%define native 0
%endif
%endif

%ifarch armv6el
Changetarget: armv6l-tizen-linux
%define _gnu gnueabi
%endif

%ifarch armv7el
Changetarget: armv7l-tizen-linux
%define _gnu gnueabi
%if %{cross_7}
#Support: cross-armv7tnhl-platformfile
#Support: cross-armv7l-platformfile
Prefer: cross-armv7l-binutils-accel-armv7l
Prefer: cross-armv7l-gcc-accel-armv7l
%define speedcommon 1
%define speedbash 1
%define speedbinutils 1
%define speedgcc 1
%define native 0
%define speedtools 1
%endif

%endif

%if %speedtools
Support: patch-x86-arm findutils-x86-arm gawk-x86-arm fdupes-x86-arm 
Preinstall: libfile-x86-arm
Preinstall: elfutils-libelf-x86-arm
Preinstall: nss-softokn-freebl-x86-arm
Preinstall: nss-x86-arm
Preinstall: nspr-x86-arm
Preinstall: libgcc-x86-arm
Preinstall: libacl-x86-arm
Preinstall: libattr-x86-arm
Preinstall: libcap-x86-arm
Preinstall: liblua-x86-arm
Preinstall: popt-x86-arm
Preinstall: xz-libs-x86-arm
Preinstall: zlib-x86-arm
Preinstall: file
Preinstall: sqlite-x86-arm
Preinstall: mpfr-x86-arm
Preinstall: gmp-x86-arm
Preinstall: mpc-x86-arm
Preinstall: bzip2-libs-x86-arm
Preinstall: rpm-x86-arm
Preinstall: rpm-libs-x86-arm

Required: tar-x86-arm
Required: sed-x86-arm
Required: elfutils-x86-arm
Required: elfutils-libs-x86-arm
Required: elfutils-libelf-x86-arm
Required: diffutils-x86-arm
Required: gzip-x86-arm
Required: libgcc-x86-arm
Required: libacl-x86-arm
Required: libattr-x86-arm
Required: coreutils
Required: coreutils-x86-arm
Required: libcap-x86-arm
Required: liblua-x86-arm
Required: popt-x86-arm
Required: xz-libs-x86-arm
Required: zlib-x86-arm
Required: file
Required: file-x86-arm
Required: make
Required: make-x86-arm
Required: libfile-x86-arm
Required: sqlite-x86-arm
Required: rpm-x86-arm
Required: rpm-libs-x86-arm
Required: rpm-build-x86-arm

Runscripts: rpm-x86-arm
Runscripts: rpm-libs-x86-arm
Runscripts: rpm-build-x86-arm

Support: !rpmlint-mini
Support: !rpmlint-mini-x86-arm
Prefer: python-libs
%endif


%if %speedcommon
# cross-compilation/speedup
Preinstall: tizen-accelerator eglibc-x86-arm 
Runscripts: tizen-accelerator
Required: tizen-accelerator
%endif

%if %speedbash
# bash
Preinstall: ncurses-libs-x86-arm
Preinstall: bash-x86-arm 
Runscripts: bash-x86-arm
%endif

%if %speedbinutils
Required: cross-arm-binutils-accel
%endif

%if %speedgcc
Required: cross-arm-gcc-accel
%endif

Preinstall: rpm
Preinstall: rpm-libs
Required:   rpm
Prefer:     rpm-libs
Prefer:     rpm

# now i586 land
%else



Ignore: ncurses-libs-x86 libncurses-x86
Preinstall: rpm rpm-libs
Required:   rpm
%endif

#
# ARM End
#

Preinstall: setup filesystem

Preinstall: bash bzip2 coreutils diffutils liblua
Preinstall: eglibc eglibc-common libacl libattr
Preinstall: libgcc libcap
Preinstall: popt readline sed tar zlib sqlite

Preinstall: ncurses-libs
Preinstall: elfutils-libelf bzip2-libs libstdc++ setup libfile 
Preinstall: xz-libs 
Preinstall: nss nspr
Preinstall: nss-softokn-freebl

Runscripts: setup
VMinstall: perl libblkid e2fsprogs-libs libuuid perl-libs grep libpcre 
Preinstall: 
Required: binutils gcc eglibc rpm-build libtool lzo-devel
Support: cpio gcc-c++ perl-libs perl findutils

Support: perl-HTML-Tagset
Support: perl-IO-Compress-Base
Support: perl-Module-Pluggable
Support: perl-Pod-Escapes
Support: perl-TimeDate
Support: perl-Compress-Raw-Zlib
Support: perl-ExtUtils-ParseXS
Support: perl-Pod-Simple
Support: perl-Test-Simple
Support: perl-IO-Compress-Zlib
Support: perl-Test-Harness
Support: perl-ExtUtils-MakeMaker
Support: perl-CPAN

Support: file findutils zlib bzip2 
Support: gzip 
Support: ncurses-libs
Support: net-tools
Support: make  patch sed  gawk tar grep coreutils pkgconfig autoconf automake
Support: m4 libfile tzdata tizen-release
Support: kernel-headers eglibc-headers
Support: xz-lzma-compat

Keep: binutils cpp  file findutils gawk gcc  gcc-c++
Keep: gdbm gzip libada libunwind  eglibc-devel libpcre xz-lzma-compat 
Keep: make  gmp libcap groff cpio
Keep: patch rpm-build  nss nspr elfutils python grep libgcc gcc-c++ 
Keep: eglibc-headers perl-libs
Keep: pkgconfig glib2 tizen-rpm-config
Keep: xz-lzma-compat
Keep: mpc mpfr  tar sed
Keep: cloog cloog-ppl ppl  
Keep: nss-softokn-freebl
Keep: setup

# SLP
Ignore: iso-codes:xml-common

%if "%_repository" == "i586emul"
 Prefer: simulator-opengl-devel
 Support: emulator-macros 
 Optflags: i586 %{__global_cflags} -m32 -march=core2 -msse3 -mno-ssse3 -mfpmath=sse -mtune=generic -fasynchronous-unwind-tables -fno-omit-frame-pointer
%else
 %ifarch armv7el
   Prefer: pvr-bin-mdfld-devel
   Substitute: pvr-bin-mdfld simulator-opengl
   Substitute: pvr-bin-mdfld-devel simulator-opengl-devel
 %else
   Prefer: libdrm
   Substitute: simulator-opengl-devel pvr-bin-mdfld-devel
   Substitute: simulator-opengl pvr-bin-mdfld
   Prefer: pvr-bin-mdfld-devel pvr-bin-mdfld
   Prefer: mesa-libEGL
   Prefer: kernel-mfld-blackbay
 %endif
%endif

Macros:
%tizen_version 1.0
%tizen 1.0
%vendor tizen
%_vendor tizen
%_default_patch_fuzz   2



# python main version
%py_ver         %(echo `python -c "import sys; print sys.version[:3]"`)

# directories
%py_prefix      %(echo `python -c "import sys; print sys.prefix"`)
%py_libdir      %{py_prefix}/lib/python%{py_ver}
%py_incdir      /usr/include/python%{py_ver}
%py_sitedir     %{py_libdir}/site-packages
%py_dyndir      %{py_libdir}/lib-dynload

# pure python modules compilation
%py_comp        python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
%py_ocomp       python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"

%ext_info .gz
%ext_man .gz

%info_add(:-:) test -x /sbin/install-info -a -f %{?2}%{?!2:%{_infodir}}/%{1}%ext_info && /sbin/install-info --info-dir=%{?2}%{?!2:%{_infodir}} %{?2}%{?!2:%{_infodir}}/%{1}%ext_info \
%{nil}

%info_del(:-:) test -x /sbin/install-info -a ! -f %{?2}%{?!2:%{_infodir}}/%{1}%ext_info && /sbin/install-info --quiet --delete --info-dir=%{?2}%{?!2:%{_infodir}} %{?2}%{?!2:%{_infodir}}/%{1}%ext_info \
%{nil}

%lang_package \
%package locale \
Summary: Translations and Locale for package %{name}\
Group: Translations\
AutoReqProv: 0\
%description locale\
This package provides translations for package %{name}.\
%files locale -f %{name}.lang\
%defattr(-,root,root,-)\
%{nil}


%docs_package \
%package docs \
Summary: Documentation for package %{name}\
Group: Documentation\
AutoReqProv: 0\
%description docs\
This package provides documentation for package %{name}.\
%files docs -f documentation.list\
%defattr(-,root,root,-)\
%{nil}

%devel_package \
%package devel \
Summary: Development files for package %{name}\
Group: Development\
%description devel\
This package provides header files and other developer releated files for package %{name}.\
%files devel \
%{_includedir}/*\
%{_libdir}/pkgconfig/*.pc\
%{_libdir}/*.so\
%{nil}


%_smp_mflags -j4


%remove_docs \
  rm -rf %{?buildroot:%{buildroot}}%{_infodir} \
  rm -rf %{?buildroot:%{buildroot}}%{_defaultdocdir} \
  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/doc/%{name} \
  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/gtk-doc \
  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/man \
  find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]" | xargs rm -f -- \
  find %{?buildroot:%{buildroot}} -regex ".*/man/../man./.*\.[0-9]" | xargs rm -f -- \
  find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]pm" | xargs rm -f --
