#!/bin/sh


	export RPM_SOURCE_DIR="/home/metalsoft/RPM/SOURCES"
	export RPM_BUILD_DIR="/home/metalsoft/RPM/BUILD"
	export RPM_OPT_FLAGS="-pipe -Wall -O2 -march=i586 -mcpu=i686"
	export RPM_ARCH="i586"
	export RPM_OS="linux"
	export RPM_DOC_DIR="/usr/share/doc"
	export RPM_PACKAGE_NAME="zabbix"
	export RPM_PACKAGE_VERSION="1.4.2"
	export RPM_PACKAGE_RELEASE="alt1"
	export RPM_BUILD_ROOT="/home/metalsoft/tmp/zabbix-buildroot"
	export RPM_CLEANUP_METHOD="auto"
	export RPM_COMPRESS_METHOD="auto"
	export RPM_FIXUP_METHOD="binconfig pkgconfig libtool"
	export RPM_STRIP_METHOD="executable shared"
	export RPM_VERIFY_ELF_METHOD="normal"
	
	
	export RPM_FINDREQ_DEFAULT_METHOD="files lib pam perl python tcl shell"
	export RPM_FINDPROV_DEFAULT_METHOD="lib pam perl python tcl shell"
	export RPM_CLEANUP_TOPDIR=""
	export RPM_COMPRESS_TOPDIR="/usr"
	export RPM_FIXUP_TOPDIR=""
	export RPM_STRIP_TOPDIR=""
	export RPM_VERIFY_ELF_TOPDIR=""
	export RPM_FINDREQ_TOPDIR=""
	export RPM_FINDPROV_TOPDIR=""
	export RPM_CLEANUP_SKIPLIST=""
	export RPM_COMPRESS_SKIPLIST=""
	export RPM_FIXUP_SKIPLIST=""
	export RPM_STRIP_SKIPLIST="*/debug/*"
	export RPM_VERIFY_ELF_SKIPLIST=""
	export RPM_FINDREQ_SKIPLIST="/usr/share/doc/*"
	export RPM_FINDPROV_SKIPLIST="/usr/share/doc/*"
	export RPM_FINDPROV_LIB_PATH="/lib:/usr/lib:/usr/X11R6/lib:/lib64:/usr/lib64:/usr/X11R6/lib64"
	
	export RPM_PERL_REQ_METHOD="normal"
	export RPM_PYTHON_LIB_PATH=""""
	export RPM_PYTHON_MODULE_DECLARED=""""
	
	export RPM_PYTHON_REQ_METHOD="slight"
	export RPM_PYTHON_REQ_SKIP=""""
	export RPM_PYTHON_COMPILE_METHOD="ALL"
	export RPM_PYTHON_COMPILE_EXCLUDE="/usr/share/doc"
	export RPM_PYTHON_COMPILE_INCLUDE="/usr/lib"
	export RPM_PYTHON_COMPILE_DEEP="20"
	export RPM_PYTHON_COMPILE_SKIP_X="1"
	export RPM_PYTHON_COMPILE_CLEAN="1"
	export RPM_TCL_LIB_PATH=""""
	export RPM_TCL_REQ_METHOD="normal"
	export RPM_TCL_REQ_SKIP=""""
	
	
	
	
	export RPM_PYTHON="/usr/bin/python"
	export RPM_TCLSH="/usr/bin/tclsh"
	
	unset LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION LC_ALL ||:
	
	
	unset DISPLAY XAUTHORITY ||:
	
	
	
	unset CCACHE_CC CCACHE_CXX CCACHE_DIR ||:
	
	
	
	
	export RPM_LIB="lib"
	export RPM_LIBDIR="/usr/lib"
	
	unset AUTOCONF_VERSION AUTOMAKE_VERSION LIBTOOL_VERSION GCC_VERSION ||:
	
	
	
	
	
	export PAM_SO_SUFFIX="%{_pam_so_suffix}"
	export PAM_NAME_SUFFIX="%{_pam_name_suffix}"
	
	export MAKEFLAGS="-w PAM_SO_SUFFIX=%_pam_so_suffix"
	
	set -x
	umask 022
	/bin/mkdir -p /home/metalsoft/RPM/BUILD
	cd /home/metalsoft/RPM/BUILD



cd zabbix-1.4.2
%__autoreconf

# we must call this for produce dbsync.h
pushd create/schema
./gen.pl c >../../include/dbsync.h
popd

# temporary hack
chmod +x configure


  CFLAGS="${CFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export FFLAGS ; 
   
   
  [ -f configure.ac -o -f configure.in ] && libtoolize --copy --force ; 
  ./configure --build=i586-alt-linux --host=i586-alt-linux \
 	--prefix=/usr \
	--exec-prefix=/usr \
	--bindir=/usr/bin \
	--sbindir=/usr/sbin \
	--sysconfdir=/etc \
	--datadir=/usr/share \
	--includedir=/usr/include \
	--libdir=/usr/lib \
	--libexecdir=/usr/lib \
	--localstatedir=/var/lib \
	--sharedstatedir=/usr/com \
	--mandir=/usr/share/man \
	--infodir=/usr/share/info \
	--without-included-gettext --with-mysql \
	--with-net-snmp \
	--enable-server \
	--enable-agent \
	--with-ldap \
	--with-curl \
	--with-jabber
make

mv src/zabbix_server/zabbix_server src/zabbix_server/zabbix_mysql
make clean


  CFLAGS="${CFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--pipe -Wall -O2 -march=i586 -mcpu=i686}" ; export FFLAGS ; 
   
   
  [ -f configure.ac -o -f configure.in ] && libtoolize --copy --force ; 
  ./configure --build=i586-alt-linux --host=i586-alt-linux \
 	--prefix=/usr \
	--exec-prefix=/usr \
	--bindir=/usr/bin \
	--sbindir=/usr/sbin \
	--sysconfdir=/etc \
	--datadir=/usr/share \
	--includedir=/usr/include \
	--libdir=/usr/lib \
	--libexecdir=/usr/lib \
	--localstatedir=/var/lib \
	--sharedstatedir=/usr/com \
	--mandir=/usr/share/man \
	--infodir=/usr/share/info \
	--without-included-gettext --with-pgsql \
	--with-net-snmp \
	--enable-server \
	--enable-agent \
	--with-ldap \
	--with-curl \
	--with-jabber
make

mv src/zabbix_server/zabbix_server src/zabbix_server/zabbix_pgsql

# create database schemas
pushd create/schema
make dist-hook distdir=.
popd

# adjust in several files /home/zabbix
for file in misc/conf/*; do
  sed -i -e "s,/home/zabbix/bin,/usr/sbin,g" \
         -e "s,PidFile=/var/tmp,PidFile=/var/run/zabbix,g" \
         -e "s,LogFile=/tmp,LogFile=/var/log/zabbix,g" \
         -e "s,/home/zabbix/lock,/var/lock/subsys/zabbix,g" \
	 -e "s,/tmp/mysql.sock,/var/lib/mysql/mysql.sock,g" $file
done


exit 0
