summaryrefslogtreecommitdiff
path: root/bin/MakeProjectCreator/modules/GNUACEWorkspaceCreator.pm
blob: a2c19cf6d14f5215aaedc4b904c9dce752aeaf10 (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
package GNUACEWorkspaceCreator;

# ************************************************************
# Description   : A GNU Workspace (GNUmakefile) creator for ACE
# Author        : Chad Elliott
# Create Date   : 5/13/2002
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;
use File::Basename;

use GNUACEProjectCreator;
use WorkspaceCreator;

use vars qw(@ISA);
@ISA = qw(WorkspaceCreator);

# ************************************************************
# Subroutine Section
# ************************************************************

sub generate_implicit_project_dependencies {
  #my($self) = shift;
  return 1;
}


sub workspace_file_name {
  my($self) = shift;
  return $self->get_modified_workspace_name('GNUmakefile', '');
}


sub workspace_per_project {
  #my($self) = shift;
  return 1;
}


sub pre_workspace {
  my($self) = shift;
  my($fh)   = shift;
  my($crlf) = $self->crlf();

  print $fh '# -*- makefile -*-', $crlf,
            '#-------------------------------------------------------------------------', $crlf,
            '#       GNU ACE Workspace', $crlf,
            '#', $crlf,
            '# $Id$', $crlf,
            '#', $crlf,
            '# This file was generated by MPC.  Any changes made directly to', $crlf,
            '# this file will be lost the next time it is generated.', $crlf,
            '#', $crlf,
            '# MPC Command:', $crlf,
            "# $0 @ARGV", $crlf,
            '#', $crlf,
            '#-------------------------------------------------------------------------', $crlf,
            'MAKEFILE = ', $self->get_current_output_name(), $crlf;
}


sub write_comps {
  my($self)    = shift;
  my($fh)      = shift;
  my($crlf)    = $self->crlf();
  my(%targnum) = ();
  my($pjs)     = $self->get_project_info();
  my(@list)    = $self->number_target_deps($self->get_projects(),
                                           $pjs, \%targnum);

  ## Print out some preliminary information
  print $fh $crlf,
            "ifeq (\$(findstring k,\$(MAKEFLAGS)),k)$crlf",
            "  KEEP_GOING = -$crlf",
            "endif$crlf$crlf",
            "include \$(ACE_ROOT)/include/makeinclude/macros.GNU$crlf",
            $crlf;

  ## Determine the ordering of the sub-directories
  my(@dirs)  = ();
  my(%found) = ();
  foreach my $file (reverse @list) {
    my($dir) = $self->get_first_level_directory($file);
    if ($dir ne '.') {
      if (!defined $found{$dir}) {
        $found{$dir} = 1;
        unshift(@dirs, $dir);
      }
    }
  }
  my($need_dirs) = ($#dirs > -1);

  ## Store the local projects in a separate list
  my(@lprj)   = ();
  my(%dirprj) = ();
  foreach my $project (@list) {
    if ($project !~ /\//) {
      push(@lprj, $project);
      if ($need_dirs && defined $targnum{$project}) {
        foreach my $number (@{$targnum{$project}}) {
          if ($list[$number] =~ /\//) {
            ## If any local project depends on a project that is not
            ## in this directory, we can not rely on the directory
            ## recursion to get the correct dependencies.  We will do
            ## all projects as local targets.
            @lprj = ();
            foreach my $prj (@list) {
              push(@lprj, $prj);
              if ($prj =~ /\//) {
                $dirprj{$prj} = 1;
              }
            }
            $need_dirs = 0;
            last;
          }
        }
        if (!$need_dirs) {
          last;
        }
      }
    }
  }

  if ($#lprj >= 0) {
    ## Print out the all target first.  This will allow multiple projects
    ## within the same directory to build in parallel.
    print $fh 'all:';
    foreach my $project (@lprj) {
      print $fh ' ', $$pjs{$project}->[0];
    }
    print $fh $crlf;
    if ($need_dirs) {
      foreach my $dir (@dirs) {
        print $fh "\t\$(KEEP_GOING)\@cd $dir && ",
                  "\$(MAKE) -f \$(MAKEFILE) \$(\@)$crlf";
      }
    }

    ## Print out each target separately.  Make can decide on which
    ## targets can be built in parallel because we add the local
    ## dependencies.
    foreach my $project (@lprj) {
      print $fh $crlf, '.PHONY: ', $$pjs{$project}->[0],
                $crlf, $$pjs{$project}->[0], ':';
      if (defined $targnum{$project}) {
        foreach my $number (@{$targnum{$project}}) {
          print $fh ' ', $$pjs{$list[$number]}->[0];
        }
      }
      print $fh $crlf,
                "\t\$(KEEP_GOING)\@";
      if (defined $dirprj{$project}) {
        print $fh "cd ", $self->mpc_dirname($project),
                  " && \$(MAKE) -f ", basename($project), $crlf;
      }
      else {
        print $fh "\$(MAKE) -f $project$crlf";
      }
    }
    print $fh $crlf,
              'REMAINING_TARGETS := ',
              '$(subst all, , $(TARGETS_NESTED:.nested=)) $(CUSTOM_TARGETS)',
              $crlf;
  }
  else {
    print $fh 'REMAINING_TARGETS := $(TARGETS_NESTED:.nested=) ',
              '$(CUSTOM_TARGETS)', $crlf;
  }

  ## Print out the remaing targets.
  ## They will be handled serially by make.
  print $fh "\$(REMAINING_TARGETS):$crlf";
  foreach my $project (@lprj) {
    print $fh "\t\$(KEEP_GOING)\@";
    if (defined $dirprj{$project}) {
      print $fh "cd ", $self->mpc_dirname($project),
                " && \$(MAKE) -f ", basename($project), " \$(\@)", $crlf;
    }
    else {
      print $fh "\$(MAKE) -f $project \$(\@)$crlf";
    }
  }
  if ($need_dirs) {
    foreach my $dir (@dirs) {
      print $fh "\t\$(KEEP_GOING)\@cd $dir && ",
                "\$(MAKE) -f \$(MAKEFILE) \$(\@)$crlf";
    }
  }
  print $fh $crlf;
}

1;