#!/bin/sh

#get date:
date_string=`date`

# init config file:
cat > ../test/regression.cfg << EOF
//
// regression test script for boost configuration setup
//
run libs/config/test/config_info.cpp
run libs/config/test/config_test.cpp
run libs/config/test/limits_test.cpp

EOF

# init main config test file:
cat > ../test/config_test.cpp << EOF
//  (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Test file for config setup
// This file should compile, if it does not then
// one or more macros need to be defined.
// see boost_*.cxx for more details

// Do not edit this file, it was generated automatically by
// ../tools/generate from boost_*.cxx on
// $date_string

#include <boost/config.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include "test.hpp"

EOF

all_no=""
all_has=""

#
# enumerate through the boost_no* test files:
#
for file in ../test/boost_no_*.cxx; do

	basename=`echo $file | sed 's/.*boost_\(.*\)\.cxx/\1/'`
	macroname=`cat $file | grep '^//[ 	]*MACRO:' | sed 's/.*MACRO:[ 	]*\([_A-Z0-9]*\).*/\1/'`
	title=`cat $file | grep '^//[ 	]*TITLE:' | sed 's/.*TITLE:[ 	]*\([^ 	].*\)/\1/'`
	namespace=`echo $macroname | tr [:upper:] [:lower:]`
	
#	echo $basename
	echo
	echo "processing $macroname ..."
#	echo $title
#	echo $namespace
	# now create positive test file:
	if test -f "../test/$basename""_pass.cpp"; then
		echo "skipping file ../test/$basename""_pass.cpp"
	else
		echo "generating file ../test/$basename""_pass.cpp"
	cat > "../test/$basename""_pass.cpp" << EOF

//  (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Test file for macro $macroname
// This file should compile, if it does not then
// $macroname needs to be defined.
// see boost_$basename.cxx for more details

// Do not edit this file, it was generated automatically by
// ../tools/generate from boost_$basename.cxx on
// $date_string

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
#  undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>
#include <boost/test/cpp_main.cpp>
#include "test.hpp"

#ifndef $macroname
#include "boost_$basename.cxx"
#else
namespace ${namespace} = empty_boost;
#endif

int cpp_main( int, char *[] )
{
	return ${namespace}::test();
}	
	
EOF

	fi
	
	# now create negative test file:
	if test -f "../test/$basename""_fail.cpp"; then
		echo "skipping file ../test/$basename""_fail.cpp"
	else
		echo "generating file ../test/$basename""_fail.cpp"
	cat > "../test/$basename""_fail.cpp" << EOF

//  (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Test file for macro $macroname
// This file should not compile, if it does then
// $macroname need not be defined.
// see boost_$basename.cxx for more details

// Do not edit this file, it was generated automatically by
// ../tools/generate from boost_$basename.cxx on
// $date_string

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
#  undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>
#include <boost/test/cpp_main.cpp>
#include "test.hpp"

#ifdef $macroname
#include "boost_$basename.cxx"
#else
#error "this file should not compile"
#endif

int cpp_main( int, char *[] )
{
	return ${namespace}::test();
}	
	
EOF
	fi
	
	# now append to config_test.cpp:
	cat >> "../test/config_test.cpp" << EOF
#ifndef $macroname
#include "boost_$basename.cxx"
#else
namespace ${namespace} = empty_boost;
#endif
EOF
	all_no="$namespace $all_no"

	# output regression tests:
	echo "run libs/config/test/$basename""_pass.cpp" >> ../test/regression.cfg
	echo "link-fail libs/config/test/$basename""_fail.cpp" >> ../test/regression.cfg
	
	
done

#
# enumerate through the boost_has* test files:
#
for file in ../test/boost_has_*.cxx; do

	basename=`echo $file | sed 's/.*boost_\(.*\)\.cxx/\1/'`
	macroname=`cat $file | grep '^//[ 	]*MACRO:' | sed 's/.*MACRO:[ 	]*\([_A-Z0-9]*\).*/\1/'`
	title=`cat $file | grep '^//[ 	]*TITLE:' | sed 's/.*TITLE:[ 	]*\([^ 	].*\)/\1/'`
	namespace=`echo $macroname | tr [:upper:] [:lower:]`
	
#	echo $basename
	echo
	echo "processing $macroname ..."
#	echo $title
#	echo $namespace

	# now create positive test file:
	if test -f "../test/$basename""_pass.cpp"; then
		echo "skipping file ../test/$basename""_pass.cpp"
	else
		echo "generating file ../test/$basename""_pass.cpp"
	cat > "../test/$basename""_pass.cpp" << EOF

//  (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Test file for macro $macroname
// This file should compile, if it does not then
// $macroname should not be defined.
// see boost_$basename.cxx for more details

// Do not edit this file, it was generated automatically by
// ../tools/generate from boost_$basename.cxx on
// $date_string

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
#  undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>
#include <boost/test/cpp_main.cpp>
#include "test.hpp"

#ifdef $macroname
#include "boost_$basename.cxx"
#else
namespace ${namespace} = empty_boost;
#endif

int cpp_main( int, char *[] )
{
	return ${namespace}::test();
}	
	
EOF
	fi

	# now create negative test file:
	if test -f "../test/$basename""_fail.cpp"; then
		echo skipping file "../test/$basename""_fail.cpp"
	else
		echo generating file "../test/$basename""_fail.cpp"
	cat > "../test/$basename""_fail.cpp" << EOF

//  (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Test file for macro $macroname
// This file should not compile, if it does then
// $macroname may be defined.
// see boost_$basename.cxx for more details

// Do not edit this file, it was generated automatically by
// ../tools/generate from boost_$basename.cxx on
// $date_string

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
#  undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>
#include <boost/test/cpp_main.cpp>
#include "test.hpp"

#ifndef $macroname
#include "boost_$basename.cxx"
#else
#error "this file should not compile"
#endif

int cpp_main( int, char *[] )
{
	return ${namespace}::test();
}	
	
EOF
	fi

	# now append to config_test.cpp:
	cat >> "../test/config_test.cpp" << EOF
#ifdef $macroname
#include "boost_$basename.cxx"
#else
namespace ${namespace} = empty_boost;
#endif
EOF
	all_has="$namespace $all_has"

	# output regression tests:
	echo "run libs/config/test/$basename""_pass.cpp" >> ../test/regression.cfg
	echo "link-fail libs/config/test/$basename""_fail.cpp" >> ../test/regression.cfg
	
done


#
# finish off config_test.cpp:
#
	echo generating "../test/config_test.cpp"
	cat >> "../test/config_test.cpp" << EOF

int test_main( int, char *[] )
{
EOF

for macro in $all_no; do
	cat >> "../test/config_test.cpp" << EOF
	BOOST_TEST(0 == ${macro}::test());
EOF

done
for macro in $all_has; do
	cat >> "../test/config_test.cpp" << EOF
	BOOST_TEST(0 == ${macro}::test());
EOF

done
	cat >> "../test/config_test.cpp" << EOF
	return 0;
}
EOF

#rm -f ../config.*
echo "updating configure script..."
autoconf ../tools/configure.in > ../configure
echo










