aboutsummaryrefslogtreecommitdiff
path: root/contrib/bluegnu2.0.3/lib/libgloss.exp
blob: 7e54e8dabfa49aa787e79b5ebc107e2c904a28af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Copyright (C) 92, 93, 94, 95, 1996 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 

# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu

# This file was written by Rob Savoye. (rob@welcomehome.org)

#
# Find the linker script for the current target. Returns a string
# suitable to pass to $CC or $CXX to use a liblgoss based linker script,
# or NULL if there is no support.
#
proc libgloss_script { } {
    global srcdir
    global target_cpu
    global LDFLAGS
    global CFLAGS
    global CXXFLAGS
    global target_info

    # sanity check
    if ![info exists LDFLAGS] {
	set LDFLAGS ""
    }
    if ![info exists CFLAGS] {
	set CFLAGS ""
    }

     if ![info exists CXXFLAGS] {
	set CXXFLAGS ""
    }

    # find the linker script. first we look at the config
    # data and hope to find it all ready for us to use. if
    # that fails, then look in the LDFLAGS and CFLAGS variables that
    # get set in the global site.exp file.
    if [info exists target_info(target,name)] {
	set script $target_info(target,name).ld
    } else {
	if [regexp -- "-T.*\.ld" ${LDFLAGS} script] {
	    string trimleft ${script} "-T"
	}
	if [regexp -- "-T.*\.ld" ${CFLAGS} script] {
	    string trimleft ${script} "-T"
	}
	if [regexp -- "-T.*\.ld" ${CXXFLAGS} script] {
	    string trimleft ${script} "-T"
	}
    }

    if ![info exists script] {
	warning "Couldn't find the linker script name for target"
	return ""
    }
    
    # if we're on a remote host, we can't search for the file, so use the
    # linker script in the path.
    if [is3way] {
	return "-T${script}"
    }
    
    # search for the general directories
    foreach i ".. ../.. ../../.. ../../../.." {
	verbose "Looking for a ${srcdir}/${i}/libgloss/${target_cpu}/${script}" 2
	if [file exists ${srcdir}/$i/libgloss/${target_cpu}/${script} ] {
	    verbose "Found ${srcdir}/${i}/libgloss/${target_cpu}/${script}." 3
	    return "-T${srcdir}/${i}/libgloss/${target_cpu}/${script}"
	}
    }

    # we didn't find the script, so we have to hope it's installed
    return "-T${script}"
}

#
# Find all the pieces of libgloss for testing the GNU development tools
# needed to use $CC or $CXX. It returns a string suitable to pass to 
# $CC or $CXX to get a fully linked binary for the target.
#
proc libgloss_flags { } {
    global target_alias
    global target_cpu
    global srcdir
    global base_dir

    # libgloss doesn't work native
    if [isnative] {
	return ""
    }

    # if we're on a remote host, we can't search for the file, so we can only
    # use an installed compiler, so we don't add any paths here.
    if [is3way] {
	return "[libgloss_script]"
    }
    
    # search for the general directories
    foreach i ".. ../.. ../../.. ../../../.." {
	if [file exists ${base_dir}/${i}/${target_alias}/libgloss/${target_cpu} ] {
	    verbose "Found ${base_dir}/${i}/${target_alias}/libgloss/${target_cpu}." 3
	    return  "-L${base_dir}/${i}/${target_alias}/libgloss/${target_cpu} [libgloss_script]"
	}
    }
    
    # we didn't find any support at all
    return "[libgloss_script]"
}

#
# Find the C libraries
#
proc newlib_flags { } {
    global base_dir
    global srcdir
    global target_alias

    # if we're on a remote host, we can't search for the file, so use the
    # newlib already installed.
    if [is3way] {
	return ""
    }

    # search for the general directories
    foreach i ".. ../.. ../../.. ../../../.." {
	verbose "Looking for a ${base_dir}/${i}/${target_alias}/newlib/targ-include" 2
	if [file exists ${base_dir}/${i}/${target_alias}/newlib/targ-include ] {
	    verbose "Found ${base_dir}/${i}/${target_alias}/newlib/targ-include." 3
	    set incls1 "-I${base_dir}/${i}/${target_alias}/newlib/targ-include"
	}
	verbose "Looking for a ${srcdir}/${i}/newlib/libc/include" 2
	if [file exists ${srcdir}/${i}/newlib/libc/include ] {
	    verbose "Found ${srcdir}/${i}/newlib/libc/include." 3
	    set incls2 "-I${srcdir}/${i}/newlib/libc/include"
	}
    }

    # search for the general directories
    foreach i ".. ../.. ../../.. ../../../.." {
	verbose "Looking for a ${base_dir}/${i}/newlib" 2
	if [file exists ${base_dir}/${i}/newlib ] {
	    verbose "Found ${base_dir}/${i}/newlib." 3
	    return "-B${base_dir}/${i}/newlib/ ${incls1} ${incls2}"
	}
    }
    return ""
}

#
# Find all the pieces of libgloss for testing the GNU development tools
# needed to use $LD. This gets fun cause we have to guess the name of the
# BSP for this target. If returns a string suitable to pass to LD to get
# a fully linked binary for the target. It also sets two global variables,
# CRT0 is the path to the startup file, and
# BSP is the path to the support library.
#
proc libgloss_ld {} {
#proc gloss_ld {} {
    global target_cpu
    global srcdir
    global base_dir
    global CRT0
    global BSP

    # libgloss doesn't work native
    if [isnative] {
	return ""
    }

#    set ldflags ""
    # search for the general directories
    foreach i ".. ../.. ../../.. ../../../.." {
	if ![info exists gloss_srcdir] {
	    if [file exists ${srcdir}/$i/libgloss/${target_cpu} ] {
		verbose "Found ${srcdir}/$i/libgloss/${target_cpu}." 3
		set gloss_srcdir "$i/libgloss/${target_cpu}"
	    }
	}
	if ![info exists gloss_objdir] {
	    if [file exists ${base_dir}/$i/libgloss/${target_cpu} ] {
		verbose "Found ${base_dir}/$i/libgloss/${target_cpu}." 3
		set gloss_objdir "$i/libgloss/${target_cpu}"
		append ldflags " -L${gloss_objdir} "
	    }
	}
    }

    # find the crt0
    if [file exists ${gloss_objdir}/crt0.o] {
	verbose "Found ${base_dir}/$i/libgloss/${target_cpu}." 3
	set CRT0 "$i/libgloss/${target_cpu}"
	append ldflags " ${gloss_objdir}/crt0.o "
    } else {
	perror "No crt0.o built for this target"
    }
    
    # find the BSP (currently an object, it may become an archive soon)
    foreach i "[list_targets]" {
	if [info exists target_info($i,name}] {
	    if [file exists ${gloss_objdir}/${target_info}($i,name).o ] {
		set BSP "${target_info}($i,name).o"
		append ldflags " -lc -l ${target_info}($i,name).o -lc "
	    }
	}
    }
    if [expr ![info exists gloss_srcdir] || ![info exists gloss_srcdir]] {
	warning "No libgloss support in build tree"
	return ""
    } else {
	return "${ldflags}"
    }
}