%distinitials %(grep -i fedora.core /etc/redhat-release >/dev/null && echo "fc" || { grep -i fedora.release /etc/redhat-release >/dev/null && echo "f" || { grep -i "red hat enterprise linux" /etc/redhat-release >/dev/null && echo "el" || { grep -i "scientific linux" /etc/redhat-release >/dev/null && echo "el" || { grep -i "CentOS" /etc/redhat-release >/dev/null && echo "el" || echo "RHL"; }; }; }; })
#disttaginitials %(grep -i fedora /etc/redhat-release >/dev/null && echo "fc" || { grep -i "red hat enterprise linux" /etc/redhat-release >/dev/null && echo "el" || echo "RHL"; })
%disttaginitials %(grep -i fedora /etc/redhat-release >/dev/null && echo "fc" || echo "el";)
%distversion %(rpm -qf --qf='%{VERSION}' /etc/redhat-release | sed -e's,^\\([0-9]*\\)[^0-9].*,\\1,') 
%disttagversion %(rpm -qf --qf='%{VERSION}' /etc/redhat-release | sed -e's,^\\([0-9]*\\)[^0-9].*,\\1,') 
#distname %(grep -i fedora.core /etc/redhat-release >/dev/null && echo "Fedora Core" || { grep -i fedora.release /etc/redhat-release >/dev/null && echo "Fedora" || { grep -i "red hat enterprise linux" /etc/redhat-release >/dev/null && echo "Red Hat Enterprise Linux" || echo "Red Hat Linux"; }; })
%distname %(grep -i fedora.core /etc/redhat-release >/dev/null && echo "Fedora Core" || { grep -i fedora.release /etc/redhat-release >/dev/null && echo "Fedora" || echo "Red Hat Enterprise Linux"; })
%distid %(echo %{distinitials}%{distversion} | sed -e's,\\.,_,g')
%disttag %(echo %{disttaginitials}%{disttagversion} | sed -e's,\\.,_,g')
#%dist .%{distinitials}%{distversion}

%eversion	%{?epoch:%{epoch}:}%{version}
%evr		%{?epoch:%{epoch}:}%{version}-%{release}

%__find_requires        /usr/lib/rpm/atrpms/find-requires
%__find_provides        /usr/lib/rpm/atrpms/find-provides
%__os_install_post    \
    /usr/lib/rpm/atrpms/brp-compress \
    /usr/lib/rpm/atrpms/brp-strip %{__strip} \
    /usr/lib/rpm/atrpms/brp-strip-static-archive %{__strip} \
    /usr/lib/rpm/atrpms/brp-strip-comment-note %{__strip} %{__objdump} \
%{nil}

################################################################
%_initdir	%{_sysconfdir}/rc.d/init.d
%_initddir	%{_sysconfdir}/rc.d/init.d
%_varlibdir	%{_localstatedir}/lib
%_varcachedir	%{_localstatedir}/cache
%_logdir		%{_localstatedir}/log
%_rundir		%{_localstatedir}/run
%_subsysdir	%{_localstatedir}/lock/subsys
%_sysconfigdir	%{_sysconfdir}/sysconfig
%_logrotatedir	%{_sysconfdir}/logrotate.d

###

%sgmlbase	%{_datadir}/sgml
%sgmlcatdir	%{_sysconfdir}/sgml
%rootcat	%{sgmlcatdir}/catalog

%xmlbase	%{_datadir}/xml
%xmlcatdir	%{_sysconfdir}/xml
%rootxmlcat	%{xmlcatdir}/catalog

################################################################ python
# setup ... --root ...
%python_version	%(python -c "import sys; print (sys.version[:3])")
#python_libdir	%(python -c "from distutils import sysconfig; print sysconfig.get_python_lib()")

#python_libdir  %(python -c "from distutils import sysconfig; print sysconfig.get_python_lib()" | sed -e's,/usr/lib/,%{_libdir}/,')
#python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
#python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")

%python_libdir %{_libdir}/python%{python_version}/site-packages
%python_sitelib /usr/lib/python%{python_version}/site-packages
%python_sitearch %{_libdir}/python%{python_version}/site-packages


%python_burninversion %{nil}
#test -d %{buildroot} && find %{buildroot} -type f | xargs grep -l '^#!.*python' | xargs perl -pi -e's,^(#!.*python)[0-9.]*,${1}%python_version,'
################################################################ tex

%texmf           %{_datadir}/texmf
%texmflocal      %{_datadir}/texmf-local
%vartexmf        %{_datadir}/texmf-var


################################################################ (x)emacs
%emacspkgdir %{_datadir}/emacs/site-lisp

# >= RH9
%xemacspkgdir %{_datadir}/xemacs/site-packages
%vendorxemacspkgdir %{_datadir}/xemacs/xemacs-packages
%xemacssitestart %{_datadir}/xemacs/site-packages/lisp/site-start.d
# <= RH8_0
#xemacspkgdir %{_libdir}/xemacs/site-packages
#vendorxemacspkgdir %{_libdir}/xemacs/xemacs-packages
#xemacssitestart %{_libdir}/xemacs/xemacs-packages/lisp/site-start.d


%__ldconfig %(echo %{expand:%%__ldconfig_%{distid}} | grep '^%' > /dev/null && echo /sbin/ldconfig || echo %{expand:%%__ldconfig_%{distid}})
%__ldconfig_el3 /sbin/ldconfig
%__ldconfig_el4 /sbin/ldconfig
%__ldconfig_el5 /sbin/ldconfig
%__ldconfig_el6 /sbin/ldconfig
%__ldconfig_f12 /sbin/ldconfig
%__ldconfig_f17 /sbin/ldconfig

%__depmod %(echo %{expand:%%__depmod_%{distid}} | grep '^%' > /dev/null && echo /usr/sbin/depmod || echo %{expand:%%__depmod_%{distid}})
%__depmod_el3 /sbin/depmod
%__depmod_el4 /sbin/depmod
%__depmod_el5 /sbin/depmod
%__depmod_el6 /sbin/depmod
%__depmod_f12 /sbin/depmod
%__depmod_f17 /sbin/depmod

###
###
###



%_x_prefix %(echo %{expand:%%_x_prefix_%{distid}} | grep '^%' > /dev/null && echo %{_prefix} || echo %{expand:%%_x_prefix_%{distid}})
%_x_includes %(echo %{expand:%%_x_includes_%{distid}} | grep '^%' > /dev/null && echo %{_includedir} || echo %{expand:%%_x_includes_%{distid}})
%_x_libraries %(echo %{expand:%%_x_libraries_%{distid}} | grep '^%' > /dev/null && echo %{_libdir} || echo %{expand:%%_x_libraries_%{distid}})
%_x_module_path %(echo %{expand:%%_x_module_path_%{distid}} | grep '^%' > /dev/null && echo %{_libdir}/xorg/modules || echo %{expand:%%_x_module_path_%{distid}})
%_x_bindir %(echo %{expand:%%_x_bindir_%{distid}} | grep '^%' > /dev/null && echo %{_bindir} || echo %{expand:%%_x_bindir_%{distid}})

%_x_prefix_el4 /usr/X11R6
%_x_includes_el4 /usr/X11R6/include
%_x_libraries_el4 /usr/X11R6/%{_lib}
%_x_module_path_el4 /usr/X11R6/%{_lib}/modules
%_x_bindir_el4 /usr/X11R6/bin
%_x_prefix_el3 /usr/X11R6
%_x_includes_el3 /usr/X11R6/include
%_x_libraries_el3 /usr/X11R6/%{_lib}
%_x_module_path_el3 /usr/X11R6/%{_lib}/modules
%_x_bindir_el3 /usr/X11R6/bin
%_x_prefix_fc4 /usr/X11R6
%_x_includes_fc4 /usr/X11R6/include
%_x_libraries_fc4 /usr/X11R6/%{_lib}
%_x_module_path_fc4 /usr/X11R6/%{_lib}/modules
%_x_bindir_fc4 /usr/X11R6/bin
%_x_prefix_fc3 /usr/X11R6
%_x_includes_fc3 /usr/X11R6/include
%_x_libraries_fc3 /usr/X11R6/%{_lib}
%_x_module_path_fc3 /usr/X11R6/%{_lib}/modules
%_x_bindir_fc3 /usr/X11R6/bin
%_x_prefix_fc2 /usr/X11R6
%_x_includes_fc2 /usr/X11R6/include
%_x_libraries_fc2 /usr/X11R6/%{_lib}
%_x_module_path_fc2 /usr/X11R6/%{_lib}/modules
%_x_bindir_fc2 /usr/X11R6/bin
%_x_prefix_fc1 /usr/X11R6
%_x_includes_fc1 /usr/X11R6/include
%_x_libraries_fc1 /usr/X11R6/%{_lib}
%_x_module_path_fc1 /usr/X11R6/%{_lib}/modules
%_x_bindir_fc1 /usr/X11R6/bin
%_x_prefix_rh9 /usr/X11R6
%_x_includes_rh9 /usr/X11R6/include
%_x_libraries_rh9 /usr/X11R6/%{_lib}
%_x_module_path_rh9 /usr/X11R6/%{_lib}/modules
%_x_bindir_rh9 /usr/X11R6/bin
%_x_prefix_rh8_0 /usr/X11R6
%_x_includes_rh8_0 /usr/X11R6/include
%_x_libraries_rh8_0 /usr/X11R6/%{_lib}
%_x_module_path_rh8_0 /usr/X11R6/%{_lib}/modules
%_x_bindir_rh8_0 /usr/X11R6/bin
%_x_prefix_rh7_3 /usr/X11R6
%_x_includes_rh7_3 /usr/X11R6/include
%_x_libraries_rh7_3 /usr/X11R6/%{_lib}
%_x_module_path_rh7_3 /usr/X11R6/%{_lib}/modules
%_x_bindir_rh7_3 /usr/X11R6/bin

%_pkgdocdir %(echo %{expand:%%_pkgdocdir_%{distid}} | grep '^%' > /dev/null && echo %{_docdir}/%{name} || echo %{expand:%%_pkgdocdir_%{distid}})

%_pkgdocdir_el7 %{_docdir}/%{name}-%{version}
%_pkgdocdir_el6 %{_docdir}/%{name}-%{version}
%_pkgdocdir_fc19 %{_docdir}/%{name}-%{version}
%_pkgdocdir_fc18 %{_docdir}/%{name}-%{version}

%__spec_install_post\
    %{?__lib_packages:%{__lib_install_post}}\
    %{?__devel_package:%{__devel_install_post}}\
    /usr/lib/rpm/atrpms/python_burninversion.sh\
    %{__arch_install_post}\
    %{__os_install_post}\
%{nil}

%prep \
%%prep\
LANG=C\
export LANG\
unset DISPLAY || :\
%{nil}

%build %%build\
LANG=C\
export LANG\
unset DISPLAY || :\
%{nil}

%install %{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}\
%{?__lib_packages:%{expand:%__lib_packages}}\
%{?_enable_devel_packages:%{devel_package}}\
%%install\
LANG=C\
export LANG\
unset DISPLAY || :\
%{nil}




################################################################ perl

# Two of these are already provided
#perl_archlib		%(eval "`perl -V:installarchlib`"; echo $installarchlib)
%perl_privlib		%(eval "`perl -V:installprivlib`"; echo $installprivlib)

#perl_sitearch		%(eval "`perl -V:installsitearch`"; echo $installsitearch)
%perl_sitelib		%(eval "`perl -V:installsitelib`"; echo $installsitelib)

%perl_vendorarch	%(eval "`perl -V:installvendorarch`"; echo $installvendorarch)
%perl_vendorlib		%(eval "`perl -V:installvendorlib`"; echo $installvendorlib)

%perl_bin		%(eval "`perl -V:installbin`"; echo $installbin)
%perl_script		%(eval "`perl -V:installscript`"; echo $installscript)
%perl_man1dir		%(eval "`perl -V:installman1dir`"; echo $installman1dir)
%perl_man3dir		%(eval "`perl -V:installman3dir`"; echo $installman3dir)

%perl_version		%(eval "`perl -V:version`"; echo $version)

%perl_module() %{expand:%%global pkgname %1}\
Requires: atrpms-perl-module-helper \
BuildRequires: perl, atrpms-perl-module-helper\
#Requires: perl(:MODULE_COMPAT_%perl_version) \
Requires: %(perl -MConfig -le 'if (defined $Config{useithreads}) { print "perl(:WITH_ITHREADS)" } else { print "perl(:WITHOUT_ITHREADS)" }')\
Requires: %(perl -MConfig -le 'if (defined $Config{usethreads}) { print "perl(:WITH_THREADS)" } else { print "perl(:WITHOUT_THREADS)" }')\
Requires: %(perl -MConfig -le 'if (defined $Config{uselargefiles}) { print "perl(:WITH_LARGEFILES)" } else { print "perl(:WITHOUT_LARGEFILES)" }')\
Name: perl-%1\
Version: %2\
Release: %3%{?dist}\
%{nil}

%perl_module_wo_prefix() %{expand:%%global pkgname %1}\
Requires: atrpms-perl-module-helper \
BuildRequires: perl, atrpms-perl-module-helper\
#Requires: perl(:MODULE_COMPAT_%perl_version) \
Requires: %(perl -MConfig -le 'if (defined $Config{useithreads}) { print "perl(:WITH_ITHREADS)" } else { print "perl(:WITHOUT_ITHREADS)" }')\
Requires: %(perl -MConfig -le 'if (defined $Config{usethreads}) { print "perl(:WITH_THREADS)" } else { print "perl(:WITHOUT_THREADS)" }')\
Requires: %(perl -MConfig -le 'if (defined $Config{uselargefiles}) { print "perl(:WITH_LARGEFILES)" } else { print "perl(:WITHOUT_LARGEFILES)" }')\
Name: %1\
Version: %2\
Release: %3%{?dist}\
%{nil}

#_perl_extra_path	%{buildroot}%{perl_sitearch}:%{buildroot}%{perl_sitelib}:%{perl_sitearch}:%{perl_sitelib}
%_perl_extra_path	%{buildroot}%{perl_vendorarch}:%{buildroot}%{perl_vendorlib}
%_perl5lib		test -z "$PERL5LIB" && export PERL5LIB=%{_perl_extra_path} || export PERL5LIB="$PERL5LIB":%{_perl_extra_path}

%_perl_buildroot	$(DESTDIR_REDIRECT)

# Install by default in vendor, add INSTALLDIRS=perl or site, if appropriate.
%perl_configure() %{_perl5lib} \
  test -z "$CFLAGS" && export CFLAGS="%{optflags}" \
  %{__perl} Makefile.PL 'PREFIX=%{_perl_buildroot}%{_prefix}' INSTALLDIRS=vendor %* \
  %{__perl} -pi -e 's/^\tLD_RUN_PATH=[^\s]+\s*/\t/' Makefile \
  %{nil}

%perl_make %{_perl5lib}\
  %{__make} OPTIMIZE="$RPM_OPT_FLAGS" \
  %{nil}


%perl_makecheck() %{_perl5lib}\
%if %{?_without_check:0}%{!?_without_check:1}\
%{__make} test %*\
%endif \
%{nil}


# removed second find, FC4's find looks broken ... (?)
%perl_makeinstall_nofc4() %{_perl5lib}\
%{__make} install DESTDIR_REDIRECT=%{buildroot} %*\
find %{buildroot} \\( -name .packlist -or -name perllocal.pod -or \\( -name '*.bs' -a -empty \\) \\) -exec rm -f {} \\;\
find %{buildroot} -type d -depth -empty -exec rmdir {} \\; \
%{nil}

%perl_makeinstall() %{_perl5lib}\
%{__make} install DESTDIR_REDIRECT=%{buildroot} %*\
find %{buildroot} \\( -name .packlist -or -name perllocal.pod -or \\( -name '*.bs' -a -empty \\) \\) -exec rm -f {} \\;\
%{nil}

# Some distributions use a different compiler than the default one for
# building the kernel
%_kernelcompiler %(echo %{expand:%%_kernelcompiler_%{distid}} | grep '^%' > /dev/null && echo /usr/bin/gcc || echo %{expand:%%_kernelcompiler_%{distid}})
%_kernelcompiler_fc1 /usr/bin/gcc32

%kmdl_kernelsrcdir      /lib/modules/%(rpm -q `rpm -q kernel >/dev/null && echo kernel || echo kernel-core ` | sed "s@kernel-core-@@" | sed "s@kernel-@@" | sort -Vr | head -n1 | tr -d '\n')/build
#%kmdl_kernelsrcdir	/lib/modules/%(rpm -q --queryformat "%{VERSION}-%{RELEASE}.%{ARCH} " `rpm -q kernel >/dev/null && echo kernel || echo kernel-core ` | xargs -n1 | sort -Vr | sed -n 1p | tr -d '\n' )/build
%_unamer		%(/usr/lib/rpm/atrpms/find-unamer.sh "%{kmdl_kernelsrcdir}")

%kmdl_userland		%(test "%{_kpkgname}" = "%%{_kpkgname}" && echo 1 || echo 0)

%_kflavour	%(echo %{_unamer} | grep -E '(smp|bigmem|hugemem|largesmp|xen0|xenU|xen|kdump|debug|PAE|PAEdebug)' | sed -e's/^.*\\(smp\\|bigmem\\|hugemem\\|largesmp\\|xen0\\|xenU\\|xen\\|kdump\\|debug\\|PAE\\|PAEdebug\\).*$/\\1/')

%_unamer_noflavour	%(echo %{_unamer} | sed -e's/^\\(.*\\)\\(smp\\|bigmem\\|hugemem\\|largesmp\\|xen0\\|xenU\\|xen\\|kdump\\|debug\\|PAE\\|PAEdebug\\).*$/\\1/')
%_unamer_noarch		%(echo %{_unamer} | sed -e's/\\.%{_target_cpu}//')

# The name of the kernel with flavour ("kernel", "kernel-smp", ...)
%_kname		%(echo kernel-%{_kflavour} | sed -e's/-$//')

# "_unamer": the output of "uname -r" of the kernel to build for
# (default: the running one)
# "_kernelsrcdir": The directory of the sources used to build "kernel"
# (default: /lib/modules/%{_unamer}/build)

#
%kmdl_name_with_arch %{_kpkgname}-kmdl-%{_unamer}
%kmdl_name %{_kpkgname}-kmdl-%{_unamer_noarch}
%kmdl_nameof() %1-kmdl-%{_unamer_noarch}
%kmdl_namepure %{_kpkgname}-kmdl

%_kernelbuildreq %{nil}

%kmdl() \
%{expand:%%global _kpkgname %1} \
%_kernelbuildreq \
%{nil}

%kmdl_parentdependencies\
Requires: %{kmdl_namepure}-%{evr}

%kmdl_dependencies\
Requires: /boot/vmlinuz-%{_unamer}\
Requires: %__depmod\
Conflicts: modutils < 2.4.14\
BuildRequires: %_kernelcompiler\
Provides: %kmdl_namepure-%{evr}\
Provides: %kmdl_namepure-%_unamer = %{evr}\
Provides: %kmdl_name_with_arch\
Provides: kernel-modules = %{_unamer}\
#\
# backward compatibility kernel-module-foo\
Obsoletes: kernel-module-%{_kpkgname}\
Obsoletes: kernel-module-%{_kpkgname}-%{evr}\
Obsoletes: kernel-module-%{_kpkgname}-%_unamer <= %{evr}

%kmdl_moduledir /lib/modules/%{_unamer}/updates

%kmdl_config %{nil}

%kmdl_desc\
This package contains the %_kpkgname kernel modules for the Linux kernel package:\
%{_kname}-%{_unamer_noflavour}.%{_target_cpu}.rpm.

%kmdl_install\
depmod -ae -F /boot/System.map-%{_unamer} %{_unamer} > /dev/null 2>&1 || :

%kmdl_remove\
depmod -ae -F /boot/System.map-%{_unamer} %{_unamer} > /dev/null 2>&1 || :
#######################################################################################################
%__lib_name() lib%(echo %1 | grep '[0-9]$' > /dev/null && echo %{1}_%2 || echo %1%2)

%lib_package() \
%global __lib_dependencies %{?__lib_dependencies:%(echo -n %__lib_dependencies | sed -e's,%%,%%%%,g'),}%%%%{__lib_name %1 %2} = %{evr}\
%global __lib_packages %{?__lib_packages:%(echo %__lib_packages | sed -e's,%%,%%%%,g')}%%%%{__lib_package %1 %2}\
%global __lib_package_list %{?__lib_package_list:%(echo %__lib_package_list | sed -e's,%%,%%%%,g')} %1 %2


%__lib_package() \
%global _enable_devel_packages 1\
%global __the_lib_name lib%(echo %1 | grep '[0-9]$' > /dev/null && echo %{1}_%2 || echo %1%2)\
%package -n %__the_lib_name\
Summary: Shared libraries for package %{name}\
Group: System Environment/Libraries\
Provides: shared-library-package\
%(echo %__the_lib_name | grep -- - > /dev/null && echo "Obsoletes: %__the_lib_name" | sed -e's,-,,g')\
%description -n %__the_lib_name\
This package provides the shared libraries lib%1.so.%{2}* for the package %{name}.\
Shared libraries are required at runtime for software built against %{name}.\
Keeping shared libraries in a separate package enables their use as\
forward/backward compatibility packages.\
%post -n %__the_lib_name -p %__ldconfig\
%postun -n %__the_lib_name -p %__ldconfig\
%if %{kmdl_userland}\
%files -n %__the_lib_name -f %{__the_lib_name}.list \
%endif\
%{nil}

%lib_dependencies %{?__lib_dependencies:Requires: %{expand:%__lib_dependencies}}

%devel_extra_Requires() \
%global __devel_extra_Requires %{?__devel_extra_Requires:%__devel_extra_Requires, }%*

%devel_extra_Obsoletes() \
%global __devel_extra_Obsoletes %{?__devel_extra_Obsoletes:%__devel_extra_Obsoletes, }%*

%devel_extra_Provides() \
%global __devel_extra_Provides %{?__devel_extra_Provides:%__devel_extra_Provides, }%*

%devel_extra_Conflicts() \
%global __devel_extra_Conflicts %{?__devel_extra_Conflicts:%__devel_extra_Conflicts, }%*

#
%devel_package \
%global __devel_package 1\
%package devel\
Summary: Development files for building against the %{name} package\
Group: Development/Libraries\
%lib_dependencies\
%{?__devel_extra_Requires:Requires: %{__devel_extra_Requires}}\
%{?__devel_extra_Obsoletes:Obsoletes: %{__devel_extra_Obsoletes}}\
%{?__devel_extra_Provides:Provides: %{__devel_extra_Provides}}\
%{?__devel_extra_Conflicts:Conflicts: %{__devel_extra_Conflicts}}\
%description devel\
This package provides the files necessary for development against\
%{name}. Use this package if you need to build a package depending on\
%{name} at build time, or if you want to do your own development\
against %{name}.\
%if %{kmdl_userland}\
%files devel -f develfiles.list\
%defattr(-,root,root,-)\
%endif\
%{nil}

%__lib_install_post \
   /usr/lib/rpm/atrpms/find-lib.sh %{buildroot} %{_builddir}/%{buildsubdir} %{__lib_package_list} \
%{nil}

%__devel_install_post   \
   /usr/lib/rpm/atrpms/find-devel.sh %{buildroot} %{_builddir}/%{buildsubdir}\
%{nil}
# /etc/rpm/macros.bcond
# macros used in rpm 4.4, not available in previous versions
%bcond_with()		%{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
%bcond_without()	%{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}
%with()		%{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without()	%{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}
