OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [testsuite/] [lib/] [ada.exp] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
# Copyright 2004, 2007, 2008 Free Software Foundation, Inc.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see .
15
 
16
load_lib libgloss.exp
17
 
18
# FIXME:brobecker/2004-03-31:
19
# The following function should eventually be part of dejagnu. Even after
20
# this function becomes available in dejagnu, we will keep for a while
21
# a copy of this function here in order to avoid increasing the dejagnu
22
# version requirement.
23
 
24
proc gdb_find_gnatmake {} {
25
    global tool_root_dir
26
 
27
    set root "$tool_root_dir/gcc"
28
    set GM ""
29
 
30
    if ![is_remote host] {
31
        set file [lookfor_file $root gnatmake]
32
        if { $file != "" } {
33
            set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
34
        }
35
    }
36
 
37
    if {$GM == ""} {
38
        set GM [transform gnatmake]
39
    }
40
 
41
    return $GM
42
}
43
 
44
# FIXME:brobecker/2004-03-31:
45
# The following function is a copy of the function of the same name provided
46
# by dejagnu, except that it has been modified to add support for building
47
# Ada programs.  This copy is temporarily placed here until the changes
48
# are merged into the dejagnu official release. Once the changes are merged,
49
# we will likely keep this local copy for a while to avoid increasing the
50
# dejagnu version requirement.
51
 
52
proc gdb_default_target_compile {source destfile type options} {
53
    global target_triplet
54
    global tool_root_dir
55
    global CFLAGS_FOR_TARGET
56
    global compiler_flags
57
 
58
    if { $destfile == "" && $type != "preprocess" && $type != "none" } {
59
        error "Must supply an output filename for the compile to default_target_compile"
60
    }
61
 
62
    set add_flags ""
63
    set libs ""
64
    set compiler_type "c"
65
    set compiler ""
66
    set ldflags ""
67
    set dest [target_info name]
68
 
69
    if [info exists CFLAGS_FOR_TARGET] {
70
        append add_flags " $CFLAGS_FOR_TARGET"
71
    }
72
 
73
    if [info exists target_info(host,name)] {
74
        set host [host_info name];
75
    } else {
76
        set host "unix";
77
    }
78
 
79
    foreach i $options {
80
        if { $i == "ada" } {
81
            set compiler_type "ada"
82
            if [board_info $dest exists adaflags] {
83
                append add_flags " [target_info adaflags]"
84
            }
85
            # append add_flags " [gnatmake_include_flags]";
86
            if [board_info $dest exists gnatmake] {
87
                set compiler [target_info gnatmake];
88
            } else {
89
                set compiler [find_gnatmake];
90
            }
91
        }
92
 
93
        if { $i == "c++" } {
94
            set compiler_type "c++"
95
            if [board_info $dest exists cxxflags] {
96
                append add_flags " [target_info cxxflags]"
97
            }
98
            append add_flags " [g++_include_flags]";
99
            if [board_info $dest exists c++compiler] {
100
                set compiler [target_info c++compiler];
101
            } else {
102
                set compiler [find_g++];
103
            }
104
        }
105
 
106
        if { $i == "f77" } {
107
            set compiler_type "f77"
108
            if [board_info $dest exists f77flags] {
109
                append add_flags " [target_info f77flags]"
110
            }
111
#           append add_flags " [f77_include_flags]"
112
            if [board_info $dest exists f77compiler] {
113
                set compiler [target_info f77compiler]
114
            } else {
115
                set compiler [find_g77]
116
            }
117
        }
118
 
119
        if [regexp "^dest=" $i] {
120
            regsub "^dest=" $i "" tmp
121
            if [board_info $tmp exists name] {
122
                set dest [board_info $tmp name];
123
            } else {
124
                set dest $tmp;
125
            }
126
        }
127
        if [regexp "^compiler=" $i] {
128
            regsub "^compiler=" $i "" tmp
129
            set compiler $tmp
130
        }
131
        if [regexp "^additional_flags=" $i] {
132
            regsub "^additional_flags=" $i "" tmp
133
            append add_flags " $tmp"
134
        }
135
        if [regexp "^ldflags=" $i] {
136
            regsub "^ldflags=" $i "" tmp
137
            append ldflags " $tmp"
138
        }
139
        if [regexp "^libs=" $i] {
140
            regsub "^libs=" $i "" tmp
141
            append libs " $tmp"
142
        }
143
        if [regexp "^incdir=" $i] {
144
            regsub "^incdir=" $i "-I" tmp
145
            append add_flags " $tmp"
146
        }
147
        if [regexp "^libdir=" $i] {
148
            regsub "^libdir=" $i "-L" tmp
149
            append add_flags " $tmp"
150
        }
151
        if [regexp "^ldscript=" $i] {
152
            regsub "^ldscript=" $i "" ldscript
153
        }
154
        if [regexp "^redirect=" $i] {
155
            regsub "^redirect=" $i "" redirect
156
        }
157
        if [regexp "^optimize=" $i] {
158
            regsub "^optimize=" $i "" optimize
159
        }
160
        if [regexp "^timeout=" $i] {
161
            regsub "^timeout=" $i "" timeout
162
        }
163
    }
164
 
165
    if [board_info $host exists cflags_for_target] {
166
        append add_flags " [board_info $host cflags_for_target]";
167
    }
168
 
169
    global CC_FOR_TARGET
170
    global CXX_FOR_TARGET
171
    global F77_FOR_TARGET
172
    global GNATMAKE_FOR_TARGET
173
 
174
    if [info exists CC_FOR_TARGET] {
175
        if { $compiler == "" } {
176
            set compiler $CC_FOR_TARGET
177
        }
178
    }
179
 
180
    if [info exists CXX_FOR_TARGET] {
181
        if { $compiler_type == "c++" } {
182
            set compiler $CXX_FOR_TARGET
183
        }
184
    }
185
 
186
    if [info exists F77_FOR_TARGET] {
187
        if { $compiler_type == "f77" } {
188
            set compiler $F77_FOR_TARGET
189
        }
190
    }
191
 
192
    if [info exists GNATMAKE_FOR_TARGET] {
193
        if { $compiler_type == "ada" } {
194
            set compiler $GNATMAKE_FOR_TARGET
195
        }
196
    }
197
 
198
    if { $compiler == "" } {
199
        set compiler [board_info $dest compiler];
200
        if { $compiler == "" } {
201
            return "default_target_compile: No compiler to compile with";
202
        }
203
    }
204
 
205
    if ![is_remote host] {
206
        if { [which $compiler] == 0 } {
207
            return "default_target_compile: Can't find $compiler."
208
        }
209
    }
210
 
211
    if {$type == "object"} {
212
        append add_flags " -c"
213
    }
214
 
215
    if { $type == "preprocess" } {
216
        append add_flags " -E"
217
    }
218
 
219
    if { $type == "assembly" } {
220
        append add_flags " -S"
221
    }
222
 
223
    if [board_info $dest exists cflags] {
224
        append add_flags " [board_info $dest cflags]"
225
    }
226
 
227
    if { $type == "executable" } {
228
        # This must be added here.
229
        # if [board_info $dest exists ldscript] {
230
        #     append add_flags " [board_info $dest ldscript]"
231
        # }
232
 
233
        if [board_info $dest exists ldflags] {
234
            append add_flags " [board_info $dest ldflags]"
235
        }
236
        if { $compiler_type == "c++" } {
237
            append add_flags " [g++_link_flags]";
238
        }
239
        if [isnative] {
240
            # This is a lose.
241
            catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
242
            if { ${tmp} != "" } {
243
                if [regexp ".*solaris2.*" $target_triplet] {
244
                    # Solaris 2
245
                    append add_flags " -R$tool_root_dir/libstdc++"
246
                } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
247
                    # OSF/1 or Irix5
248
                    append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
249
                } elseif [regexp ".*hppa.*" $target_triplet] {
250
                    # HP/UX
251
                    append add_flags " -Wl,-a,shared_archive"
252
                }
253
            }
254
        }
255
    }
256
 
257
    if ![info exists ldscript] {
258
        set ldscript [board_info $dest ldscript]
259
    }
260
 
261
    foreach i $options {
262
        if { $i == "debug" } {
263
            if [board_info $dest exists debug_flags] {
264
                append add_flags " [board_info $dest debug_flags]";
265
            } else {
266
                append add_flags " -g"
267
            }
268
        }
269
    }
270
 
271
    if [info exists optimize] {
272
        append add_flags " $optimize";
273
    }
274
 
275
    if { $type == "executable" } {
276
        append add_flags " $ldflags"
277
        foreach x $libs {
278
            if [file exists $x] {
279
                append source " $x"
280
            } else {
281
                append add_flags " $x";
282
            }
283
        }
284
 
285
        if [board_info $dest exists libs] {
286
            append add_flags " [board_info $dest libs]"
287
        }
288
 
289
        # This probably isn't such a good idea, but it avoids nasty
290
        # hackiness in the testsuites.
291
        # The math library must be linked in before the C library.  The C
292
        # library is linked in by the linker script, so this must be before
293
        # the linker script.
294
        if [board_info $dest exists mathlib] {
295
            append add_flags " [board_info $dest mathlib]"
296
        } else {
297
            append add_flags " -lm"
298
        }
299
 
300
        # This must be added here.
301
        append add_flags " $ldscript";
302
 
303
        if [board_info $dest exists remote_link] {
304
            # Relink option.
305
            append add_flags " -Wl,-r"
306
        }
307
        if [board_info $dest exists output_format] {
308
            append add_flags " -Wl,-oformat,[board_info $dest output_format]";
309
        }
310
    }
311
 
312
    if [board_info $dest exists multilib_flags] {
313
        append add_flags " [board_info $dest multilib_flags]";
314
    }
315
 
316
    verbose "doing compile"
317
 
318
    set sources ""
319
    if [is_remote host] {
320
        foreach x $source {
321
            set file [remote_download host $x];
322
            if { $file == "" } {
323
                warning "Unable to download $x to host."
324
                return "Unable to download $x to host."
325
            } else {
326
                append sources " $file";
327
            }
328
        }
329
    } else {
330
        set sources $source
331
    }
332
 
333
    if [is_remote host] {
334
        append add_flags " -o a.out"
335
        remote_file host delete a.out;
336
    } else {
337
        if { $destfile != "" } {
338
            append add_flags " -o $destfile";
339
        }
340
    }
341
 
342
    # This is obscure: we put SOURCES at the end when building an
343
    # object, because otherwise, in some situations, libtool will
344
    # become confused about the name of the actual source file.
345
    if {$type == "object"} {
346
        set opts "$add_flags $sources"
347
    } else {
348
        set opts "$sources $add_flags"
349
    }
350
 
351
    if [is_remote host] {
352
        if [host_info exists use_at] {
353
            set fid [open "atfile" "w"];
354
            puts $fid "$opts";
355
            close $fid;
356
            set opts "@[remote_download host atfile]"
357
            remote_file build delete atfile
358
        }
359
    }
360
 
361
    verbose "Invoking the compiler as $compiler $opts" 2
362
 
363
    if [info exists redirect] {
364
        verbose "Redirecting output to $redirect" 2
365
        set status [remote_exec host "$compiler $opts" "" "" $redirect];
366
    } else {
367
        if [info exists timeout] {
368
            verbose "Setting timeout to $timeout" 2
369
            set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
370
        } else {
371
            set status [remote_exec host "$compiler $opts"];
372
        }
373
    }
374
 
375
    set compiler_flags $opts
376
    if [is_remote host] {
377
        remote_upload host a.out $destfile;
378
        remote_file host delete a.out;
379
    }
380
    set comp_output [prune_warnings [lindex $status 1]];
381
    regsub "^\[\r\n\]+" $comp_output "" comp_output;
382
    if { [lindex $status 0] != 0 } {
383
        verbose -log "compiler exited with status [lindex $status 0]";
384
    }
385
    if { [lindex $status 1] != "" } {
386
        verbose -log "output is:\n[lindex $status 1]" 2;
387
    }
388
    if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
389
        set comp_output "exit status is [lindex $status 0]";
390
    }
391
    return ${comp_output};
392
}
393
 
394
# See if the version of dejaGNU being used to run the testsuite is
395
# recent enough to contain support for building Ada programs or not.
396
# If not, then use the functions above in place of the ones provided
397
# by dejaGNU. This is only temporary (brobecker/2004-03-31).
398
 
399
if {[info procs find_gnatmake] == ""} {
400
  proc find_gnatmake { } { return [gdb_find_gnatmake] }
401
  proc default_target_compile { source destfile type options } {
402
    return [gdb_default_target_compile $source $destfile $type $options]
403
  }
404
}
405
 
406
# Compile some Ada code.
407
 
408
proc gdb_compile_ada {source dest type options} {
409
 
410
    set srcdir [file dirname $source]
411
    set gprdir [file dirname $srcdir]
412
    set objdir [file dirname $dest]
413
 
414
    append options " ada"
415
    append options " additional_flags=-P$gprdir/gnat_ada"
416
    append options " additional_flags=-XSRC=[file tail $srcdir]"
417
    append options " additional_flags=-XOBJ=$objdir"
418
 
419
    set result [target_compile [file tail $source] $dest $type $options]
420
 
421
    # The Ada build always produces some output, even when the build
422
    # succeeds. Thus, we can not use the output the same way we do in
423
    # gdb_compile to determine whether the build has succeeded or not.
424
    # We therefore simply check whether the dest file has been created
425
    # or not. Unless not present, the build has succeeded.
426
    if ![file exists $dest] {
427
        unsupported "Ada compilation failed: $result"
428
        return "Ada compilation failed."
429
    }
430
}
431
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.