1# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
2#
3# Permission to use, copy, modify, and distribute this software
4# is freely granted, provided that this notice is preserved.
5#
6
7# flags.exp overrides the dejagnu versions of newlib_link_flags and
8# newlib_include_flags.
9load_lib flags.exp
10
11proc newlib_version { } {
12    global tool_version
13
14    verbose "In newlib version...\n"
15
16    return $tool_version
17}
18
19set newlib_initialized 0
20
21proc newlib_init { args } {
22    global gluefile wrap_flags
23    global newlib_initialized
24    global target_info
25    # These values are initialized in the local site.exp file.
26    global srcdir objdir tmpdir
27    global host_triplet target_triplet
28    global old_ld_library_path
29
30    verbose "In newlib_init...\n"
31
32    if { $newlib_initialized == 1 } { return; }
33
34    if {[target_info needs_status_wrapper] != "" && \
35	    [target_info needs_status_wrapper] != "0" && \
36	    ![info exists gluefile]} {
37	set gluefile ${tmpdir}/testglue.o;
38	set result [build_wrapper $gluefile];
39	if { $result != "" } {
40	    set gluefile [lindex $result 0];
41	    set wrap_flags [lindex $result 1];
42	} else {
43	    unset gluefile
44	}
45    }
46
47    if [string match $host_triplet $target_triplet] then {
48	if [string match "i686-pc-linux-gnu" $host_triplet] then {
49	    set old_ld_library_path [getenv LD_LIBRARY_PATH]
50	    setenv LD_LIBRARY_PATH "$objdir/.libs"
51	}
52    }
53}
54
55proc newlib_target_compile { source dest type options } {
56    global gluefile wrap_flags
57    global srcdir objdir
58    global host_triplet target_triplet
59
60    verbose "In newlib_target_compile...\n"
61
62    lappend options "libs=-I$srcdir/include"
63    verbose "srcdir is $srcdir"
64
65    if {[target_info needs_status_wrapper] != "" && \
66	    [target_info needs_status_wrapper] != "0" && \
67	    [info exists gluefile] } {
68	lappend options "libs=$gluefile"
69	lappend options "LDFLAGS=$wrap_flags"
70    }
71
72    if [string match $host_triplet $target_triplet] then {
73	if [string match "i686-pc-linux-gnu" $host_triplet] then {
74	    lappend options "libs=$objdir/crt0.o -lc -lgcc"
75	    lappend options "LDFLAGS=-nostdlib -L$objdir/.libs [newlib_include_flags]"
76	}
77    }
78
79    return [target_compile $source $dest $type $options]
80}
81
82proc newlib_finish { } {
83    global old_ld_library_path
84    global host_triplet target_triplet
85
86    verbose "In newlib_finish...\n"
87
88    if [string match $host_triplet $target_triplet] then {
89	if [string match "i686-pc-linux-gnu" $host_triplet] then {
90	    setenv LD_LIBRARY_PATH "$old_ld_library_path"
91	}
92    }
93}
94
95proc newlib_exit { } {
96    global gluefile;
97
98    verbose "In newlib_exit...\n"
99
100    if [info exists gluefile] {
101	file_on_build delete $gluefile;
102	unset gluefile;
103    }
104}
105