implement -l, but -L isn't supported yet and the full lib name must be given

This commit is contained in:
Bill Currie 2002-07-21 07:12:17 +00:00
parent acf9ce392c
commit c2a7564d55
6 changed files with 93 additions and 24 deletions

View file

@ -34,6 +34,7 @@
void linker_begin (void);
void linker_add_object_file (const char *filename);
void linker_add_lib (const char *libname);
struct qfo_s *linker_finish (void);
#endif//__linker_h

View file

@ -34,6 +34,7 @@
#include "QF/pr_comp.h"
#include "QF/pr_debug.h"
#include "QF/vfile.h"
#define QFO "QFO"
#define QFO_VERSION 0x00001004 // MMmmmRRR 0.001.004 (hex)
@ -139,7 +140,8 @@ struct pr_info_s;
qfo_t *qfo_from_progs (struct pr_info_s *pr);
int qfo_write (qfo_t *qfo, const char *filename);
qfo_t *qfo_read (const char *filename);
qfo_t *qfo_read (VFile *file);
qfo_t *qfo_open (const char *filename);
int qfo_to_progs (qfo_t *qfo, struct pr_info_s *pr);
qfo_t *qfo_new (void);

View file

@ -39,9 +39,17 @@ static const char rcsid[] =
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#include <stdlib.h>
#include <fcntl.h>
#include "QF/hash.h"
#include "QF/pakfile.h"
#include "def.h"
#include "emit.h"
@ -183,7 +191,8 @@ process_def (qfo_def_t *def)
def->flags = d->flags;
Hash_Add (defined_defs, def);
} else {
Hash_Add (extern_defs, def);
if (def->num_relocs)
Hash_Add (extern_defs, def);
}
} else {
if (def->flags & QFOD_GLOBAL) {
@ -533,17 +542,8 @@ linker_begin (void)
}
void
linker_add_object_file (const char *filename)
linker_add_qfo (qfo_t *qfo)
{
qfo_t *qfo;
qfo = qfo_read (filename);
if (!qfo)
return;
if (options.verbosity >= 2)
puts (filename);
code_base = code->size;
data_base = data->size;
far_data_base = far_data->size;
@ -561,10 +561,67 @@ linker_add_object_file (const char *filename)
add_funcs (qfo);
add_defs (qfo);
add_lines (qfo);
}
void
linker_add_object_file (const char *filename)
{
qfo_t *qfo;
qfo = qfo_open (filename);
if (!qfo)
return;
if (options.verbosity >= 2)
puts (filename);
linker_add_qfo (qfo);
qfo_delete (qfo);
}
void
linker_add_lib (const char *libname)
{
pack_t *pack = pack_open (libname);
int i, j;
int did_something;
if (!pack)
return;
do {
did_something = 0;
for (i = 0; i < pack->numfiles; i++) {
int fd;
VFile *f;
qfo_t *qfo;
fd = open (libname, O_RDONLY);
lseek (fd, pack->files[i].filepos, SEEK_SET);
f = Qdopen (fd, "rbz");
qfo = qfo_read (f);
Qclose (f);
close (fd);
for (j = 0; j < qfo->num_defs; j++) {
qfo_def_t *def = qfo->defs + j;
if ((def->flags & QFOD_GLOBAL)
&& !(def->flags & QFOD_EXTERNAL)
&& Hash_Find (extern_defs, qfo->strings + def->name)) {
if (options.verbosity >= 2)
printf ("adding %s\n", pack->files[i].name);
linker_add_qfo (qfo);
did_something = 1;
break;
}
}
qfo_delete (qfo);
}
} while (did_something);
pack_del (pack);
}
qfo_t *
linker_finish (void)
{

View file

@ -313,9 +313,8 @@ qfo_write (qfo_t *qfo, const char *filename)
}
qfo_t *
qfo_read (const char *filename)
qfo_read (VFile *file)
{
VFile *file;
qfo_header_t hdr;
qfo_t *qfo;
qfo_def_t *def;
@ -325,12 +324,6 @@ qfo_read (const char *filename)
pr_type_t *var;
pr_lineno_t *line;
file = Qopen (filename, "rbz");
if (!file) {
perror (filename);
return 0;
}
Qread (file, &hdr, sizeof (hdr));
if (strcmp (hdr.qfo, QFO)) {
@ -385,8 +378,6 @@ qfo_read (const char *filename)
Qread (file, qfo->lines, qfo->num_lines * sizeof (pr_lineno_t));
Qread (file, qfo->types, qfo->types_size);
Qclose (file);
for (st = qfo->code; st - qfo->code < qfo->code_size; st++) {
st->op = LittleLong (st->op);
st->a = LittleLong (st->a);
@ -439,6 +430,21 @@ qfo_read (const char *filename)
return qfo;
}
qfo_t *qfo_open (const char *filename)
{
qfo_t *qfo;
VFile *file;
file = Qopen (filename, "rbz");
if (!file) {
perror (filename);
return 0;
}
qfo = qfo_read (file);
Qclose (file);
return qfo;
}
defspace_t *
init_space (int size, pr_type_t *data)
{

View file

@ -546,7 +546,10 @@ separate_compile (void)
qfo_t *qfo;
linker_begin ();
for (file = source_files; *file; file++) {
linker_add_object_file (*file);
if (strncmp (*file, "-l", 2))
linker_add_object_file (*file);
else
linker_add_lib (*file + 2);
}
qfo = linker_finish ();
if (qfo) {

View file

@ -182,7 +182,7 @@ main (int argc, char **argv)
}
}
while (optind < argc) {
qfo = qfo_read (argv[optind++]);
qfo = qfo_open (argv[optind++]);
if (!qfo)
return 1;
dump_defs (qfo);