#!/bin/csh
###################################################
if( $#argv >= 1 ) then
  if( "$1" == "-h" ) then
    echo "mkmf [module1] [module2] [...]"
    echo "  generate documentation for all Sophya"
    echo "  or only for module [module]"
    exit 0
  endif
endif

##########################################
######## Test de la configuration ########
##########################################

# mydoxy.conf
cp dox_sophya.conf mydoxy.conf
foreach n ( 1 2 3 4 5 )
  echo " " >> mydoxy.conf
end

# doxygen ?
which doxygen >! /dev/null
if( $status != 0 ) then
  echo 'ERROR: doxygen is not installed...'
  exit -1
endif

# doxysearch ?
which doxysearch >! /dev/null
if( $status != 0 ) then
  echo 'ERROR: doxysearch is not installed...'
  exit -2
else
    set s = `which doxysearch`
  echo 'doxysearch is installed in :'
  echo $s:h
  echo 'mkmf will automatically update the config file.'
    echo "BIN_ABSPATH = $s:h" >>  mydoxy.conf
    grep 'BIN_ABSPATH' mydoxy.conf | grep -v ^\#
endif

# partial doc ?
if( $#argv >= 1 ) then
  echo Partial doc generation :
    set lf =
    foreach f ( $* )
      echo "... adding ../$f to INPUT"
      set lf = ( ../$f $lf )
    end
    echo "INPUT = $lf" >>  mydoxy.conf
    grep 'INPUT = ' mydoxy.conf | grep -v ^\# | tail -1
endif

#########################################
######## Creation de la Makefile ########
#########################################

rm -f Makefile
touch Makefile
chmod +x Makefile
cat >> Makefile << EOF_
all: doc

clean:
	rm -rf html latex man rtf *.o dox_filter

doc: filter
	doxygen mydoxy.conf

filter: dox_filter

dox_filter : dox_filter.o

dox_filter.o : dox_filter.c

EOF_

exit 0
