
# -*-perl-*- hey - emacs - this is a perl file

=comment

Copyright (c) 2003-2010, Andrew Dunstan

See accompanying License file for license details

=cut 


package PGBuild;

use strict;

use vars qw(%conf);

# use vars qw($VERSION); $VERSION = 'REL_4.5';

my $branch;
{
	no warnings qw(once);
	$branch = $main::branch;
}

%conf = 
	(
	 scm => 'git', # or 'cvs'
	 scmrepo => undef , # default is community repo for either type
	 scm_url => undef, # webref for diffs on server - use default for community
	 # git_reference => undef, # for --reference on git repo
	 # cvsmethod => 'update', # or 'export'
	 use_git_cvsserver => undef, # or 'true' if repo is a git cvsserver
	 make => 'make', # or gmake if required. can include path if necessary.
	 tar_log_cmd => undef, # default is "tar -z -cf runlogs.tgz *.log"
	                       # replacement must have the same effect
	 # must be absolute, can be either Unix or Windows style for MSVC
	 build_root => 'P:\PgBuildFarm\build_root',
	 use_vpath => undef, # set true to do vpath builds

     # path to directory with auxiliary web script 
     # if relative, the must be relative to buildroot/branch
	 # possibly only necessary now on WIndows, if at all
     aux_path => "../..",

	 keep_error_builds => 0,
	 target => "http://www.pgbuildfarm.org/cgi-bin/pgstatus.pl",
	 upgrade_target => "http://www.pgbuildfarm.org/cgi-bin/upgrade.pl",
	 animal => "CHANGEME",
	 secret => "CHANGEME",

	 # change this to a true value if using MSVC, in which case also
	 # see MSVC section below

	 using_msvc => 1,

	 # if force_every is a scalar it will be used on all branches, like this
	 # for legacy reasons:
	 # force_every => 336 , # max hours between builds, undef or 0 = unforced
	 # we now prefer it to be a hash with branch names as the keys, like this
	 #
	 # this setting should be kept conservatively high, or not used at all  - 
	 # for the most part it's best to let the script decide if something 
	 # has changed that requires a new run for the branch.
	 #
	 # an entry with a name of 'default' matches any branch not named
	 force_every => {
		 # HEAD => 48,
		 # REL8_3_STABLE => 72,
		 # default => 168,
	 },


	 # alerts are triggered if the server doesn't see a build on a branch after
	 # this many hours, and then sent out every so often,

	 alerts => {
		 #HEAD          => { alert_after => 72,  alert_every => 24 },
		 # REL8_1_STABLE => { alert_after => 240, alert_every => 48 },
	 },

	 print_success => undef,

	 # pattern for files whose changes do NOT trigger a build
	 # use qr[/(doc|po)/] to ignore changes to docs and po files (recommended)
	 # undef means don't ignore anything.
	 trigger_filter => qr[/(doc|po)/] ,

	 # settings for mail notices - default to notifying nobody
	 # these lists contain addresses to be notified
	 # must be complete email addresses, as the email is sent from the server

	 mail_events =>
	 {
		 all => [], # unconditional
		 fail => [], # if this build fails
		 change => [], # if this build causes a state change
		 green => [], # if this build causes a state change to/from OK
	 },
		 
	 # env settings to apply within build/report process
	 # these settings will be seen by all the processes, including the
	 # configure process.

	 build_env =>
	 {
		 # use a dedicated cache for the build farm. this should give us
		 # very high hit rates and slightly faster cache searching.

		 CCACHE_DIR => "/home/andrew/pgfarmbuild/ccache/$branch", 

         ### use these settings for CYGWIN
         # CYGWIN => 'server',
         # MAX_CONNECTIONS => '3',

		 ### set this if you need a proxy setting for the
		 # outbound web transaction that reports the results
		 # BF_PROXY => 'http://my.proxy.server:portnum/',

		 # see below for MSVC settings

	 },
	 # env settings to pass to configure. These settings will only be seen by 
	 # configure.
	 config_env => 
	 { 
		 CC => 'ccache gcc', 
	 },


	 # don't use --prefix or --with-pgport here 
	 # they are set up by the script
     # per-branch config can be done here or
     # more simply by using the examples below.
	 # (default ldap flag is below because it's not supported in all branches)

	 # see below for MSVC config

	 config_opts => 
	 [qw(
		 --enable-cassert 
		 --enable-debug
		 --enable-nls
		 --enable-integer-datetimes
		 --with-perl 
		 --with-python 
		 --with-tcl
		 --with-krb5 --with-includes=/usr/include/et
		 --with-openssl		 
		 )],

	 # per-branch contents of extra config for check stage
	 # each branch has an array of setting lines (no \n required)
	 extra_config => 
	 {
		 HEAD => [
				  q(log_line_prefix = '[%c:%l] '),
				  "log_connections = 'true'",
				  "log_disconnections = 'true'",
				  "log_statement = 'all'"
				  ],
	 },

	 optional_steps => 
     {
      # which optional steps to run and when to run them
      # valid keys are: branches, dow, min_hours_since, min_hour, max_hour
	  # find_typedefs => { branches => ['HEAD'], dow => [1,4],
	  #	 			       min_hours_since => 25 },
	  # build_docs => {min_hours_since => 24},
	 }, 

	 # locales to test

	 locales => [ qw( C )],

	 # port number actually used will be based on this param and the branch,
	 # so we ensure they don't collide

	 base_port => 5678,


	 );


# MSVC setup

if ($conf{using_msvc})
{

	# all this stuff is to support MSVC builds - it's literally what
	# a VS Command Prompt sets for me.
	# make sure it's what your sets for you. There can be subtle differences.
	# Note: we need to set here whatever would be set in buildenv.bat, as
	# we aren't going to write that file. This supercedes it. In 
	# particular, the PATH possibly needs to include the path to perl, bison,
	# flex etc., as well as CVS if that's not in the path.

	my %extra_buildenv = 
		(

		 VSINSTALLDIR => 'C:\Program Files (x86)\Microsoft Visual Studio 10.0',
		 VCINSTALLDIR => 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC',
		 VS80COMNTOOLS => 
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools',
		 VS100COMNTOOLS => 
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools',
		 FrameworkDir => 'C:\Windows\Microsoft.NET\Framework64',
		 FrameworkVersion => 'v4.0.30319',
		 FrameworkSDKDir => 
			 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\SDK\v3.5',
		 DevEnvDir => 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE',

		 PATH => join
		 (
		  ';' , 
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64',
		  'C:\Windows\Microsoft.NET\Framework64\v4.0.30319',
		  'C:\Windows\Microsoft.NET\Framework64\v3.5',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\VCPackages',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools',
		  'C:\Program Files (x86)\HTML Help Workshop',
		  'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64',
		  'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64',
		  'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin',
		  'C:\Program Files\Common Files\Microsoft Shared\Windows Live',
		  'C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live',
		  'C:\Perl64\bin',
		  'c:\prog\pgdepend\bin',
		  $ENV{PATH}
		  ),
		 INCLUDE => join
		 (
		  ';',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE',
		  'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include',
		  $ENV{INCLUDE}
		  ),
		 LIB => join
		 (
		  ';',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64',
		  'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64',
		  $ENV{LIB}
		  ),
		 LIBPATH => join
		 (
		  ';',
		  'C:\Windows\Microsoft.NET\Framework64\v4.0.30319',
		  'C:\Windows\Microsoft.NET\Framework64\v3.5',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64',
		  'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64'
		  ),
		 );

	%{$conf{build_env}} = (%{$conf{build_env}}, %extra_buildenv);

	 # MSVC needs a somewhat different style of config opts (why??)
	 # What we write here will be literally (via Data::Dumper) put into
	 # the config.pl file for the MSVC build.


	 $conf{config_opts} = 
	 {
		 asserts=>1,                     # --enable-cassert
		 integer_datetimes=>1,   # --enable-integer-datetimes
		 nls=>undef,                             # --enable-nls=<path>
		 tcl=>undef,          # --with-tls=<path>
		 perl=>'C:\Perl64',                        # --with-perl
		 python=>'C:\Python27', # --with-python=<path>
		 krb5=> undef, # 'c:\prog\pgsql\depend\krb5', # --with-krb5=<path>
		 ldap=>0,                        # --with-ldap
		 openssl=> undef, # 'c:\openssl', # --with-ssl=<path>
		 xml=> undef, # 'c:\prog\pgsql\depend\libxml2',
		 xslt=> undef, # 'c:\prog\pgsql\depend\libxslt',
		 iconv=> undef, # 'c:\prog\pgsql\depend\iconv',
		 zlib=> undef, # 'c:\prog\pgsql\depend\zlib', # --with-zlib=<path>
	 };

};
	

##################################
#
# examples of per branch processing
# tailor as required for your site.
#
##################################

# ldap support is new as of 8.2
if ($branch eq 'HEAD' || $branch ge 'REL8_2')
{
	# msvc can set it up separately - see above

	push(@{$conf{config_opts}},"--with-ldap")
		unless $conf{using_msvc};
}

# libxml/libxslt support as of 8.3
if ($branch eq 'HEAD' || $branch ge 'REL8_3')
{
        # msvc can set it up separately - see above

        push(@{$conf{config_opts}},"--with-libxml", "--with-libxslt")
                unless $conf{using_msvc};
}



if ($branch eq 'HEAD')
{
#	push(@{$conf{config_opts}},"--enable-depend");
}
elsif ($branch =~ /^REL7_/)
{
#    push(@{$conf{config_opts}},"--without-tk");
}


1;
