summaryrefslogtreecommitdiff
path: root/lib/sbin/BuildHeaders.pl
blob: 9dbd6e58d1bfa0ea393eab428483ac035fa41a41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /usr/bin/perl -s

#/*@@
#  @routine BuildHeaders
#  @date Sun 13 Sep 1999
#  @author Gabrielle Allen
#  @desc
#  Creates the dynamic header files requested in interface.ccl files
#  and writes them into the Bindings include directory
#  @enddesc
#  @calls
#  @calledby
#  @history
#  @endhistory
#@@*/

require "$sbin_dir/CSTUtils.pl";

sub BuildHeaders
{
  local($cctk_home,$bindings_dir,%database) = @_;
  local($start_dir,$thorn,$inc_file,$inc_file1,$inc_file2);

  $start_dir = `pwd`;
  chdir $bindings_dir;
  chdir include;

# First set all data strings 
  foreach $thorn (split(" ",$interface_database{"THORNS"}))
  {
    foreach $inc_file (split(" ",$interface_database{"\U$thorn USES HEADER"}))
    {
      $data{"$inc_file"} = "/* Include file $inc_file used by $thorn */\n";
    }
  }

# Add the local headers from thorns
  foreach $thorn (split(" ",$interface_database{"THORNS"}))
  {

    $arrangement = $interface_database{"\U$thorn ARRANGEMENT"};

    foreach $inc_file1 (split(" ",$interface_database{"\U$thorn ADD HEADER"}))
    {
      if ($inc_file1 !~ /^\s*$/)
      {
	$inc_file1 =~ s/ //g;
	$inc_file2 = $interface_database{"\U$thorn ADD HEADER $inc_file1 TO"};

	# Write information to the global include file
	$data{"$inc_file2"} .= "/* Including file $inc_file1 from $thorn */\n";
	
	# Now have to find the include file and copy it
	if (-e "$cctk_home/arrangements/$arrangement/$thorn/src/$inc_file1")
	{
	  open(HEADER,"<$cctk_home/arrangements/$arrangement/$thorn/src/$inc_file1");
	  while (<HEADER>)
	  {
	    $data{"$inc_file2"} .= $_;
	  }
	  $data{"$inc_file2"} .= "\n\n\n";
	  close HEADER;
	}
	elsif (-e "$cctk_home/arrangements/$arrangement/$thorn/src/include/$inc_file1")
	{
	  open(HEADER,"<$cctk_home/arrangements/$arrangement/$thorn/src/include/$inc_file1");
	  while (<HEADER>)
	  {
	    $data{"$inc_file2"} .= $_;
	  }
	  $data{"$inc_file2"} .= "\n\n\n";
	  close HEADER;
	}
	else
	{
	  $message = "Include file $inc_file1 not found in $arrangement/$thorn\n";
	  &CST_error(0,$message,__LINE__,__FILE__);
	}
	$data{"$inc_file2"} .= "/* End of include file $inc_file1 from $thorn */\n";
      }
    }
  }

  foreach $thorn (split(" ",$interface_database{"THORNS"}))
  {
    foreach $inc_file1 (split(" ",$interface_database{"\U$thorn USES HEADER"}))
    {
      &WriteFile($inc_file1,$data{"$inc_file1"});
    }
  }

  chdir $start_dir;
  return;

}

1;