Added close gadget and increased hight of default con window.
[AROS.git] / tools / collect-aros / backend-generic.c
blob011f32cf5636537f8ff763ee9d4313daaca166dc
1 #include "misc.h"
2 #include "backend.h"
3 #include <sys/param.h>
4 #include <string.h>
5 #include <errno.h>
6 #include <stdlib.h>
8 #include "env.h"
10 static FILE *my_popen(const char *command, const char *file)
12 static char command_buf[MAXPATHLEN];
14 size_t command_len = strlen(command);
15 size_t file_len = strlen(file);
17 FILE *pipe;
19 if (file_len + command_len >= sizeof(command_buf))
20 fatal("collect_sets()", strerror(ENAMETOOLONG));
22 memcpy(command_buf, command, command_len);
23 memcpy(command_buf + command_len, file, file_len + 1);
25 set_compiler_path();
27 pipe = popen(command_buf, "r");
28 if (pipe == NULL)
29 fatal(command_buf, strerror(errno));
31 return pipe;
36 This routine is slow, but does the work and it's the simplest to write down.
37 All this will get integrated into the linker anyway, so there's no point
38 in doing optimizations
40 void collect_sets(const char *file, setnode **setlist_ptr)
42 char secname[201];
44 FILE *pipe = my_popen(OBJDUMP_NAME " -h ", file);
46 /* This fscanf() simply splits the whole stream into separate words */
47 while (fscanf(pipe, " %200s ", secname) > 0)
49 parse_format(secname);
50 parse_secname(secname, setlist_ptr);
53 pclose(pipe);
57 This routine is slow, but does the work and it's the simplest to write down.
58 All this will get integrated into the linker anyway, so there's no point
59 in doing optimizations
61 void collect_libs(const char *file, setnode **liblist_ptr)
63 unsigned long offset;
64 char type;
65 char secname[201];
66 char buff[256];
68 FILE *pipe = my_popen("nm ", file);
70 /* This fscanf() simply splits the whole stream into separate words */
71 while (fgets(buff, sizeof(buff), pipe)) {
72 struct setnode *node;
73 int pri;
75 offset = 0;
77 if (sscanf(buff, "%lx %c %200s ", &offset, &type, secname) != 3 &&
78 sscanf(buff, " %c %200s", &type, secname) != 2)
79 continue;
81 if (strncmp(secname, "__aros_libreq_", 14) != 0)
82 continue;
84 if (type == 'A') {
85 char *cp, *tmp;
87 cp = strchr(secname + 14, '.');
88 if (cp == NULL)
89 continue;
91 pri = strtoul(cp+1, &tmp, 0);
92 if ((cp+1) == tmp)
93 continue;
95 *(cp++) = 0;
96 } else if (type == 'w') {
97 pri = 0;
98 } else {
99 continue;
102 node = calloc(sizeof(*node),1);
103 node->secname = strdup(secname);
104 node->off_setname = 14;
105 node->pri = pri;
106 node->next = *liblist_ptr;
107 *liblist_ptr = node;
110 pclose(pipe);
114 int check_and_print_undefined_symbols(const char *file)
116 int there_are_undefined_syms = 0;
117 char buf[200];
118 size_t cnt;
120 FILE *pipe = my_popen(NM_NAME " -ulC ", file);
122 while ((cnt = fread(buf, 1, sizeof(buf), pipe)) != 0)
124 if (!there_are_undefined_syms)
126 there_are_undefined_syms = 1;
127 fprintf(stderr, "There are undefined symbols in '%s':\n", file);
130 fwrite(buf, cnt, 1, stderr);
133 pclose(pipe);
135 return there_are_undefined_syms;