## ======================================================================

%_rpmconfigdir		%{!?getconfdir:/opt/osstech/lib/rpm}

## RHEL 5+ compatibility
## ----------------------------------------------------------------------

%defined()		%{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%undefined()		%{expand:%%{?%{1}:0}%%{!?%{1}:1}}

%with()			%{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without()		%{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}

%bcond_with()		%{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
%bcond_without()	%{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}

## Vendor specific macros
## ======================================================================

%vendor_name		%{?_with_vendor_name}%{!?_with_vendor_name:OSS Technology Corp.}
%vendor_nickname	%{?_with_vendor_nickname}%{!?_with_vendor_nickname:OSSTech}
%vendor_url		%{?_with_vendor_url}%{!?_with_vendor_url:http://www.osstech.co.jp/}
%vendor_id		%{?_with_vendor_id}%{!?_with_vendor_id:osstech}
%vendor_info		%{?_with_vendor_info}%{!?_with_vendor_info:OSS Technology Corp. <http://www.osstech.co.jp/>}
%vendor_name_prefix	%{vendor_id}-

## ----------------------------------------------------------------------

%vendor_prefix		/opt/%{vendor_id}
%vendor_exec_prefix	%{vendor_prefix}
%vendor_bindir		%{vendor_exec_prefix}/bin
%vendor_sbindir		%{vendor_exec_prefix}/sbin
%vendor_libdir		%{vendor_exec_prefix}/%{_lib}
%vendor_libexecdir	%{vendor_exec_prefix}/libexec
%vendor_includedir	%{vendor_prefix}/include
%vendor_sysconfdir	%{vendor_prefix}/etc
%vendor_sharedstatedir	%{vendor_prefix}/com
%vendor_localstatedir	%{vendor_prefix}/var
%vendor_rundir		%{vendor_localstatedir}/run
%vendor_vardir		%{vendor_localstatedir}/lib
%vendor_datadir		%{vendor_prefix}/share
%vendor_infodir		%{vendor_prefix}/share/info
%vendor_mandir		%{vendor_prefix}/share/man
%vendor_docdir		%{vendor_prefix}/share/doc
%vendor_svdir		%{vendor_localstatedir}/lib/sv

%_prefix		%{vendor_prefix}
%_exec_prefix		%{vendor_exec_prefix}
%_bindir		%{vendor_bindir}
%_sbindir		%{vendor_sbindir}
## See OSSTech ticket:41
## "%%{?name_dist:/%%{name_dist}" is for backward compatibility
%_includedir		%{vendor_includedir}%{?dist_name:/%{dist_name}}%{?name_dist:/%{name_dist}}
%_libdir		%{vendor_libdir}%{?dist_name:/%{dist_name}}%{?name_dist:/%{name_dist}}
%_libexecdir		%{vendor_libexecdir}
%_sysconfdir		%{vendor_sysconfdir}
%_sharedstatedir	%{vendor_sharedstatedir}
%_localstatedir		%{vendor_localstatedir}
%_rundir		%{vendor_rundir}
%_vardir		%{vendor_vardir}
%_datadir		%{vendor_datadir}
%_infodir		%{vendor_infodir}
%_mandir		%{vendor_mandir}
%_docdir		%{vendor_docdir}
%_defaultdocdir		%{vendor_docdir}
%_svdir			%{vendor_svdir}

%_initddir		/etc/init.d
# Deprecated misspelling, present for backwards compatibility.
%_initrddir		%{_initddir}
%_pamddir		/etc/pam.d

## ----------------------------------------------------------------------

%with_vendor		1
%vendor_release		%{nil}
%vendor_rpmconfigdir	%{_rpmconfigdir}/%{vendor_id}
%vendor_rpmhome		%{vendor_rpmconfigdir}
%vendor_rpmmacros	%{vendor_rpmconfigdir}/macros

%name_prefix		%{vendor_name_prefix}
%ver_rel		%{?epoch:%{epoch}:}%{version}-%{release}

## ======================================================================

%___vendor_build_pre \
eval "`env |sed -n 's/^\\([a-zA-Z0-9_]*\\)=.*$/unset \\1 || :/p' |egrep -v ' (_|PATH|PWD|LOGNAME) '`"\
LC_ALL="C"\
PATH="%{vendor_bindir}:%{?___platform_path}%{!?___platform_path:/usr/sbin:/usr/bin:/sbin:/bin}"\
export LC_ALL PATH\
%{___build_pre}\
CC="%{__cc}"\
CPP="%{__cpp}"\
CXX="%{__cxx}"\
CPPFLAGS="$CPPFLAGS"\
CFLAGS="-O -g${CFLAGS:+ $CFLAGS}"\
CXXFLAGS="-O -g${CXXFLAGS:+ $CXXFLAGS}"\
#LDFLAGS="-L/XXXX/lib -R/XXXX/lib${LDFLAGS:+ $LDFLAGS}"\
#PKG_CONFIG_PATH="/XXXX/lib/pkgconfig:/XXXX/share/pkgconfig:/usr/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"\
PERL="%{__perl}"\
export CC CPP CXX CPPFLAGS CFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH PERL\
%{?___platform_build_pre}\
%{nil}

%___build_template	#!%{___build_shell}\
%{___vendor_build_pre}\
%{nil}
%__spec_prep_pre	%{___vendor_build_pre}
%__spec_build_pre	%{___vendor_build_pre}
%__spec_install_pre	%{___vendor_build_pre}
%__spec_check_pre	%{___vendor_build_pre}
%__spec_clean_pre	%{___vendor_build_pre}

%_install_script_path	%{vendor_bindir}:%{?___platform_path}%{!?___platform_path:/usr/sbin:/usr/bin:/sbin:/bin}

## Override %%__os_install_post not to strip binaries by brp-strip-*
%__os_install_post \
if [ x"$(uname -s)" = x"Linux" ]; then\
  %{_rpmconfigdir}/brp-compress\
fi\
%{nil}

## Use own dependency generator to generate vendor-specific libs info
%_use_internal_dependency_generator 0

## WARNING: Do not split %%__find_provides and %%__find_requires definition
## into the multiple lines because RPM cannot treat it in some situation!
%__find_provides %{vendor_rpmconfigdir}/find-provides --perl-provides "%{__perl_provides}" --python-provides "%{__python_provides}" --mono-provides "%{__mono_provides}" %{buildroot} %{_libdir}
%__find_requires %{vendor_rpmconfigdir}/find-requires --perl-requires "%{__perl_requires}" --python-requires "%{__python_requires}" --mono-requires "%{__mono_requires}" %{buildroot} %{_libdir}

## ======================================================================

%vendor_package \
Vendor: %{vendor_info}\
Requires(pre): %{vendor_id}-base >= 3.0\
Provides: %{vendor_id}-package = 3.0\
%{nil}

%vendor_build_env() \
[ -f "%{vendor_rpmconfigdir}/%{1}-build.env" ] && . "%{vendor_rpmconfigdir}/%{1}-build.env"\
%{nil}

## OSSTech GCC uses ld-wrapper script, that emulates SVR4 ld(1)
%vendor_pkg_config_path() \
PKG_CONFIG_PATH="%{vendor_libdir}/%{1}/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"\
%ifos %{solaris} %{os_aix}\
LDFLAGS="-Wl,-R%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
%ifos linux\
LDFLAGS="-Wl,-rpath,%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
export PKG_CONFIG_PATH LDFLAGS\
%{nil}

## OSSTech GCC uses ld-wrapper script, that emulates SVR4 ld(1)
%vendor_build_flags() \
CPPFLAGS="-I%{vendor_includedir}/%{1}${CPPFLAGS:+ $CPPFLAGS}"\
%ifos %{solaris} %{os_aix}\
LDFLAGS="-L%{vendor_libdir}/%{1} -Wl,-R%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
%ifos linux\
LDFLAGS="-L%{vendor_libdir}/%{1} -Wl,-rpath,%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
export CPPFLAGS LDFLAGS\
## Create a temporary prefix directory in $RPM_BUILD_DIR for a library\
## and set the prefix location into $%%{1}_prefix variable.\
## Some configure scripts expect that *.h and *.so files for a required\
## library are located in %%{_prefix}/include and %%{_prefix}/lib, that is,\
## %%{_prefix}/include/%%{name} and %%{_prefix}/lib/%%{name} are not usable.\
## See also: OSSTech ticket:41\
_vendor_tmp="%{1}_prefix"\
_vendor_tmp="${_vendor_tmp//[^a-z_0-9]/_}"\
eval "${_vendor_tmp}='$RPM_BUILD_DIR/%{name}-%{version}-%{release}-buildrequires-prefix/%{1}'"\
eval "rm -rf \\"\\$${_vendor_tmp}\\""\
eval "mkdir -p \\"\\$${_vendor_tmp}\\""\
eval "ln -s '%{vendor_includedir}/%{1}%{?2}' \\"\\$${_vendor_tmp}/include\\""\
eval "ln -s '%{vendor_libdir}/%{1}%{?2}' \\"\\$${_vendor_tmp}/lib\\""\
unset _vendor_tmp\
[ -f "%{vendor_rpmconfigdir}/%{1}-build.env" ] && . "%{vendor_rpmconfigdir}/%{1}-build.env"\
%{expand:%%{?vendor_%{1}_build_flags}}\
%{nil}

## OSSTech GCC uses ld-wrapper script, that emulates SVR4 ld(1)
%vendor_ld_run_path() \
%ifos %{solaris} %{os_aix}\
export LDFLAGS="-Wl,-R%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
%ifos linux\
export LDFLAGS="-Wl,-rpath,%{vendor_libdir}/%{1}${LDFLAGS:+ $LDFLAGS}"\
%endif\
%{nil}

