summaryrefslogtreecommitdiff
path: root/lib/sbin/CreateConfigurationBindings.pl
blob: 3a04a219474c0b0ef53d71a546678d9d42cbe1a0 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#/*@@
#  @file      CreateConfigurationBindings.pl
#  @date      Thu Mar 25 14:25:13 2004
#  @author    Yaakoub Y El-Khamra
#  @desc
#             New Configuration.ccl script processing
#  @enddesc
#  @version   $Header$
#@@*/


require "$sbin_dir/CSTUtils.pl";

#/*@@
#  @routine    CreateScheduleBindings
#  @date       Thu Mar 25 14:25:13 2004
#  @author     Yaakoub Y El-Khamra
#  @desc
#              Creates the configuration bindings.
#  @enddesc
#@@*/
sub CreateConfigurationBindings
{
  my($bindings_dir, $cfg, $thorns)=@_;
  my($field, $providedcap, $thorn, $temp);

  if(! $build_dir)
  {
    $build_dir = "$bindings_dir/build";
  }

  if(! -d $bindings_dir)
  {
    mkdir("$bindings_dir", 0755) || die "Unable to create $bindings_dir";
  }

  $start_dir = `pwd`;

  chdir $bindings_dir;

  if(! -d 'Configuration')
  {
    mkdir('Configuration', 0755) || die 'Unable to create Configuration directory';
  }

  if(! -d 'include')
  {
    mkdir('include', 0755) || die 'Unable to create include directory';
  }

  if(! -d "$build_dir")
  {
    mkdir("$build_dir", 0755) || die "Unable to create $build_dir";
  }

  foreach $thorn (sort keys %thorns)
  {
    if ($cfg->{"\U$thorn\E REQUIRES"} || $cfg->{"\U$thorn\E OPTIONAL"})
    { 
      if(! -d "$bindings_dir/Configuration/$thorn")
      {
        mkdir("$bindings_dir/Configuration/$thorn", 0755) || die "Unable to create Thorn $thorn Configuration directory"; 
      }
    }
  }

  # this string goes into the cactus executable directly 
  my $linkerflagdirs = '';
  my $linkerflaglibs = '';

  # here we put all the PROVIDES to where they belong
  foreach $thorn (sort keys %thorns)
  {
    # we know that all the requirements have been satisfied
    # so all we need to do is put the provides where they belong
    # and make references to them from the requirements and optional
    # since we can have multiple provides, we make each capability
    # separate
    if ($cfg->{"\U$thorn\E PROVIDES"})
    {
      my $codedef       = '';
      my $codedep       = '';
      my $incdir        = '';
      my $lib           = '';
      my $libdir        = '';
      my $thornDefnFile = '';
      my $thornDepsFile = '';

      foreach $providedcap (split (' ', $cfg->{"\U$thorn\E PROVIDES"}))
      {
        $providedcaplist .= $providedcap;
        if ( $cfg->{"\U$thorn $providedcap\E DEFINE"} )
        {
          &WriteFile("include/\U$providedcap\E.h",\$cfg->{"\U$thorn $providedcap\E DEFINE"});    
        }
        if ( $cfg->{"\U$thorn $providedcap\E MAKE_DEFINITION"} )
        {
          $codedef = $cfg->{"\U$thorn $providedcap\E MAKE_DEFINITION"}; 
          &WriteFile("$bindings_dir/Configuration/make.\U$providedcap\E.defn",\$cfg->{"\U$thorn $providedcap\E MAKE_DEFINITION"});
        } 
        if ( $cfg->{"\U$thorn $providedcap\E MAKE_DEPENDENCY"} )
        {
          $codedep = $cfg->{"\U$thorn $providedcap\E MAKE_DEPENDENCY"}; 
          &WriteFile("$bindings_dir/Configuration/make.\U$providedcap\E.deps",\$cfg->{"\U$thorn $providedcap\E MAKE_DEPENDENCY"});
        } 
        if ( $cfg->{"\U$thorn $providedcap\E INCLUDE_DIRECTORY"} )
        {
          $incdir = $cfg->{"\U$thorn $providedcap\E INCLUDE_DIRECTORY"};
        } 
        if ( $cfg->{"\U$thorn $providedcap\E LIBRARY"} )
        {
#          print "\nlibs\n";
          $lib = $cfg->{"\U$thorn $providedcap\E LIBRARY"};
        } 
        if ( $cfg->{"\U$thorn $providedcap\E LIBRARY_DIRECTORY"} )
        {
#          print "\ndirs\n";
          $libdir = $cfg->{"\U$thorn $providedcap\E LIBRARY_DIRECTORY"};
        }
        
        # Now put the stuff from the provide in the required and options
        foreach $temp (sort keys %thorns)
        {
          foreach $requiredcap (split (' ', $cfg->{"\U$temp\E REQUIRES"}))           
          { 
            if ( $requiredcap eq $providedcap )
            { 
              if ( $codedef ne '' )
              { 
                $thornDefnFile .= "-include $bindings_dir/Configuration/make.\U$providedcap\E.defn\n";
              }
              if ( $codedep ne '' )
              {
                $thornDepsFile .= "-include $bindings_dir/Configuration/make.\U$providedcap\E.deps\n";
              }
              if ( $incdir ne '' )
              { 
                $thornDefnFile .= "INC_DIRS += $incdir\n";
              }
              if ( $libdir ne '' )
              { 
                $linkerflagdirs .= $libdir . " ";
              }
              if ( $lib ne '' )
              { 
                $linkerflaglibs .= $lib . " ";
              }
              if(! -d "Configuration/$temp")
              {
                mkdir("Configuration/$temp", 0755) || die "Unable to create Configuration/$temp directory";
              }
              &WriteFile("$bindings_dir/Configuration/$temp/make.configuration.defn",\$thornDefnFile);
              &WriteFile("$bindings_dir/Configuration/$temp/make.configuration.deps",\$thornDepsFile);
            }
          }
          foreach $requiredcap (split (' ', $cfg->{"\U$temp\E OPTIONAL"}))           
          { 
            if ( $requiredcap eq $providedcap )
            { 
              if ( $codedef ne '' )
              { 
                $thornDefnFile .= "-include $bindings_dir/Configuration/make.\U$providedcap\E.defn\n";
              }
              if ( $codedep ne '' )
              {
                $thornDepsFile .= "-include $bindings_dir/Configuration/make.\U$providedcap\E.deps\n";
              }
              if ( $incdir ne '' )
              { 
                $thornDefnFile .= "INC_DIRS += $incdir\n";
              }
              if ( $libdir ne '' )
              { 
                $linkerflagdirs .= $libdir . " ";
              }
              if ( $lib ne '' )
              { 
                $linkerflaglibs .= $lib . " ";
              }
              if(! -d "Configuration/$temp")
              {
                mkdir("Configuration/$temp", 0755) || die "Unable to create Configuration/$temp directory";
              }
              &WriteFile("$bindings_dir/Configuration/$temp/make.configuration.defn",\$thornDefnFile);
              &WriteFile("$bindings_dir/Configuration/$temp/make.configuration.deps",\$thornDepsFile);
            }
          }
        }
      }
    }
  }  
  

  $linkerflagdirs = "LIBDIRS += " . $linkerflagdirs;
  $linkerflaglibs = "LIBS += " . $linkerflaglibs;

  $linkerflagdirs = $linkerflagdirs . "\n" . $linkerflaglibs;

  &WriteFile("$bindings_dir/Configuration/make.link",\$linkerflagdirs);

}

return 1;