configure.ac:

define default include and lib paths for qfcc
ruamoko:
	{cl_menu,game}/Makefile.am:
		conform to the new qfcc library linking rules
	lib/Makefile.am:
		install the libs to ${prefix}/lib/ruamoko
qfcc:
	linker.[ch]:
		support path searching for -llib and make linker_add_lib search for
		libfoo.a for -lfoo in the paths, or just a single dir search for the
		libname otherwise.
	options.c:
		support -L libpath and setup the default include and lib paths
		also change most strdup calls to save_string
	qfcc.c:
		check for foo.a as well as -lfoo when deciding whether the file is
		an object file or lib file.
This commit is contained in:
Bill Currie 2002-11-01 18:05:12 +00:00
parent ca95033c4f
commit 7f69f593d3
8 changed files with 79 additions and 14 deletions

View file

@ -1937,6 +1937,8 @@ QF_DEPS(QFDEFS,
AC_DEFINE_UNQUOTED(PATH_SEPARATOR, '/', [Define this to your operating system's path separator character]) AC_DEFINE_UNQUOTED(PATH_SEPARATOR, '/', [Define this to your operating system's path separator character])
AC_DEFINE_UNQUOTED(CPP_NAME, "$CPP_NAME", [Define this to the command line for the C preprocessor]) AC_DEFINE_UNQUOTED(CPP_NAME, "$CPP_NAME", [Define this to the command line for the C preprocessor])
AC_DEFINE_UNQUOTED(QFCC_INCLUDE_PATH, "$prefix/include/QF/ruamoko", [Define this to where qfcc should look for header files])
AC_DEFINE_UNQUOTED(QFCC_LIB_PATH, "$prefix/lib/ruamoko", [Define this to where qfcc should look for lib files])
AM_CONDITIONAL(BUILD_GL, test "$BUILD_GL" = "yes") AM_CONDITIONAL(BUILD_GL, test "$BUILD_GL" = "yes")
AM_CONDITIONAL(BUILD_SW, test "$BUILD_SW" = "yes") AM_CONDITIONAL(BUILD_SW, test "$BUILD_SW" = "yes")

View file

@ -42,7 +42,7 @@ menu_src= \
menu_obj=$(addsuffix .qfo,$(basename $(menu_src))) menu_obj=$(addsuffix .qfo,$(basename $(menu_src)))
menu.dat$(GZ): $(menu_obj) $(QFCC_DEP) ../lib/libgui.a ../lib/libcsqc.a ../lib/libr.a menu.dat$(GZ): $(menu_obj) $(QFCC_DEP) ../lib/libgui.a ../lib/libcsqc.a ../lib/libr.a
$(QFCC) $(QCFLAGS) -p $(STRIP) -o menu.dat $(menu_obj) -l../lib/libgui.a -l../lib/libcsqc.a -l../lib/libr.a $(QFCC) $(QCFLAGS) -p $(STRIP) -o menu.dat $(menu_obj) ../lib/libgui.a ../lib/libcsqc.a ../lib/libr.a
$(GZIP) $(GZIP)
EXTRA_DIST= $(menu_src) \ EXTRA_DIST= $(menu_src) \

View file

@ -30,7 +30,7 @@ game_src= Axe.r GameEntity.r World.r tempent.r
game_obj=$(addsuffix .qfo,$(basename $(game_src))) game_obj=$(addsuffix .qfo,$(basename $(game_src)))
game.dat: $(game_obj) ../lib/libr.a game.dat: $(game_obj) ../lib/libr.a
$(QFCC) $(QCFLAGS) -p $(STRIP) -o game.dat $(game_obj) -l../lib/libr.a $(QFCC) $(QCFLAGS) -p $(STRIP) -o game.dat $(game_obj) ../lib/libr.a
EXTRA_DIST= $(game_src) Axe.h GameEntity.h tempent.h Weapon.h World.h EXTRA_DIST= $(game_src) Axe.h GameEntity.h tempent.h Weapon.h World.h
CLEANFILES= *.dat *.sym *.gz *.qfo CLEANFILES= *.dat *.sym *.gz *.qfo

View file

@ -1,5 +1,7 @@
AUTOMAKE_OPTIONS= foreign AUTOMAKE_OPTIONS= foreign
libdir=$(prefix)/lib/ruamoko
QFCC=$(top_builddir)/tools/qfcc/source/qfcc$(EXEEXT) QFCC=$(top_builddir)/tools/qfcc/source/qfcc$(EXEEXT)
QCFLAGS=-qq -g -Werror QCFLAGS=-qq -g -Werror
QCPPFLAGS=$(INCLUDES) QCPPFLAGS=$(INCLUDES)
@ -15,7 +17,7 @@ else
libs= libs=
endif endif
noinst_LIBRARIES= $(libs) lib_LIBRARIES= $(libs)
EXTRA_LIBRARIES= $(ruamoko_libs) EXTRA_LIBRARIES= $(ruamoko_libs)
%.qfo: %.r %.qfo: %.r

View file

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

View file

@ -53,6 +53,7 @@ static const char rcsid[] =
#include "QF/dstring.h" #include "QF/dstring.h"
#include "QF/hash.h" #include "QF/hash.h"
#include "QF/pakfile.h" #include "QF/pakfile.h"
#include "QF/va.h"
#include "def.h" #include "def.h"
#include "emit.h" #include "emit.h"
@ -77,6 +78,11 @@ Xgroup(def) // defgroup_t
Xgroup(reloc) // relocgroup_t Xgroup(reloc) // relocgroup_t
Xgroup(func) // funcgroup_t Xgroup(func) // funcgroup_t
typedef struct path_s {
struct path_s *next;
const char *path;
} path_t;
static hashtab_t *extern_defs; static hashtab_t *extern_defs;
static hashtab_t *defined_defs; static hashtab_t *defined_defs;
static hashtab_t *field_defs; static hashtab_t *field_defs;
@ -103,6 +109,9 @@ static int reloc_base;
static int func_base; static int func_base;
static int line_base; static int line_base;
static path_t *path_head;
static path_t **path_tail = &path_head;
#define DATA(x) (data->data + (x)) #define DATA(x) (data->data + (x))
#define STRING(x) (strings->strings + (x)) #define STRING(x) (strings->strings + (x))
#define TYPE_STRING(x) (type_strings->strings + (x)) #define TYPE_STRING(x) (type_strings->strings + (x))
@ -640,22 +649,47 @@ linker_add_object_file (const char *filename)
int int
linker_add_lib (const char *libname) linker_add_lib (const char *libname)
{ {
pack_t *pack = pack_open (libname); pack_t *pack;
path_t start = {path_head, "."};
path_t *path = &start;
const char *path_name;
int i, j; int i, j;
int did_something; int did_something;
if (strncmp (libname, "-l", 2) == 0) {
while (path) {
path_name = va ("%s/lib%s.a", path->path, libname + 2);
pack = pack_open (path_name);
if (pack)
break;
if (errno != ENOENT) {
if (errno)
perror (libname);
return 1;
}
path = path->next;
}
} else {
path_name = libname;
pack = pack_open (path_name);
}
if (!pack) { if (!pack) {
if (errno) if (errno)
perror (libname); perror (libname);
return 1; return 1;
} }
if (options.verbosity > 1)
puts (path_name);
do { do {
did_something = 0; did_something = 0;
for (i = 0; i < pack->numfiles; i++) { for (i = 0; i < pack->numfiles; i++) {
QFile *f; QFile *f;
qfo_t *qfo; qfo_t *qfo;
f = Qsubopen (libname, pack->files[i].filepos, f = Qsubopen (path_name, pack->files[i].filepos,
pack->files[i].filelen, 1); pack->files[i].filelen, 1);
qfo = qfo_read (f); qfo = qfo_read (f);
Qclose (f); Qclose (f);
@ -735,3 +769,13 @@ linker_finish (void)
qfo->entity_fields = entity->size; qfo->entity_fields = entity->size;
return qfo; return qfo;
} }
void
linker_add_path (const char *path)
{
path_t *p = malloc (sizeof (path_t));
p->next = 0;
p->path = path;
*path_tail = p;
path_tail = &p->next;
}

View file

@ -49,6 +49,7 @@ static const char rcsid[] =
#include "QF/va.h" #include "QF/va.h"
#include "cpp.h" #include "cpp.h"
#include "linker.h"
#include "options.h" #include "options.h"
#include "qfcc.h" #include "qfcc.h"
@ -82,6 +83,7 @@ static struct option const long_options[] = {
static const char *short_options = static const char *short_options =
"-" // magic option parsing mode doohicky (must come first) "-" // magic option parsing mode doohicky (must come first)
"l:" // lib file "l:" // lib file
"L:" // lib path
"o:" // output file "o:" // output file
"c" // separate compilation "c" // separate compilation
"r" // partial linking "r" // partial linking
@ -138,7 +140,7 @@ add_file (const char *file)
files_size += 16; files_size += 16;
source_files = realloc (source_files, files_size * sizeof (char *)); source_files = realloc (source_files, files_size * sizeof (char *));
} }
source_files[num_files++] = strdup (file); source_files[num_files++] = save_string (file);
source_files[num_files] = 0; source_files[num_files] = 0;
} }
@ -174,12 +176,15 @@ DecodeArgs (int argc, char **argv)
this_program); this_program);
exit (1); exit (1);
} else { } else {
options.output_file = strdup (optarg); options.output_file = save_string (optarg);
} }
break; break;
case 'l': // lib file case 'l': // lib file
add_file (va ("-l%s", optarg)); add_file (va ("-l%s", optarg));
break; break;
case 'L':
linker_add_path (optarg);
break;
case 'h': // help case 'h': // help
usage (0); usage (0);
break; break;
@ -188,10 +193,10 @@ DecodeArgs (int argc, char **argv)
exit (0); exit (0);
break; break;
case 's': // src dir case 's': // src dir
sourcedir = strdup (optarg); sourcedir = save_string (optarg);
break; break;
case 'P': // progs-src case 'P': // progs-src
progs_src = strdup (optarg); progs_src = save_string (optarg);
break; break;
case 'p': case 'p':
options.strip_path = atoi (optarg); options.strip_path = atoi (optarg);
@ -307,7 +312,7 @@ DecodeArgs (int argc, char **argv)
} }
break; break;
case 256: // --cpp= case 256: // --cpp=
cpp_name = strdup (optarg); cpp_name = save_string (optarg);
break; break;
case 'S': // save temps case 'S': // save temps
options.save_temps = true; options.save_temps = true;
@ -361,6 +366,11 @@ DecodeArgs (int argc, char **argv)
usage (1); usage (1);
} }
} }
// add the default paths
add_cpp_def (nva ("-I%s", QFCC_INCLUDE_PATH));
linker_add_path (QFCC_LIB_PATH);
if (options.verbosity >= 3) if (options.verbosity >= 3)
yydebug = 1; yydebug = 1;
return optind; return optind;

View file

@ -561,10 +561,16 @@ separate_compile (void)
qfo_t *qfo; qfo_t *qfo;
linker_begin (); linker_begin ();
for (file = source_files; *file; file++) { for (file = source_files; *file; file++) {
if (strncmp (*file, "-l", 2)) if (strncmp (*file, "-l", 2)) {
if (strlen (*file) >= 2
&& strcmp (*file + strlen (*file) - 2, ".a") == 0) {
err = linker_add_lib (*file);
} else {
err = linker_add_object_file (*file); err = linker_add_object_file (*file);
else }
err = linker_add_lib (*file + 2); } else {
err = linker_add_lib (*file);
}
if (err) if (err)
return err; return err;
} }