summaryrefslogtreecommitdiff
path: root/lib/sbin/BuildHeaders.pl
blob: 9ab4e6eb4107a3e4aa076eefe9d75b0cb35b95af (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /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
#@@*/


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 delete all global include files since we will be appending
  foreach $thorn (split(" ",$interface_database{"THORNS"}))
  {
    foreach $inc_file (split(" ",$interface_database{"\U$thorn USES HEADER"}))
    {
      if (-e $inc_file)
      {
	system("rm $inc_file");
      }
    }
  }

# Create all the global include files used by thorns
  foreach $thorn (split(" ",$interface_database{"THORNS"}))
  {
    foreach $inc_file (split(" ",$interface_database{"\U$thorn USES HEADER"}))
    {
      if (!-e $inc_file)
      {
	open(OUT,">$inc_file") || die "Cannot open $inc_dir";
	print OUT "/* Include file $inc_file used by $thorn */\n";
	close OUT;
      }
      else
      {
	open(OUT,">>$inc_file") || die "Cannot open $inc_dir";
	print OUT "/* Include file $inc_file used by $thorn */\n";
	close OUT;
      }
    }
  }

# 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
	  open(OUT,">>$inc_file2") || die "Cannot open $inc_dir2";
	  print OUT "/* 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>)
	    {
	      print OUT;
	    }
	    print OUT "\n\n\n";
	    close HEADER;
	  }
	  elsif (-e "$cctk_home/arrangements/$arrangement/$thorn/src/include/$inc_file1")
	  {
	    open(HEADER,"<$cctk_home/arrangements/$arrangement/$thorn/src/$inc_file1");
	    while (<HEADER>)
	    {
	      print OUT;
	    }
	    print OUT "\n\n\n";
	    close HEADER;
	  }
	  else
	  {
	    $message = "Include file $inc_file1 not found in $arrangement/$thorn\n";
	    &CST_error(0,$message,__LINE__,__FILE__);
	  }
	  print OUT "/* End of include file $inc_file1 from $thorn */\n";
	  close OUT;
      }
    }
  }

  chdir $start_dir;
  return;

}

1;