6
my $libtool = "FREEHDL/libtool";
7
my $libtool_options = "--mode=link";
8
my $vhdl_source_name = "";
11
my $cpplibs = "-lm FREEHDL/kernel/libfreehdl-kernel.la FREEHDL/std/libfreehdl-std.la";
12
my $vhdl_library = ""; # Library the design entity is compiled into
13
my $cpp_options = "-static ";
14
my $vhdl_options = "";
15
my $no_cpp_compile = 0;
18
my $vhdl_libdir = "FREEHDL";
19
my $freehdl_root_path="";
21
# set root path of the FreeHDL system
22
sub set_freehdl_root_path {
23
$freehdl_root_path = $ENV{'FREEHDL'};
24
if ($freehdl_root_path ne "") { return; }
25
# if environment variable is not set then test
26
# each parent directory
29
# test whether $path is a valid path
30
if (not -d "$path/") { die "Could not find FreeHDL root path! Please set environment FREEHDL."; }
31
# is there a file named v2cc.libs in the directory?
32
if (not -f "$path/v2cc.libs") { $path = $path . "/.."; next; }
33
# open file and analyze content
34
open INFILE, "$path/v2cc.libs" or die "Could not read $path/v2cc.libs\n";
38
$text = $text . " " . $_;
41
if ($text !~ /std\s*:\s*std/i) { $found = 0; }
42
if ($text !~ /ieee\s*:\s*ieee/i) { $found = 0; }
44
# return result if freehdl root path was found
46
$freehdl_root_path = $path;
50
$path = $path . "/..";
57
s/FREEHDL/$freehdl_root_path/g;
64
my $label_text = $_[1];
66
open(COMMAND, "$cmd 2>&1 |");
68
print $out_file, "$label_text$_";
70
return close(COMMAND)? 0 : 256;
76
# determine root path of freehdl installation
77
set_freehdl_root_path;
78
print "gvhdl: FreeHDL root path is '$freehdl_root_path'.\n";
79
$includes = "-I $freehdl_root_path";
82
open(MSTREAM, ">&STDOUT");
83
open(PROGRESS_BAR, ">/dev/null");
85
$cpplibs = update($cpplibs);
86
$libtool = update($libtool);
87
$vhdl_libdir = update($vhdl_libdir);
91
my $create_simulator = 1;
94
while ($arg_index < scalar(@ARGV)) {
95
my $argument = $ARGV[$arg_index];
96
if ($argument =~ /^\-l/) {
97
die "gvhdl: Missing argument for '-l'!\n" if (++$arg_index >= scalar(@ARGV));
98
$vhdl_library = "-l " . $ARGV[$arg_index];
99
} elsif ($argument =~ /^\-C/) {
100
$cc = $ARGV[++$arg_index];
101
} elsif ($argument =~ /^\-FHDLgui/) {
102
# gvhdl will communiate with is caller via 2 sockets. The socket
103
# file names are generated from the base string passed over as a
104
# argument to option FHDLgui. The actual file names are derived
105
# by appending channel number 0 or 4 to the base name. Channel 0
106
# is used for printing messages generated during code
107
# generation/compilation/linking while channel 4 is used to
108
# print progress information.
109
my $socket_base_name = $ARGV[++$arg_index];
111
my $socket_name = $socket_base_name . "0";
112
socket(MSTREAM, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
113
connect(MSTREAM, sockaddr_un($socket_name)) || die "connect: $!";
115
my $socket_name = $socket_base_name . "4";
116
socket(PROGRESS_BAR, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
117
connect(PROGRESS_BAR, sockaddr_un($socket_name)) || die "connect: $!";
121
} elsif ($argument =~ /^\-L/) {
122
$vhdl_libdir .= " -L " . $ARGV[++$arg_index];
123
} elsif ($argument =~ /^\-R/) {
124
$vhdl_options = $vhdl_options . " -R";
125
} elsif ($argument =~ /^\-g/) {
126
$vhdl_options = $vhdl_options . " -g";
127
$cpp_options = $cpp_options . " -g";
128
} elsif ($argument =~ /^\-c/) {
130
$create_simulator = 0;
131
$cpp_options = $cpp_options . " -c";
132
} elsif ($argument =~ /^\-G/) {
133
$cpp_options = $cpp_options . " -g";
134
} elsif ($argument =~ /^\-v/) {
136
} elsif ($argument =~ /^\-V/) {
137
$vhdl_options = $vhdl_options . " -v";
138
} elsif ($argument =~ /^\-D/) {
139
$vhdl_options = $vhdl_options . " -D";
140
} elsif ($argument =~ /^\--relaxed-component-visibility/) {
141
$vhdl_options = $vhdl_options . " --relaxed-component-visibility";
142
} elsif ($argument =~ /^\--libieee/) {
143
$cpplibs .= " " . update ("FREEHDL/ieee/libieee.la");
144
} elsif ($argument =~ /^\-/) {
145
$cpp_options = $cpp_options . " " . $argument;
147
push @source_files, $argument;
153
my $steps = scalar(@source_files);
154
if ($no_cpp_compile == 0) { $steps *= 2; }
155
if ($do_link == 1) { $steps += 1; }
156
$steps = int(99 / $steps);
157
my $progress_value = 0;
159
##############################################################
160
# Create name for main file
161
##############################################################
164
if ($create_simulator == 1) {
165
$_ = $source_files [0];
166
if ($_ =~ /\.vhdl$/) { $main_vhdl_file = $_; }
167
s/\.[^\.]*$/\._main_/i;
168
$main_file_name = $_;
171
##############################################################
172
# process each source file
173
##############################################################
174
foreach $vhdl_source_name (@source_files) {
175
# skip object (*.o) files
176
if ($vhdl_source_name =~ /\.o$/) {
177
$object_files = $object_files . " " . $vhdl_source_name;
180
# skip object (*.a) files
181
if ($vhdl_source_name =~ /\.a$/) {
182
$object_files = $object_files . " " . $vhdl_source_name;
185
##############################################################
186
# Comiling vhdl -> cc
187
##############################################################
188
$_ = $vhdl_source_name;
190
my $out_file_name = $_;
193
if ($create_simulator == 1 &&
194
$main_vhdl_file == $vhdl_source_name) {
195
$cmd = "$freehdl_root_path/v2cc/freehdl-v2cc -m $main_file_name.cc -L $vhdl_libdir $vhdl_library $vhdl_options -o $out_file_name $vhdl_source_name";
197
$cmd = "$freehdl_root_path/v2cc/freehdl-v2cc -L $vhdl_libdir $vhdl_library $vhdl_options -o $out_file_name $vhdl_source_name";
199
print MSTREAM "gvhdl: executing '$cmd'\n";
200
if (execute_cmd ($cmd, "", $MSTREAM)/256 != 0) {
201
print MSTREAM "gvhdl: Compilation failed!\n";
202
print PROGRESS_BAR "99";
206
$progress_value = int($progress_value + $steps);
207
print PROGRESS_BAR $progress_value;
209
##############################################################
211
##############################################################
214
$object_files .= " " . $_;
216
if ($no_cpp_compile == 0) {
217
my $cmd = "$cc $cpp_options $includes -c $out_file_name";
218
print MSTREAM "gvhdl:\n";
219
print MSTREAM "gvhdl: ================================\n";
220
print MSTREAM "gvhdl: Compiling '$out_file_name'...\n";
221
print MSTREAM "gvhdl: ================================\n";
222
print MSTREAM "gvhdl: $cmd\n";
223
if (execute_cmd ($cmd, "c++: ", $MSTREAM)/256 != 0) {
224
print MSTREAM "gvhdl: Compilation failed!\n";
225
print PROGRESS_BAR "99";
229
$progress_value = int($progress_value + $steps);
230
print PROGRESS_BAR $progress_value;
234
##############################################################
235
# Comiling main cc file -> o
236
##############################################################
237
if ($create_simulator == 1) {
238
my $out_file_name = $main_file_name . ".cc";
239
my $cmd = "$cc $cpp_options $includes -c $out_file_name";
240
print MSTREAM "gvhdl:\n";
241
print MSTREAM "gvhdl: ================================\n";
242
print MSTREAM "gvhdl: Compiling simulator main file '$out_file_name'...\n";
243
print MSTREAM "gvhdl: ================================\n";
244
print MSTREAM "gvhdl: $cmd\n";
245
if (execute_cmd ($cmd, "c++: ", $MSTREAM)/256 != 0) {
246
print MSTREAM "gvhdl: Compilation failed!\n";
247
print PROGRESS_BAR "99";
251
$progress_value = int($progress_value + $steps);
252
print PROGRESS_BAR $progress_value;
255
##############################################################
257
##############################################################
259
$_ = $source_files[0];
261
my $target_name = $_;
263
my $cmd = "$libtool $libtool_options $cc $cpp_options $main_file_name.o $object_files $cpplibs -o $target_name";
264
print MSTREAM "gvhdl: Linking simulator '$target_name'...\n";
265
print MSTREAM "gvhdl: $cmd\n";
266
if (execute_cmd ($cmd, "linker: ", $MSTREAM)/256 != 0) {
267
print $MSTREAM "gvhdl: Linking failed!\n";
270
print MSTREAM "gvhdl: ================================\n";
271
print MSTREAM "gvhdl: Simulator '$target_name' created.\n";
272
print MSTREAM "gvhdl: ================================\n";
274
print PROGRESS_BAR "99";