Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / GHSWorkspaceCreator.pm
blob4cc9dd2a1527c7f1a28e8c4ad40a3a67f95956eb
1 package GHSWorkspaceCreator;
3 # ************************************************************
4 # Description : A GHS Workspace creator for version 4.x
5 # Author : Chad Elliott
6 # Create Date : 7/3/2002
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use GHSProjectCreator;
16 use WorkspaceCreator;
17 use GHSPropertyBase;
19 use vars qw(@ISA);
20 @ISA = qw(GHSPropertyBase WorkspaceCreator);
22 # ************************************************************
23 # Data Section
24 # ************************************************************
26 my %directives = ('I' => 1,
27 'L' => 1,
28 'D' => 1,
29 'l' => 1,
30 'G' => 1,
31 'non_shared' => 1,
32 'bsp' => 1,
33 'os_dir' => 1,
35 my $tgt;
36 my $integrity = '[INTEGRITY Application]';
37 my @integ_bsps;
39 # ************************************************************
40 # Subroutine Section
41 # ************************************************************
43 sub compare_output {
44 #my $self = shift;
45 return 1;
49 sub workspace_file_name {
50 return $_[0]->get_modified_workspace_name('default', '.gpj');
54 sub pre_workspace {
55 my($self, $fh) = @_;
56 my $crlf = $self->crlf();
57 my $prjs = $self->get_projects();
59 ## Take the primaryTarget from the first project in the list
60 if (defined $$prjs[0]) {
61 my $fh = new FileHandle();
62 my $outdir = $self->get_outdir();
63 if (open($fh, "$outdir/$$prjs[0]")) {
64 while(<$fh>) {
65 if (/^#primaryTarget=(.+)$/) {
66 $tgt = $1;
67 last;
70 close($fh);
74 ## Print out the preliminary information
75 print $fh "#!gbuild$crlf",
76 "primaryTarget=$tgt$crlf",
77 "[Project]$crlf",
78 "\t--one_instantiation_per_object$crlf",
79 "\t:sourceDir=.$crlf",
80 "\t--std$crlf",
81 "\t-language=cxx$crlf",
82 "\t--long_long$crlf",
83 "\t--new_style_casts$crlf";
87 sub create_integrity_project {
88 my($self, $int_proj, $project, $type, $target) = @_;
89 my $outdir = $self->get_outdir();
90 my $crlf = $self->crlf();
91 my $fh = new FileHandle();
92 my $int_file = $int_proj;
93 $int_file =~ s/\.gpj$/.int/;
95 if (open($fh, ">$outdir/$int_proj")) {
96 ## First print out the project file
97 print $fh "#!gbuild$crlf",
98 "\t$integrity$crlf",
99 "$project\t\t$type$crlf",
100 "$int_file$crlf";
101 foreach my $bsp (@integ_bsps) {
102 print $fh "$bsp$crlf";
104 close($fh);
106 ## Next create the integration file
107 if (open($fh, ">$outdir/$int_file")) {
108 print $fh "Kernel$crlf",
109 "\tFilename\t\t\tDynamicDownload$crlf",
110 "EndKernel$crlf$crlf",
111 "AddressSpace$crlf",
112 "\tFilename\t\t\t$target$crlf",
113 "\tLanguage\t\t\tC++$crlf",
114 "\tLibrary\t\t\t\tlibINTEGRITY.so$crlf",
115 "\tLibrary\t\t\t\tlibc.so$crlf",
116 "\tLibrary\t\t\t\tlibscxx_e.so$crlf",
117 "\tTask Initial$crlf",
118 "\t\tStackLength\t\t0x8000$crlf",
119 "\tEndTask$crlf",
120 "EndAddressSpace$crlf";
121 close($fh);
127 sub mix_settings {
128 my($self, $project) = @_;
129 my $rh = new FileHandle();
130 my $mix = $project;
131 my $outdir = $self->get_outdir();
133 ## Things that seem like they should be set in the project
134 ## actually have to be set in the controlling project file.
135 if (open($rh, "$outdir/$project")) {
136 my $crlf = $self->crlf();
137 my $integrity_project = (index($tgt, 'integrity') >= 0);
138 my($int_proj, $int_type, $target);
140 while(<$rh>) {
141 if (/^\s*(\[(Program|Library|Subproject)\])\s*$/) {
142 my $type = $1;
143 if ($integrity_project && $type eq '[Program]') {
144 $int_proj = $project;
145 $int_proj =~ s/(\.gpj)$/_int$1/;
146 $int_type = $type;
147 $mix =~ s/(\.gpj)$/_int$1/;
148 $type = $integrity;
150 $mix .= "\t\t$type$crlf" .
151 "\t-object_dir=" . $self->mpc_dirname($project) .
152 '/.obj' . $crlf;
154 elsif (/^\s*(\[Shared Object\])\s*$/) {
155 $mix .= "\t\t$1$crlf" .
156 "\t-pic$crlf" .
157 "\t-object_dir=" . $self->mpc_dirname($project) .
158 '/.shobj' . $crlf;
160 elsif ($integrity_project && /^(.*\.bsp)\s/) {
161 push(@integ_bsps, $1);
163 else {
164 if (/^\s*\-((\w)\w*)/) {
165 ## Save the required options into the mixed project string
166 if (defined $directives{$2} || defined $directives{$1}) {
167 $mix .= $_;
170 ## If this is an integrity project, we need to find out
171 ## what the output file will be for the integrate file.
172 if (defined $int_proj && /^\s*\-o\s+(.*)\s$/) {
173 $target = $1;
178 if (defined $int_proj) {
179 $self->create_integrity_project($int_proj, $project,
180 $int_type, $target);
182 close($rh);
185 return $mix;
189 sub write_comps {
190 my($self, $fh) = @_;
192 ## Print out each projet
193 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
194 print $fh $self->mix_settings($project);