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

# ************************************************************
# Description   : A GNU Workspace (Makefile) 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 workspace_file_name {
  my($self) = shift;
  return $self->get_modified_workspace_name('Makefile', '');
}


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


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

  print $fh "#----------------------------------------------------------------------------$crlf" .
            "#       GNU ACE Workspace$crlf" .
            "#$crlf" .
            "# \@file Makefile$crlf" .                 
            "#$crlf" .
            "# \$Id\$$crlf" .
            "#$crlf" .
            "# This file was automatically generated by MPC.  Any changes made directly to$crlf" .
            "# this file will be lost the next time it is generated.$crlf" .
            "#$crlf" .
            "#----------------------------------------------------------------------------$crlf" .
            $crlf;
}


sub write_comps {
  my($self)     = shift;
  my($fh)       = shift;
  my($projects) = $self->get_projects();
  my($pjs)      = $self->get_project_info();
  my(@list)     = $self->sort_dependencies($projects, $pjs);
  my($crlf)     = $self->crlf();

  ## Print out the projet Makefile
  print $fh "include \$(ACE_ROOT)/include/makeinclude/macros.GNU$crlf" .
            "TARGETS_NESTED := \$(TARGETS_NESTED:.nested=)$crlf";

  ## Only use the list if there is more than one project
  if ($#list > 0) {
    print $fh "MFILES = \\$crlf";
    for(my $i = 0; $i <= $#list; $i++) {
      print $fh "         $list[$i]";
      if ($i != $#list) {
        print $fh ' \\';
      }
      print $fh $crlf;
    }
    print $fh $crlf .
              "MAKE_OPTIONS=\$(shell echo \$(MAKEFLAGS) | sed 's/--unix *//; s/ .*//')$crlf" .
              "ifeq (\$(findstring k,\$(MAKE_OPTIONS)),k)$crlf" .
              "  KEEP_GOING = 1$crlf" .
              "else$crlf" .
              "  KEEP_GOING = 0$crlf" .
              "endif$crlf";
  }

  print $fh $crlf .
            "\$(TARGETS_NESTED):$crlf";

  ## If there is more than one project, use a for loop
  if ($#list > 0) {
    my(@dirs)  = ();
    my(%added) = ();
    print $fh "ifeq (\$(KEEP_GOING),1)$crlf" .
              "\t\@for file in \$(MFILES); do \\$crlf" .
              "\t\$(MAKE) -f `basename \$\$file` -C `dirname \$\$file` \$(\@); \\$crlf" .
              "\tdone$crlf" .
              "else$crlf";
    foreach my $project (@list) {
      print $fh "\t\@\$(MAKE) -f " . basename($project) . ' -C ' . dirname($project) . " \$(\@);$crlf";
      my($dname) = dirname($project);
      if ($dname ne '.' && !defined $added{$dname}) {
        push(@dirs, $dname);
        $added{$dname} = 1;
      }
    }
    print $fh "endif$crlf";

    ## Print out the reverseclean target
    if (defined $dirs[0]) {
      print $fh $crlf .
                'DIRS = \\' . $crlf;
      for(my $i = 0; $i <= $#dirs; ++$i) {
        print $fh "  $dirs[$i]" . ($i != $#dirs ? ' \\' : '') . $crlf;
      }
      print $fh $crlf .
                "reverseclean:$crlf" .
                "\t\@\$(ACE_ROOT)/bin/reverse_clean \$(DIRS)$crlf";
    }
  }
  else {
    ## Otherwise, just list the call to make without a for loop
    my($dir)  = dirname($list[0]);
    my($base) = basename($list[0]);
    print $fh "\t\@\$(MAKE) -f $base " . ($dir ne '.' ? "-C $dir " : '') .
              "\$(\@);$crlf$crlf" .
              "reverseclean:$crlf" .
              "\t\@\$(MAKE) -f $base " . ($dir ne '.' ? "-C $dir " : '') .
              "realclean$crlf";
  }
}



1;