Skip to content

Commit b085809

Browse files
authored
Merge pull request #230 from mitza-oci/ghs-update
Updated Green Hills Integrity (ghs) project generation
2 parents 4abacbc + 9842d6f commit b085809

File tree

5 files changed

+133
-49
lines changed

5 files changed

+133
-49
lines changed

modules/GHSProjectCreator.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ use vars qw(@ISA);
2525
# Data Section
2626
# ************************************************************
2727

28+
my %templates = ('ghs' => '.gpj',
29+
'ghscmd' => '.cmd');
30+
my @tkeys = sort keys %templates;
31+
my $default_template = 'ghs';
32+
2833
my $startre;
2934

3035
# ************************************************************
@@ -67,6 +72,7 @@ sub post_file_creation {
6772
return undef;
6873
}
6974

75+
7076
sub compare_output {
7177
#my $self = shift;
7278
return 1;
@@ -79,6 +85,26 @@ sub project_file_extension {
7985
}
8086

8187

88+
sub get_template {
89+
return $ENV{MPC_GHS_GENERATE_CMD} ? @tkeys : $_[0]->{'pctype'};
90+
}
91+
92+
93+
sub file_visible { # (self, template)
94+
return $_[1] eq $default_template;
95+
}
96+
97+
98+
sub project_file_name {
99+
my($self, $name, $template) = @_;
100+
my $project_file_name = $self->SUPER::project_file_name($name, $template);
101+
if (!$self->file_visible($template)) {
102+
$project_file_name =~ s/\.gpj$/.cmd/;
103+
}
104+
return $project_file_name;
105+
}
106+
107+
82108
sub fill_value {
83109
my($self, $name) = @_;
84110
my $value;

modules/GHSWorkspaceCreator.pm

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ sub workspace_file_name {
5050
return $_[0]->get_modified_workspace_name('default', '.gpj');
5151
}
5252

53+
sub is_absolute_path {
54+
my $path = shift;
55+
return ($path =~ /^\/.+/ || $path =~ /^[a-zA-Z]:.+/);
56+
}
5357

5458
sub pre_workspace {
5559
my($self, $fh) = @_;
@@ -60,7 +64,9 @@ sub pre_workspace {
6064
if (defined $$prjs[0]) {
6165
my $fh = new FileHandle();
6266
my $outdir = $self->get_outdir();
63-
if (open($fh, "$outdir/$$prjs[0]")) {
67+
my $fullpath = is_absolute_path($$prjs[0]) ? $$prjs[0] : "$outdir/$$prjs[0]";
68+
69+
if (open($fh, $fullpath)) {
6470
while(<$fh>) {
6571
if (/^#primaryTarget=(.+)$/) {
6672
$tgt = $1;
@@ -71,51 +77,82 @@ sub pre_workspace {
7177
}
7278
}
7379

80+
## Try to read the INTEGRITY installation directory and BSP name from environment.
81+
## Default values are the installation directory on Windows and the BSP name
82+
## for the simulator for PowerPC architecture.
83+
my $ghs_os_dir = defined $ENV{GHS_OS_DIR} ? $ENV{GHS_OS_DIR} : 'C:\ghs\int1146';
84+
my $ghs_bsp_name = defined $ENV{GHS_BSP_NAME} ? $ENV{GHS_BSP_NAME} : "sim800";
85+
7486
## Print out the preliminary information
7587
print $fh "#!gbuild$crlf",
88+
"import ACE_ROOT$crlf",
89+
"import TAO_ROOT$crlf",
90+
'defineConfig(Debug dbg "")', $crlf,
91+
'defineConfig(Release rel "")', $crlf,
92+
"macro __OS_DIR=$ghs_os_dir$crlf",
93+
"macro __BSP_NAME=$ghs_bsp_name$crlf",
94+
"macro __BSP_DIR=\${__OS_DIR}\\\${__BSP_NAME}$crlf",
95+
"macro __BUILD_DIR=\${ACE_ROOT}\\build$crlf",
96+
"macro __LIBS_DIR_BASE=\${__OS_DIR}\\libs$crlf",
7697
"primaryTarget=$tgt$crlf",
98+
"customization=\${__OS_DIR}\\target\\integrity.bod$crlf",
7799
"[Project]$crlf",
78-
"\t--one_instantiation_per_object$crlf",
100+
"\t-gcc$crlf",
101+
"\t--c++11$crlf",
79102
"\t:sourceDir=.$crlf",
80-
"\t--std$crlf",
103+
"\t:optionsFile=\${__OS_DIR}\\target\\\${__BSP_NAME}.opt$crlf",
104+
"\t-I\${ACE_ROOT}$crlf",
105+
"\t-I\${TAO_ROOT}$crlf",
81106
"\t-language=cxx$crlf",
82-
"\t--long_long$crlf",
83-
"\t--new_style_casts$crlf";
107+
"\t--new_style_casts$crlf",
108+
"\t-non_shared$crlf",
109+
"\t{config(dbg)}-G$crlf";
84110
}
85111

86-
112+
# Write a .int file processed by the Integrate tool to create a dynamic download image.
113+
# This file creates a single virtual AddressSpace with specific assumptions such as
114+
# the language being used is C++, the heap size, stack length of the Initial Task.
115+
# Specific application may need to update the generated .int file according to its needs.
116+
# For example, if the application requires working with a file system, use the MULTI IDE
117+
# GUI to add a file system module to the application; this will automatically update the
118+
# .int file. If the application requires more heap memory, manually update the HeapSize
119+
# line to increase the heap size.
87120
sub create_integrity_project {
88121
my($self, $int_proj, $project, $type, $target) = @_;
89122
my $outdir = $self->get_outdir();
90123
my $crlf = $self->crlf();
91124
my $fh = new FileHandle();
92125
my $int_file = $int_proj;
93126
$int_file =~ s/\.gpj$/.int/;
127+
my $int_file_base = $self->mpc_basename($int_file);
128+
my $project_base = $self->mpc_basename($project);
94129

95-
if (open($fh, ">$outdir/$int_proj")) {
130+
my $int_proj_path = is_absolute_path($int_proj) ? $int_proj : "$outdir/$int_proj";
131+
if (open($fh, ">$int_proj_path")) {
96132
## First print out the project file
97133
print $fh "#!gbuild$crlf",
98134
"\t$integrity$crlf",
99-
"$project\t\t$type$crlf",
100-
"$int_file$crlf";
135+
"$project_base\t\t$type$crlf",
136+
"$int_file_base$crlf";
101137
foreach my $bsp (@integ_bsps) {
102138
print $fh "$bsp$crlf";
103139
}
104140
close($fh);
105141

106142
## Next create the integration file
107-
if (open($fh, ">$outdir/$int_file")) {
143+
my $int_path = is_absolute_path($int_file) ? $int_file : "$outdir/$int_file";
144+
if (open($fh, ">$int_path")) {
108145
print $fh "Kernel$crlf",
109146
"\tFilename\t\t\tDynamicDownload$crlf",
110147
"EndKernel$crlf$crlf",
111148
"AddressSpace$crlf",
112149
"\tFilename\t\t\t$target$crlf",
113150
"\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",
151+
# Default heap size is 64kB.
152+
# Increase to 2MB here to cover more applications.
153+
"\tHeapSize\t\t\t0x200000$crlf",
117154
"\tTask Initial$crlf",
118-
"\t\tStackLength\t\t0x8000$crlf",
155+
"\t\tStackLength\t\t0xa000$crlf",
119156
"\tEndTask$crlf",
120157
"EndAddressSpace$crlf";
121158
close($fh);
@@ -130,43 +167,39 @@ sub mix_settings {
130167
my $mix = $project;
131168
my $outdir = $self->get_outdir();
132169

170+
# If the project file path is already an absolute path, use it.
171+
my $fullpath = is_absolute_path($project) ? $project : "$outdir/$project";
172+
133173
## Things that seem like they should be set in the project
134174
## actually have to be set in the controlling project file.
135-
if (open($rh, "$outdir/$project")) {
175+
if (open($rh, $fullpath)) {
136176
my $crlf = $self->crlf();
137177
my $integrity_project = (index($tgt, 'integrity') >= 0);
138178
my($int_proj, $int_type, $target);
139179

140180
while(<$rh>) {
181+
# Don't need to add compiler/linker options to the workspace file.
182+
# The .gpj file for each individual project should have those already.
183+
# In the workspace file, only need to list the child projects.
141184
if (/^\s*(\[(Program|Library|Subproject)\])\s*$/) {
142185
my $type = $1;
143186
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;
187+
$int_proj = $project; #E.g., tests/MyTest.gpj
188+
$int_proj =~ s/(\.gpj)$/_int$1/; #E.g., tests/MyTest_int.gpj
189+
$int_type = $type; #E.g., [Program]
190+
$mix =~ s/(\.gpj)$/_int$1/; #E.g., tests/MyTest_int.gpj
191+
$type = $integrity; # [INTEGRITY Application]
149192
}
150-
$mix .= "\t\t$type$crlf" .
151-
"\t-object_dir=" . $self->mpc_dirname($project) .
152-
'/.obj' . $crlf;
193+
$mix .= "\t\t$type$crlf";
153194
}
154195
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;
196+
$mix .= "\t\t$1$crlf";
159197
}
160198
elsif ($integrity_project && /^(.*\.bsp)\s/) {
161199
push(@integ_bsps, $1);
162200
}
163201
else {
164202
if (/^\s*\-((\w)\w*)/) {
165-
## Save the required options into the mixed project string
166-
if (defined $directives{$2} || defined $directives{$1}) {
167-
$mix .= $_;
168-
}
169-
170203
## If this is an integrity project, we need to find out
171204
## what the output file will be for the integrate file.
172205
if (defined $int_proj && /^\s*\-o\s+(.*)\s$/) {
@@ -189,12 +222,10 @@ sub mix_settings {
189222
sub write_comps {
190223
my($self, $fh) = @_;
191224

192-
## Print out each projet
225+
## Print out each project
193226
foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
194227
print $fh $self->mix_settings($project);
195228
}
196229
}
197230

198-
199-
200231
1;

templates/ghs.mpd

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
#!gbuild
22
#primaryTarget=<%primaryTarget("ppc_integrity.tgt")%>
33
<%if(exename)%>
4-
[Program]
5-
-o <%if(exeout)%><%reltop_exeout%><%else%><%reltop%><%endif%>/<%exename%><%if(use_exe_modifier)%><%lib_modifier%><%endif%><%exe_ext%>
4+
[Program]
5+
-o <%if(exeout)%><%exeout%>/<%endif%><%exename%><%if(use_exe_modifier)%><%lib_modifier%><%endif%><%exe_ext%>
66
<%if(need_staticflags)%>
7-
{optional} -non_shared
7+
-non_shared
88
<%endif%>
99
<%else%>
10-
<%if(sharedname)%>
11-
[Shared Object]
12-
-o <%if(dllout)%><%reltop_dllout%><%else%><%reltop_libout%><%endif%>/<%lib_prefix%><%libname_prefix%><%sharedname%><%if(use_lib_modifier)%><%lib_modifier%><%endif%><%libext(".so")%>
10+
<%comment("When sharedname is defined and staticname is not set in the mpc file,")%>
11+
<%comment("the staticname takes the same value as sharedname. The opposite is also true.")%>
12+
<%comment("Because of that, we can't condition only on whether either of them is defined.")%>
13+
<%comment("This fixes that by including the template input variable need_staticflags.")%>
14+
<%if(!need_staticflags && sharedname)%>
15+
[Shared Object]
16+
-o <%if(dllout)%><%dllout%><%else%><%libout%><%endif%>/<%lib_prefix%><%libname_prefix%><%sharedname%><%if(use_lib_modifier)%><%lib_modifier%><%endif%><%libext(".so")%>
1317
<%else%>
14-
<%if(staticname)%>
15-
[Library]
16-
-o <%reltop_libout%>/<%lib_prefix%><%libname_prefix%><%staticname%><%if(use_lib_modifier)%><%lib_modifier%><%endif%><%libext(".a")%>
18+
<%if(need_staticflags && staticname)%>
19+
[Library]
20+
-o <%libout%>/<%lib_prefix%><%libname_prefix%><%staticname%><%if(use_lib_modifier)%><%lib_modifier%><%endif%><%libext(".a")%>
1721
<%else%>
18-
[Subproject]
22+
[Subproject]
1923
<%endif%>
2024
<%endif%>
2125
<%endif%>
@@ -40,11 +44,11 @@
4044
-D<%pch_define%>
4145
<%endfor%>
4246
<%endif%>
43-
<%foreach(reltop_includes)%>
44-
-I<%reltop_include%>
47+
<%foreach(includes)%>
48+
-I<%include%>
4549
<%endfor%>
46-
<%foreach(reltop_libpaths)%>
47-
-L<%reltop_libpath%>
50+
<%foreach(libpaths)%>
51+
-L<%libpath%>
4852
<%endfor%>
4953
<%if(libs || lit_libs || pure_libs)%>
5054
<%if(exename || sharedname)%>
@@ -131,6 +135,8 @@
131135
<%if(!custom_only && source_files)%>
132136
<%foreach(custom_type->input_file->source_output_files)%>
133137
<%if(forfirst)%>
138+
<%if(remove_from(source_files, \.cpp, custom_type->input_file->source_output_file, \.cpp))%>
139+
<%endif%>
134140
<%custom_type->input_file->source_output_file%>
135141
<%endif%>
136142
<%endfor%>

templates/ghscmd.mpd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pushd <%convert_slashes(reltop)%>
2+
<%foreach(custom_types)%>
3+
<%foreach(custom_type->input_files)%>
4+
<%if(flag_overrides(custom_type->input_file, gendir))%>
5+
<%mkdir%> <%flag_overrides(custom_type->input_file, gendir)%><%postmkdir%>
6+
<%endif%>
7+
<%translate_vars(custom_type->command, win32)%> ^
8+
<%if(flag_overrides(custom_type->input_file, commandflags))%>
9+
<%translate_vars(flag_overrides(custom_type->input_file, commandflags), win32)%> ^
10+
<%else%>
11+
<%translate_vars(custom_type->commandflags, win32)%> ^
12+
<%endif%>
13+
<%if(custom_type->output_option)%>
14+
<%custom_type->input_file%> <%custom_type->output_option%> <%custom_type->input_file->output_file%>
15+
<%else%>
16+
<%custom_type->input_file%>
17+
<%endif%>
18+
<%endfor%>
19+
<%endfor%>
20+
popd

templates/ghscommon.mpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ conditional_include "unixcommon"
55
optimize = 1
66
exceptions = 1
77
lib_modifier =
8+
need_staticflags = 1

0 commit comments

Comments
 (0)