#! /usr/bin/env perl

$gCONFIG="DoxyfileWithVersion";

sub makeconfig {
  #旧バージョンでは cldaq-config --version が使えない
  #$version = `$ENV{"CLDAQ_INSTALL"}/config/scripts/cldaq-config --version`;
  #chop($version);
  $version = &getversion();

  open(IN, "Doxyfile");
  open(OUT, "> DoxyfileWithVersion");
  while (<IN>) {
    if ( $_ =~ /^PROJECT_NUMBER/ ) {
      print OUT "PROJECT_NUMBER         = $version\n";
    } else {
      print OUT "$_";
    }
  }
  close(IN);
  open(OUT);
}

sub latex {
  system("cd latex && make");
  system("cd latex && pdvips -o refman.ps -t a4 refman.dvi");
  system("cd latex && make ps_2on1");
}

sub getversion {
  $h="$ENV{'CLDAQ_INSTALL'}/source/system/Ttypes.h";
  open( IN, $h );
  while (<IN>) {
    if ( $_ =~ /^static const Tstring Tversion = "([0-9]+\.[0-9]+\.[0-9]+)";$/ ) {
      $ver = $1;
    }
  }
  close(IN);
  return $ver;
}

sub main {
  &makeconfig();
  system("doxygen $gCONFIG");
  &latex();
}

&main();

1;
