2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 look after all the file stuff
39 char *ldfile_input_filename
;
40 CONST
char * ldfile_output_machine_name
;
41 unsigned long ldfile_output_machine
;
42 enum bfd_architecture ldfile_output_architecture
;
47 extern boolean option_v
;
54 typedef struct search_dirs_struct
57 struct search_dirs_struct
*next
;
60 static search_dirs_type
*search_head
;
61 static search_dirs_type
**search_tail_ptr
= &search_head
;
63 typedef struct search_arch_struct
66 struct search_arch_struct
*next
;
69 static search_arch_type
*search_arch_head
;
70 static search_arch_type
**search_arch_tail_ptr
= &search_arch_head
;
75 ldfile_add_library_path(name
)
78 search_dirs_type
*new =
79 (search_dirs_type
*)ldmalloc(sizeof(search_dirs_type
));
81 new->next
= (search_dirs_type
*)NULL
;
82 *search_tail_ptr
= new;
83 search_tail_ptr
= &new->next
;
88 cached_bfd_openr(attempt
,entry
)
90 lang_input_statement_type
*entry
;
92 entry
->the_bfd
= bfd_openr(attempt
, entry
->target
);
93 if (option_v
== true && entry
->the_bfd
== (bfd
*)NULL
) {
94 info("attempt to open %s failed\n", attempt
);
96 return entry
->the_bfd
;
100 open_a(arch
, entry
, lib
, suffix
)
102 lang_input_statement_type
*entry
;
107 search_dirs_type
*search
;
108 for (search
= search_head
;
109 search
!= (search_dirs_type
*)NULL
;
110 search
= search
->next
)
114 if (entry
->is_archive
== true) {
119 entry
->filename
, arch
, suffix
);
122 if (entry
->filename
[0] == '/' || entry
->filename
[0] == '.') {
123 strcpy(buffer
, entry
->filename
);
125 sprintf(buffer
,"%s/%s",search
->name
, entry
->filename
);
128 string
= buystring(buffer
);
129 desc
= cached_bfd_openr (string
, entry
);
132 entry
->filename
= string
;
133 entry
->search_dirs_flag
= false;
134 entry
->the_bfd
= desc
;
142 /* Open the input file specified by 'entry', and return a descriptor.
143 The open file is remembered; if the same file is opened twice in a row,
144 a new open is not actually done. */
147 ldfile_open_file (entry
)
148 lang_input_statement_type
*entry
;
151 if (entry
->superfile
)
152 ldfile_open_file (entry
->superfile
);
154 if (entry
->search_dirs_flag
)
156 search_arch_type
*arch
;
157 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
159 for (arch
= search_arch_head
;
160 arch
!= (search_arch_type
*)NULL
;
162 if (open_a(arch
->name
,entry
,"","") != (bfd
*)NULL
) {
165 if (open_a(arch
->name
,entry
,"lib",".a") != (bfd
*)NULL
) {
174 entry
->the_bfd
= cached_bfd_openr (entry
->filename
, entry
);
177 if (!entry
->the_bfd
) info("%F%P: %E %I\n", entry
);
187 try_open(name
, exten
)
193 result
= fopen(name
, "r");
194 if (option_v
== true) {
195 if (result
== (FILE *)NULL
) {
202 sprintf(buff
, "%s%s", name
, exten
);
203 result
= fopen(buff
, "r");
205 if (option_v
== true) {
206 if (result
== (FILE *)NULL
) {
214 find_a_name(name
, extend
)
218 search_dirs_type
*search
;
221 /* First try raw name */
222 result
= try_open(name
,"");
223 if (result
== (FILE *)NULL
) {
224 /* Try now prefixes */
225 for (search
= search_head
;
226 search
!= (search_dirs_type
*)NULL
;
227 search
= search
->next
) {
228 sprintf(buffer
,"%s/%s", search
->name
, name
);
229 result
= try_open(buffer
, extend
);
236 void ldfile_open_command_file(name
)
239 extern FILE *ldlex_input_stack
;
240 ldlex_input_stack
= find_a_name(name
, ".ld");
242 if (ldlex_input_stack
== (FILE *)NULL
) {
243 info("%P%F cannot open load script file %s\n",name
);
245 ldfile_input_filename
= name
;
253 DEFUN(ldfile_add_arch
,(in_name
),
254 CONST
char *CONST in_name
)
256 char *name
= buystring(in_name
);
257 search_arch_type
*new =
258 (search_arch_type
*)ldmalloc(sizeof(search_arch_type
));
260 ldfile_output_machine_name
= in_name
;
263 new->next
= (search_arch_type
*)NULL
;
265 if (isupper(*name
)) *name
= tolower(*name
);
268 *search_arch_tail_ptr
= new;
269 search_arch_tail_ptr
= &new->next
;