#  -*-Makefile-*-
#
#  Main authors:
#     Christian Schulte <schulte@gecode.org>
#     Guido Tack <tack@gecode.org>
#     Grégoire Dooms <dooms@info.ucl.ac.be>
#     
#
#  Copyright:
#     Christian Schulte, 2005
#     Guido Tack, 2005
#     Grégoire Dooms, 2005 
#
#  Last modified:
#     $Date: 2005-11-01 16:01:21 +0100 (Tue, 01 Nov 2005) $ by $Author: zayenz $
#     $Revision: 2465 $
#
#  This file is part of Gecode, the generic constraint
#  development environment:
#     http://www.gecode.org
#
#  Permission is hereby granted, free of charge, to any person obtaining
#  a copy of this software and associated documentation files (the
#  "Software"), to deal in the Software without restriction, including
#  without limitation the rights to use, copy, modify, merge, publish,
#  distribute, sublicense, and/or sell copies of the Software, and to
#  permit persons to whom the Software is furnished to do so, subject to
#  the following conditions:
#
#  The above copyright notice and this permission notice shall be
#  included in all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

CONTRIBS := $(shell ls -d contribs/* 2>/dev/null )

contribdirs:
	@rm -f configure.ac
	@(echo "dnl This file was generated by Makefile.contribs."; \
	  echo "dnl Do not edit! Modifications will get lost!"; \
	  echo "dnl Edit configure.ac.in instead."; echo ""; \
	  cat configure.ac.in \
	 ) > configure.ac
	@for i in $(CONTRIBS); do \
	  if test ! -d $$i ; then continue ; fi; \
	  if test -f $$i.dis* ; then \
	  	echo "Skipping disabled contrib $$i"; \
	  elif test -f $$i/configure -a '(' -f $$i/vti.ac -o -f $$i/shortdesc.ac ')' ; then \
	    mv configure.ac configure.ac.1; \
	    sed -e "s|\(dnl @SUBDIRS@\)|AC_CONFIG_SUBDIRS($$i) \1|g" \
	    configure.ac.1 > configure.ac; \
	    if test -f $$i/vti.ac; then \
	  		echo "Add variable contrib from $$i"; \
	  		mv configure.ac configure.ac.1; \
	  		(sed -e "s|\(dnl @VTIS@\)|m4_include($$i/vti.ac) \1|g" \
	   		configure.ac.1 > configure.ac); \
	    else \
			mv configure.ac configure.ac.1; \
	  		echo "Add contrib from $$i"; \
			DESC="`head -n 1 $$i/shortdesc.ac`"; \
			sed -e "s|\(dnl @CONTRIBS@\)|AC_GECODE_ENABLE_CONTRIB($${i#*\/},\"$$DESC\",[]) \1|g" \
			configure.ac.1 > configure.ac; \
		fi ;\
	  else \
	    if test ! -f $$i/configure; then \
	  		echo "Skipping contrib $$i : no configure script"; \
	    else \
	  		echo "Skipping contrib $$i : no shortdescr.ac or vis.ac file "; \
	    fi; \
	  fi;\
	done
	@rm -f configure.ac.1
	@echo "\n// STATISTICS: support-any\n" >> gecode/support/config.hpp.in
	@echo Running autoconf on generated configure.ac ...
	@autoconf
	@autoheader
	@mv gecode/support/config.hpp.in config.hpp.in.1
	@perl misc/fixautoheader.perl < config.hpp.in.1 \
	      > gecode/support/config.hpp.in
	@rm config.hpp.in.1
	@echo done.
