1#   Copyright (C) 1993-2016 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, write to the Free Software
15# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-dejagnu@prep.ai.mit.edu
19
20# This file was written by Rob Savoye. (rob@cygnus.com)
21
22load_lib utils-lib.exp
23
24if ![info exists NM] then {
25    set NM [findfile $base_dir/nm-new $base_dir/nm-new [transform nm]]
26}
27if ![info exists NMFLAGS] then {
28    set NMFLAGS ""
29}
30if ![info exists SIZE] then {
31    set SIZE [findfile $base_dir/size]
32}
33if ![info exists SIZEFLAGS] then {
34    set SIZEFLAGS ""
35}
36if ![info exists OBJDUMP] then {
37    set OBJDUMP [findfile $base_dir/objdump]
38}
39if ![info exists OBJDUMPFLAGS] then {
40    set OBJDUMPFLAGS ""
41}
42if ![info exists OBJCOPY] then {
43    set OBJCOPY [findfile $base_dir/objcopy]
44}
45if ![info exists OBJCOPYFLAGS] then {
46    set OBJCOPYFLAGS ""
47}
48if ![info exists AR] then {
49    set AR [findfile $base_dir/ar]
50}
51if ![info exists STRIP] then {
52    set STRIP [findfile $base_dir/strip-new $base_dir/strip-new [transform strip]]
53}
54if ![info exists STRIPFLAGS] then {
55    set STRIPFLAGS ""
56}
57if ![info exists READELF] then {
58    set READELF [findfile $base_dir/readelf]
59}
60if ![info exists READELFFLAGS] then {
61    set READELFFLAGS ""
62}
63if ![info exists ELFEDIT] then {
64    set ELFEDIT [findfile $base_dir/elfedit]
65}
66if ![info exists ELFEDITFLAGS] then {
67    set ELFEDITFLAGS ""
68}
69if ![info exists WINDRES] then {
70    set WINDRES [findfile $base_dir/windres]
71}
72if ![info exists DLLTOOL] then {
73    set DLLTOOL [findfile $base_dir/dlltool]
74}
75
76if ![file isdirectory tmpdir] {catch "exec mkdir tmpdir" status}
77
78# Make a copy from tmpdir/gas/as and tmpdir/gas/ld to the assembler
79# and linker in the build tree, so that we can use a -B option to gcc
80# to force it to use the newly built assembler/linker.
81if {![file isdirectory tmpdir/gas]} {catch "exec mkdir tmpdir/gas" status}
82
83proc link_or_copy { src dst } {
84    if ![catch "exec ln -sf ../../../$src tmpdir/gas/$dst" status] then {return 0}
85    if ![catch "exec ln -f ../$src tmpdir/gas/$dst" status] then {return 0}
86    catch "exec cp -fpu ../$src tmpdir/gas/$dst" status
87}
88
89if {[file isfile gas/as-new[exe_ext]]} then {
90    link_or_copy gas/as-new[exe_ext] as[exe_ext]
91} else {
92    # For non-Windows hosts there may be an executable
93    # without a .exe suffix, so try copying that instead.
94    link_or_copy gas/as-new as[exe_ext]
95}
96# This may not be needed any more...
97if {[file isfile ld/ld-new[exe_ext]]} then {
98    link_or_copy ld/ld-new[exe_ext] ld[exe_ext]
99} else {
100    link_or_copy ld/ld-new ld[exe_ext]
101}
102if {[file isfile tmpdir/gas/as[exe_ext]]} then {
103    set gcc_gas_flag "-B[pwd]/tmpdir/gas/"
104    set dlltool_gas_flag "-S [pwd]/tmpdir/gas/as[exe_ext]"
105} else {
106    # Testing an installed toolchain.
107    set gcc_gas_flag ""
108    set dlltool_gas_flag ""
109}
110
111#
112# binutils_run
113#	run a program, returning the output
114#	sets binutils_run_failed if the program does not exist
115#
116proc binutils_run { prog progargs } {
117    default_binutils_run $prog $progargs
118}
119
120#
121# binutils_assemble
122#	assemble a file
123#
124proc binutils_assemble { source object } {
125    default_binutils_assemble_flags $source $object ""
126}
127
128#
129# binutils_assemble_flags
130#	assemble a file
131#
132proc binutils_assemble_flags { source object asflags } {
133    default_binutils_assemble_flags $source $object $asflags
134}
135