* as/asranlib/Makefile.in, as/asranlib/asranlib.dsp,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 9 Jan 2009 23:04:14 +0000 (23:04 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 9 Jan 2009 23:04:14 +0000 (23:04 +0000)
  as/asranlib/asranlib.c: added asranlib
* as/link/lkar.c, as/link/lkar.h: added support for ar format libraries
* Makefile.in, as/link/hc08/Makefile.in,
  as/link/hc08/link_hc08.dsp, as/link/lklib.c, as/link/lklibr.c,
  as/link/lklibr.h, as/link/lkrel.c, as/link/lkrel.h,
  as/link/lksdcclib.c, as/link/mcs51/Makefile.in,
  as/link/mcs51/aslink.dsp, as/link/z80/Makefile.in,
  as/link/z80/linkgbz80.dsp, as/link/z80/linkz80.dsp, configure,
  configure.in, sdcc.dsw: modified to support ar format libraries

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5336 4a8a32a2-be11-0410-ad9d-d568d2c75423

23 files changed:
ChangeLog
Makefile.in
as/asranlib/Makefile.in [new file with mode: 0644]
as/asranlib/asranlib.c [new file with mode: 0644]
as/asranlib/asranlib.dsp [new file with mode: 0644]
as/link/hc08/Makefile.in
as/link/hc08/link_hc08.dsp
as/link/lkar.c [new file with mode: 0644]
as/link/lkar.h [new file with mode: 0644]
as/link/lklib.c
as/link/lklibr.c
as/link/lklibr.h
as/link/lkrel.c
as/link/lkrel.h
as/link/lksdcclib.c
as/link/mcs51/Makefile.in
as/link/mcs51/aslink.dsp
as/link/z80/Makefile.in
as/link/z80/linkgbz80.dsp
as/link/z80/linkz80.dsp
configure
configure.in
sdcc.dsw

index 9dc2e5c140fee1ec0e1b65a1e649659cbe494d92..1f62ac880cc09f17bb2108cf608ed61a291f83dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-01-08 Borut Razem <borut.razem AT siol.net>
+
+       * as/asranlib/Makefile.in, as/asranlib/asranlib.dsp,
+         as/asranlib/asranlib.c: added asranlib
+       * as/link/lkar.c, as/link/lkar.h: added support for ar format libraries
+       * Makefile.in, as/link/hc08/Makefile.in,
+         as/link/hc08/link_hc08.dsp, as/link/lklib.c, as/link/lklibr.c,
+         as/link/lklibr.h, as/link/lkrel.c, as/link/lkrel.h,
+         as/link/lksdcclib.c, as/link/mcs51/Makefile.in,
+         as/link/mcs51/aslink.dsp, as/link/z80/Makefile.in,
+         as/link/z80/linkgbz80.dsp, as/link/z80/linkz80.dsp, configure,
+         configure.in, sdcc.dsw: modified to support ar format libraries
+
 2009-01-08 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/SDCCast.c (decorateType RETURN): use RESULT_TYPE_GPTR for generic
@@ -6,7 +19,7 @@
 2009-01-05 Philipp Klaus Krause <pkk AT spth.de>
 
        * sim/ucsim/z80.src/inst_ed.cc:
-          Fixed bug #2488074, which made regression tests fail.
+         Fixed bug #2488074, which made regression tests fail.
 
 2009-01-05 Philipp Klaus Krause <pkk AT spth.de>
 
index 0cf60ef7e3484ab0b20775c19627d050dfde15fe..b6884fd19bb621a3a582627cc6afd687bfac1501 100644 (file)
@@ -2,7 +2,7 @@
 #
 #
 
-SHELL          = /bin/sh
+SHELL           = /bin/sh
 
 VPATH           = @srcdir@
 srcdir          = @srcdir@
@@ -11,14 +11,17 @@ top_srcdir      = @top_srcdir@
 
 include Makefile.common
 
-SDCC_LIBS      = support/makebin
+SDCC_LIBS       = support/makebin
 SDCC_DOC        = doc
 
 # Parts that are not normally compiled but need to be cleaned
 SDCC_EXTRA      = support/regression support/valdiag
 
-SDCC_PACKIHX   = support/packihx
-SDCC_LIBRARIAN = support/librarian
+SDCC_PACKIHX    = support/packihx
+SDCC_LIBRARIAN  = support/librarian
+SDCC_ASRANLIB   = as/asranlib
+
+TARGETS         = sdcc-librarian sdcc-asranlib
 
 ifeq ($(OPT_DISABLE_HC08), 0)
 SDCC_ASLINK     += as/hc08 as/link/hc08
@@ -26,7 +29,7 @@ endif
 
 ifeq ($(OPT_DISABLE_MCS51), 0)
 SDCC_ASLINK     += as/mcs51 as/link/mcs51
-SDCC_MISC      += debugger/mcs51
+SDCC_MISC       += debugger/mcs51
 endif
 
 ifeq ($(OPT_DISABLE_Z80), 0)
@@ -59,14 +62,14 @@ ifeq ($(OPT_DISABLE_SDCPP), 0)
 SDCC_LIBS       += support/cpp
 endif
 
-TARGETS         += sdcc-libs sdcc-cc sdcc-device-inc sdcc-aslink sdcc-librarian
+TARGETS         += sdcc-libs sdcc-cc sdcc-device-inc sdcc-aslink
 
-PKGS           += $(SDCC_LIBS) src device/include $(SDCC_ASLINK) $(SDCC_LIBRARIAN)
+PKGS            += $(SDCC_LIBS) src device/include $(SDCC_ASLINK) $(SDCC_LIBRARIAN)
 
-PKGS_TINI      = $(SDCC_LIBS) $(SDCC_ASLINK) \
-                 src device/include $(SDCC_PACKIHX) $(SDCC_LIBRARIAN)
-PORTS          = $(shell cat ports.build)
-ALLPORTS       = $(shell cat ports.all)
+PKGS_TINI       = $(SDCC_LIBS) $(SDCC_ASLINK) \
+                  src device/include $(SDCC_PACKIHX) $(SDCC_LIBRARIAN)
+PORTS           = $(shell cat ports.build)
+ALLPORTS        = $(shell cat ports.all)
 
 # Compiling entire program or any subproject
 # ------------------------------------------
@@ -92,11 +95,14 @@ sdcc-packihx:
 sdcc-librarian:
        $(MAKE) -C $(SDCC_LIBRARIAN)
 
+sdcc-asranlib:
+       $(MAKE) -C $(SDCC_ASRANLIB)
+
 sdcc-device-inc:
        $(MAKE) -C device/include
 
 sdcc-device-lib: sdcc-cc sdcc-aslink
-       $(MAKE) -C device/lib
+       $(MAKE) -C device/lib LIB_TYPE=SDCCLIB
 
 sdcc-device-tini:
        $(MAKE) -C device/include
@@ -108,7 +114,7 @@ sdcc-doc:
 
 sdcc: $(TARGETS)
 
-sdcc-tini: sdcc-cc sdcc-aslink sdcc-device-tini sdcc-packihx sdcc-librarian
+sdcc-tini: sdcc-librarian sdcc-asranlib sdcc-cc sdcc-aslink sdcc-device-tini sdcc-packihx
        $(MAKE) -f main.mk all
 
 # Some interesting sub rules
diff --git a/as/asranlib/Makefile.in b/as/asranlib/Makefile.in
new file mode 100644 (file)
index 0000000..5889a67
--- /dev/null
@@ -0,0 +1,67 @@
+VPATH        = @srcdir@
+srcdir       = @srcdir@
+top_builddir = @top_builddir@
+
+include $(top_builddir)/Makefile.common
+
+CFLAGS          += -Wall -I$(srcdir)/../link
+
+OBJECTS         = asranlib.o
+
+SOURCES         = $(patsubst %.o,%.c,$(OBJECTS))
+
+TARGET          = $(top_builddir)/bin/asranlib$(EXEEXT)
+
+all: $(TARGET)
+
+install: all installdirs
+       $(INSTALL) $(TARGET) `echo $(DESTDIR)$(bindir)/asranlib$(EXEEXT)|sed '$(transform)'`
+       $(STRIP) `echo $(DESTDIR)$(bindir)/asranlib$(EXEEXT)|sed '$(transform)'`
+
+# Deleting all the installed files
+# --------------------------------
+uninstall:
+       rm -f $(DESTDIR)$(bindir)/asranlib$(EXEEXT)
+
+# Performing self-test
+# --------------------
+check:
+
+
+# Performing installation test
+# ----------------------------
+installcheck:
+
+
+# Creating installation directories
+# ---------------------------------
+installdirs:
+       $(INSTALL) -d $(DESTDIR)$(bindir)
+
+
+# Creating dependencies
+# ---------------------
+dep:
+
+$(TARGET): $(OBJECTS) dbuf.o dbuf_string.o
+       $(CC) $(LDFLAGS) -o $@ $(OBJECTS) dbuf.o dbuf_string.o
+
+dbuf.o: $(srcdir)/../../support/Util/dbuf.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+dbuf_string.o: $(srcdir)/../../support/Util/dbuf_string.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+.c.o:
+       $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+
+checkconf:
+
+clean:
+       rm -f *core *[%~] *.[oa] *.output
+       rm -f .[a-z]*~ \#*
+       rm -f $(top_builddir)/bin/asranlib$(EXEEXT)
+
+distclean realclean: clean
+       rm -f Makefile
diff --git a/as/asranlib/asranlib.c b/as/asranlib/asranlib.c
new file mode 100644 (file)
index 0000000..01977be
--- /dev/null
@@ -0,0 +1,442 @@
+/* asranlib.c - ranlib for asxxxx arvhives
+   version 1.0.0, April 27th, 2008
+
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include "dbuf_string.h"
+#include "lkar.h"
+
+#ifdef _WIN32
+#include <io.h>
+#define mktemp  _mktemp
+#endif
+
+#define NELEM(x)  (sizeof (x) / sizeof (*x))
+
+
+int
+is_ar (FILE * libfp)
+{
+  char buf[SARMAG];
+  int ret;
+
+  if (!(ret = fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, ARMAG, SARMAG) == 0))
+    rewind (libfp);
+
+  return ret;
+}
+
+static struct ar_hdr *
+ar_get_header (struct ar_hdr *hdr, FILE * libfp)
+{
+  char header[ARHDR_LEN];
+  char buf[AR_DATE_LEN + 1];
+
+  if (fread (header, 1, sizeof (header), libfp) != sizeof (header) ||
+      memcmp (header + AR_FMAG_OFFSET, ARFMAG, AR_FMAG_LEN) != 0)
+    {
+      /* not an ar archive */
+      return NULL;
+    }
+
+  memcpy (hdr->ar_name, &header[AR_NAME_OFFSET], AR_NAME_LEN);
+  hdr->ar_name[AR_NAME_LEN] = '\0';
+
+  memcpy (buf, &header[AR_DATE_OFFSET], AR_DATE_LEN);
+  buf[AR_DATE_LEN] = '\0';
+  hdr->ar_date = strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_UID_OFFSET], AR_GID_LEN);
+  buf[AR_GID_LEN] = '\0';
+  hdr->ar_uid = (uid_t) strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_GID_OFFSET], AR_DATE_LEN);
+  buf[AR_DATE_LEN] = '\0';
+  hdr->ar_gid = (gid_t) strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_MODE_OFFSET], AR_MODE_LEN);
+  buf[AR_MODE_LEN] = '\0';
+  hdr->ar_mode = (mode_t) strtoul (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_SIZE_OFFSET], AR_SIZE_LEN);
+  buf[AR_SIZE_LEN] = '\0';
+  hdr->ar_size = strtol (buf, NULL, 0);
+
+  return hdr;
+}
+
+
+struct symbol_s
+  {
+    const char *name;
+    off_t offset;
+    struct symbol_s *next;
+  };
+
+struct symbol_s *symlist, *lastsym;
+off_t offset, first_member_offset;
+
+int
+add_symbol (const char *sym, void *param)
+{
+  struct symbol_s *s;
+
+  if ((s = (struct symbol_s *) malloc (sizeof (struct symbol_s))) == NULL)
+    return 0;
+
+  s->name = strdup (sym);
+  s->offset = offset - first_member_offset;
+  s->next = NULL;
+
+  if (NULL == symlist)
+    {
+      lastsym = symlist = s;
+    }
+  else
+    {
+      lastsym->next = s;
+      lastsym = s;
+    }
+
+  return 0;
+}
+
+
+int
+is_rel (FILE * libfp)
+{
+  int c;
+  long pos = ftell (libfp);
+  int ret = 0;
+
+  /* [XDQ][HL] */
+  if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
+    {
+      switch (getc (libfp))
+        {
+        case '\r':
+          if (getc (libfp) == '\n')
+            ret = 1;
+          break;
+
+        case '\n':
+          ret = 1;
+        }
+    }
+  else if (c == ';')
+    {
+      char buf[6];
+
+      if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
+        ret = 1;
+    }
+  fseek (libfp, pos, SEEK_SET);
+  return ret;
+}
+
+int
+enum_symbols (FILE * fp, long size, int (*func) (const char *sym, void *param), void *param)
+{
+  long end;
+  struct dbuf_s buf;
+  struct dbuf_s symname;
+
+  assert (func != NULL);
+
+  dbuf_init (&buf, 512);
+  dbuf_init (&symname, 32);
+
+  end = (size >= 0) ? ftell (fp) + size : -1;
+
+  /*
+   * Read in the object file.  Look for lines that
+   * begin with "S" and end with "D".  These are
+   * symbol table definitions.  If we find one, see
+   * if it is our symbol.  Make sure we only read in
+   * our object file and don't go into the next one.
+   */
+
+  while (end < 0 || ftell (fp) < end)
+    {
+      const char *p;
+
+      dbuf_set_length (&buf, 0);
+      if (dbuf_getline (&buf, fp) == 0)
+        break;
+
+      p = dbuf_c_str (&buf);
+
+      if ('T' == p[0])
+        break;
+
+      /*
+       * Skip everything that's not a symbol record.
+       */
+      if ('S' == p[0] && ' ' == p[1])
+        {
+          dbuf_set_length (&symname, 0);
+
+          for (p += 2; *p && ' ' != *p; ++p)
+            dbuf_append_char (&symname, *p);
+
+          /* If it's an actual symbol, record it */
+          if (' ' == p[0] && 'D' == p[1])
+            if (func != NULL)
+              if ((*func) (dbuf_c_str (&symname), NULL))
+                return 1;
+        }
+    }
+
+  dbuf_destroy (&buf);
+  dbuf_destroy (&symname);
+
+  return 0;
+}
+
+int
+get_symbols (FILE * fp, const char *archive)
+{
+  struct ar_hdr hdr;
+
+  if (!is_ar (fp) || !ar_get_header (&hdr, fp))
+    {
+      fprintf (stderr, "asranlib: %s: File format not recognized\n", archive);
+      exit (1);
+    }
+
+  if (AR_IS_SYMBOL_TABLE (hdr))
+    {
+      /* skip the symbol table */
+      fseek (fp, hdr.ar_size + (hdr.ar_size & 1), SEEK_CUR);
+    }
+
+  first_member_offset = ftell (fp) - ARHDR_LEN;
+
+  /* walk trough all archive members */
+  do
+    {
+      if (is_rel (fp))
+        {
+          long mdule_offset = ftell (fp);
+
+          offset = mdule_offset - ARHDR_LEN;
+
+          enum_symbols (fp, hdr.ar_size, add_symbol, NULL);
+
+          fseek (fp, mdule_offset + hdr.ar_size, SEEK_SET);
+
+          if (hdr.ar_size & 1)
+            {
+              int c = getc (fp);
+              assert (c == EOF || c == '\n');
+            }
+        }
+      else
+        {
+          /* skip if the member is not a .REL format */
+          fseek (fp, hdr.ar_size + (hdr.ar_size & 1), SEEK_CUR);
+        }
+    }
+  while (ar_get_header (&hdr, fp));
+
+  return 1;
+}
+
+
+void
+do_ranlib (const char *archive)
+{
+  FILE *infp;
+
+  if (NULL == (infp = fopen (archive, "rb")))
+    {
+      fprintf (stderr, "asranlib: %s: ", archive);
+      perror (NULL);
+      exit (1);
+    }
+
+  if (get_symbols (infp, archive))
+    {
+      FILE *outfp = NULL;
+      struct symbol_s *symp;
+      char buf[4];
+      int str_length = 0;
+      int pad = 0;
+      int nsym;
+      int symtab_size;
+      char tmpfile[] = "arXXXXXX";
+
+      if (NULL == mktemp (tmpfile) || NULL == (outfp = fopen (tmpfile, "wb")))
+        {
+          fclose (infp);
+          fprintf (stderr, "asranlib: %s: ", tmpfile);
+          perror (NULL);
+          exit (1);
+        }
+
+      /* calculate the size of symbol table */
+      for (nsym = 0, symp = symlist; symp; ++nsym, symp = symp->next)
+        {
+          str_length += strlen (symp->name) + 1;
+        }
+
+      symtab_size = 4 + 4 * nsym + str_length;
+
+      fprintf (outfp, ARMAG AR_SYMBOL_TABLE_NAME "%-12d%-6d%-6d%-8d%-10d" ARFMAG, (int) time (NULL), 0, 0, 0, symtab_size);
+
+      if (symtab_size & 1)
+        {
+          pad = 1;
+          ++symtab_size;
+        }
+      else
+        pad = 0;
+
+      symtab_size += SARMAG + ARHDR_LEN;
+
+      sputl (nsym, buf);
+      fwrite (buf, 1, sizeof (buf), outfp);
+
+      for (symp = symlist; symp; symp = symp->next)
+        {
+          sputl (symp->offset + symtab_size, buf);
+          fwrite (buf, 1, sizeof (buf), outfp);
+        }
+
+
+      for (symp = symlist; symp; symp = symp->next)
+        {
+          fputs (symp->name, outfp);
+          putc ('\0', outfp);
+        }
+
+      if (pad)
+        putc ('\n', outfp);
+
+      fseek (infp, first_member_offset, SEEK_SET);
+
+      while (EOF != (pad = getc (infp)))
+        putc (pad, outfp);
+
+      fclose (outfp);
+      fclose (infp);
+
+      if (0 != remove (archive))
+        {
+          fprintf (stderr, "asranlib: can't remove %s to %s: ", tmpfile, archive);
+          perror (NULL);
+        }
+      else if (0 != rename (tmpfile, archive))
+        {
+          fprintf (stderr, "asranlib: can't rename %s to %s: ", tmpfile, archive);
+          perror (NULL);
+        }
+    }
+  else
+    fclose (infp);
+}
+
+
+void
+print_version (void)
+{
+  printf ("SDCC asxxxx ranlib 1.0.0 $Revision$\n");
+  exit (0);
+}
+
+
+void
+usage (void)
+{
+  printf ("Usage: asranlib [options] archive\n"
+    " Generate an index to speed access to archives\n"
+    " The options are:\n"
+    "  -h --help                    Print this help message\n"
+    "  -V --version                 Print version information\n"
+    "asranlib: supported targets: asxxxx\n");
+
+  exit (1);
+}
+
+
+struct opt_s
+  {
+    const char *opt;
+    void (*optfnc) (void);
+  }
+opts[] =
+  {
+    { "-v", &print_version, },
+    { "-V", &print_version, },
+    { "--version", &print_version, },
+    { "-h", &usage, },
+    { "--help", &usage, },
+  };
+
+
+void
+process_options (int argc, char *argv[])
+{
+  char **argp;
+  int noopts = 0;
+  int narch = 0;
+  for (argp = argv + 1; *argp; ++argp)
+    {
+      if (!noopts && (*argp)[0] == '-')
+        {
+          int i;
+
+          if ((*argp)[1] == '-' && (*argp)[2] == '\0')
+            {
+              noopts = 1;
+              continue;
+            }
+
+          for (i = 0; i < NELEM (opts); ++i)
+            {
+              if (0 == strcmp (*argp, opts[i].opt))
+                {
+                  if (NULL != opts[i].optfnc)
+                    {
+                      (*opts[i].optfnc) ();
+                      continue;
+                    }
+                }
+            }
+        }
+
+      do_ranlib (*argp);
+      ++narch;
+    }
+
+  if (!narch)
+    usage ();
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  process_options (argc, argv);
+
+  return 0;
+}
diff --git a/as/asranlib/asranlib.dsp b/as/asranlib/asranlib.dsp
new file mode 100644 (file)
index 0000000..be1e0b4
--- /dev/null
@@ -0,0 +1,132 @@
+# Microsoft Developer Studio Project File - Name="asranlib" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=asranlib - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "asranlib.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "asranlib.mak" CFG="asranlib - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "asranlib - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "asranlib - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "asranlib - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "Release"\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../link" /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD BASE RSC /l 0x424 /d "NDEBUG"\r
+# ADD RSC /l 0x424 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "asranlib - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "Debug"\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../link" /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c\r
+# ADD BASE RSC /l 0x424 /d "_DEBUG"\r
+# ADD RSC /l 0x424 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "asranlib - Win32 Release"\r
+# Name "asranlib - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asranlib.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.c\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\link\aslink.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\link\asxxxx_config.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\link\lkar.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\link\lkrel.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
index d2398537a22b521de994ff805006139354d72bcd..c74d260d32bfcb5ba93c297785d38204beacfc6e 100644 (file)
@@ -46,7 +46,7 @@ LKLIB = $(srcdir)/..
 
 ASXXLIBSRC = strcmpi.c
 
-LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+LKLIBSRC = getline.c lkaomf51.c lkar.c lkdata.c lkeval.c \
            lkhead.c lklex.c lklib.c lklibr.c lklist.c \
            lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
index 7a2359ac60bd5fe74902363bacb552187bb96c4f..1099f61458fd8037763b07fc0a26747440de0aa1 100644 (file)
@@ -95,6 +95,10 @@ SOURCE=..\lkaomf51.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkarea.c\r
 # End Source File\r
 # Begin Source File\r
@@ -191,6 +195,10 @@ SOURCE=..\getline.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.h\r
 # End Source File\r
 # Begin Source File\r
diff --git a/as/link/lkar.c b/as/link/lkar.c
new file mode 100644 (file)
index 0000000..6a9cc37
--- /dev/null
@@ -0,0 +1,642 @@
+/* lkar.c - ar library format handling
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/*
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+/*
+ * Extensions: P. Felber
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "aslink.h"
+#include "lklibr.h"
+#include "lkrel.h"
+#include "lkar.h"
+
+
+#ifndef max
+# define max(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef min
+# define min(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+
+static int
+is_ar (FILE * libfp)
+{
+  char buf[SARMAG];
+  int ret;
+
+  if (!(ret = fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, ARMAG, SARMAG) == 0))
+    rewind (libfp);
+
+  return ret;
+}
+
+static struct ar_hdr *
+ar_get_header (struct ar_hdr *hdr, FILE * libfp)
+{
+  char header[ARHDR_LEN];
+  char buf[AR_DATE_LEN + 1];
+
+  if (fread (header, 1, sizeof (header), libfp) != sizeof (header)
+      || memcmp (header + AR_FMAG_OFFSET, ARFMAG, AR_FMAG_LEN) != 0)
+    {
+      /* not an ar archive */
+      return NULL;
+    }
+
+  memcpy (hdr->ar_name, &header[AR_NAME_OFFSET], AR_NAME_LEN);
+  hdr->ar_name[AR_NAME_LEN] = '\0';
+
+  memcpy (buf, &header[AR_DATE_OFFSET], AR_DATE_LEN);
+  buf[AR_DATE_LEN] = '\0';
+  hdr->ar_date = strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_UID_OFFSET], AR_GID_LEN);
+  buf[AR_GID_LEN] = '\0';
+  hdr->ar_uid = (uid_t) strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_GID_OFFSET], AR_DATE_LEN);
+  buf[AR_DATE_LEN] = '\0';
+  hdr->ar_gid = (gid_t) strtol (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_MODE_OFFSET], AR_MODE_LEN);
+  buf[AR_MODE_LEN] = '\0';
+  hdr->ar_mode = (mode_t) strtoul (buf, NULL, 0);
+
+  memcpy (buf, &header[AR_SIZE_OFFSET], AR_SIZE_LEN);
+  buf[AR_SIZE_LEN] = '\0';
+  hdr->ar_size = strtol (buf, NULL, 0);
+
+  return hdr;
+}
+
+static char *sym_tab;
+static int sym_tab_size;
+
+static void
+loadfile_ar (struct lbfile *lbfh)
+{
+  FILE *fp;
+
+#ifdef __CYGWIN__
+  char posix_path[PATH_MAX];
+  void cygwin_conv_to_full_posix_path (char *win_path, char *posix_path);
+  cygwin_conv_to_full_posix_path (lbfh->libspc, posix_path);
+  fp = fopen (posix_path, "rb");
+#else
+  fp = fopen (lbfh->libspc, "rb");
+#endif
+
+  if (fp != NULL)
+    {
+      struct ar_hdr hdr;
+
+      fseek (fp, lbfh->offset, SEEK_SET);
+      if (ar_get_header (&hdr, fp))
+        {
+          D ("Loading module %s from file %s.\n", hdr.ar_name, lbfh->libspc);
+          load_rel (fp, hdr.ar_size);
+          fclose (fp);
+        }
+      else
+        {
+          fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", lbfh->libspc, lbfh->relfil);
+          fclose (fp);
+          lkexit (1);
+        }
+    }
+  else
+    {
+      fprintf (stderr, "?ASlink-Error-Opening library '%s'\n", lbfh->libspc);
+      lkexit (1);
+    }
+}
+
+#if INDEXLIB
+char *
+get_member_name (char *name)
+{
+  if (name[0] == '/')
+    {
+      if (NULL != sym_tab)
+        {
+          char *p;
+
+          int name_offset = strtol (++name, &p, 0);
+          if (p != name && name_offset < sym_tab_size)
+            {
+              int len = p - name + 1;
+              while (len < AR_NAME_LEN && name[len++] == ' ')
+                ;
+              if (len == AR_NAME_LEN)
+                {
+                  char *n;
+
+                  /* long name: get it from the symbol table */
+                  name = &sym_tab[name_offset];
+                  for (p = name; *p != '/' && *p != '\n'; ++p)
+                    assert (p < &sym_tab[sym_tab_size]);
+
+                  if (p[0] != '/' || p[1] != '\n')
+                    while (*++p != '\n')
+                      assert (p < &sym_tab[sym_tab_size]);
+
+                  n = (char *) malloc (p - name + 1);
+                  memcpy (n, name, p - name);
+                  n[p - name] = '\0';
+                  return n;
+                }
+            }
+        }
+    }
+  else
+    {
+      char *p = strrchr (name, '/');
+
+      if (NULL != p)
+        {
+          int len = p - name;
+          while (name[++len] == ' ')
+            ;
+          if (len == AR_NAME_LEN)
+            {
+              char *n = (char *) malloc (p - name + 1);
+              memcpy (n, name, p - name);
+              n[p - name] = '\0';
+              return n;
+            }
+        }
+    }
+
+  /* bad formed member name:
+     just return it */
+
+  return strdup (name);
+}
+
+static char *
+get_member_name_by_offset (FILE * fp, long offset)
+{
+  struct ar_hdr hdr;
+
+  fseek (fp, offset, SEEK_SET);
+
+  /* walk trough all archive members */
+  return (NULL != ar_get_header (&hdr, fp)) ? get_member_name (hdr.ar_name) : NULL;
+}
+
+static pmlibraryfile
+find_member_by_offset (const char *libspc, long offset)
+{
+  pmlibraryfile p;
+
+  for (p = libr; p; p = p->next)
+    {
+      if (0 == strcmp (libspc, p->libspc) && p->offset == offset)
+        return p;
+    }
+
+  return NULL;
+}
+
+static pmlibraryfile
+buildlibraryindex_ar (struct lbname *lbnh, FILE * libfp, pmlibraryfile This, int type)
+{
+  struct ar_hdr hdr;
+
+  /* walk trough all archive members */
+  while (ar_get_header (&hdr, libfp))
+    {
+      if (AR_IS_SYMBOL_TABLE (hdr))
+        {
+          char *buf, *po, *ps;
+          int i;
+          long nsym;
+
+          buf = (char *) new (hdr.ar_size);
+
+          if ((off_t) fread (buf, 1, hdr.ar_size, libfp) != hdr.ar_size)
+            {
+              free (buf);
+              return This;
+            }
+
+          nsym = sgetl (buf);
+
+          po = buf + 4;
+          ps = po + nsym * 4;
+
+          for (i = 0; i < nsym; ++i)
+            {
+              pmlibrarysymbol ThisSym;
+              char *sym;
+              long offset;
+              pmlibraryfile entry;
+
+              offset = sgetl (po);
+              po += 4;
+
+              sym = strdup (ps);
+              while (*ps++ != '\0')
+                ;
+
+              if ((entry = find_member_by_offset (lbnh->libspc, offset)) != NULL)
+                {
+                  for (ThisSym = entry->symbols; ThisSym->next != NULL; ThisSym = ThisSym->next)
+                    ;
+                }
+              else
+                {
+                  /* Opened OK - create a new libraryfile object for it */
+                  if (This == NULL)
+                    {
+                      assert (libr == NULL);
+                      libr = This = (pmlibraryfile) new (sizeof (mlibraryfile));
+                    }
+                  else
+                    {
+                      This->next = (pmlibraryfile) new (sizeof (mlibraryfile));
+                      This = This->next;
+                    }
+                  This->next = NULL;
+                  This->loaded = -1;
+                  This->libspc = lbnh->libspc;
+                  This->offset = offset;
+                  This->relfil = get_member_name_by_offset (libfp, offset);     /* member name */
+                  This->filspc = strdup (This->relfil); /* member file name */
+                  This->type = type;
+
+                  /* start a new linked list of symbols for this module. */
+                  This->symbols = ThisSym = NULL;
+                }
+
+              if (ThisSym == NULL)
+                ThisSym = This->symbols = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
+              else
+                {
+                  ThisSym->next = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
+                  ThisSym = ThisSym->next;
+                }
+              This->loaded = 0;
+              ThisSym->next = NULL;
+              ThisSym->name = sym;
+            }
+          free (buf);
+
+          break;
+        }
+      else if (AR_IS_STRING_TABLE (hdr))
+        {
+          if (sym_tab)
+            free (sym_tab);
+
+          sym_tab = (char *) new (hdr.ar_size);
+
+          if ((off_t) fread (sym_tab, 1, hdr.ar_size, libfp) != hdr.ar_size)
+            {
+              free (sym_tab);
+              sym_tab_size = 0;
+              return This;
+            }
+          sym_tab_size = hdr.ar_size;
+        }
+      else
+        {
+          long moduleOffset = ftell (libfp);
+
+          /* Opened OK - create a new libraryfile object for it */
+          if (This == NULL)
+            {
+              assert (libr == NULL);
+              libr = This = (pmlibraryfile) new (sizeof (mlibraryfile));
+            }
+          else
+            {
+              This->next = (pmlibraryfile) new (sizeof (mlibraryfile));
+              This = This->next;
+            }
+          This->next = NULL;
+          This->loaded = -1;
+          This->libspc = lbnh->libspc;
+          This->offset = moduleOffset - ARHDR_LEN;
+
+          This->relfil = get_member_name (hdr.ar_name); /* member name */
+          This->filspc = strdup (This->relfil); /* member file name */
+
+          D ("  Indexing module: %s\n", This->relfil);
+
+          This->type = type;
+
+          /* start a new linked list of symbols for this module. */
+          This->symbols = NULL;
+
+          add_rel_index (libfp, hdr.ar_size, This);
+
+          fseek (libfp, moduleOffset + hdr.ar_size, SEEK_SET);
+        }
+
+      if (hdr.ar_size & 1)
+        {
+          int c = getc (libfp);
+          assert (c == EOF || c == '\n');
+        }
+    }
+
+  if (NULL != sym_tab)
+    {
+      free (sym_tab);
+      sym_tab = NULL;
+      sym_tab_size = 0;
+    }
+
+  return This;
+}
+
+#else
+
+#if 0
+static int
+load_adb (FILE * libfp, struct lbfile *lbfh)
+{
+  struct ar_hdr hdr;
+  char *adb_name;
+
+  /* check if it is a .rel file */
+  if (0 != stricmp (&lbfh->relfil[strlen (lbfh->relfil) - 4], ".rel"))
+    return 0;
+
+
+  adb_name = (char *) new (strlen (lbfh->relfil) + 1);
+  memcpy (adb_name, lbfh->relfil, strlen (lbfh->relfil) - 4);
+  memcpy (&adb_name[strlen (lbfh->relfil) - 4], ".adb", 5);
+
+  if (!is_ar (libfp))
+    {
+      fprintf (stderr, "?ASlink-Error-%s is not an archive\n", lbfh->libspc);
+      fclose (libfp);
+      lkexit (1);
+    }
+
+
+  /* walk trough all archive members */
+  while (ar_get_header (&hdr, libfp))
+    {
+      if (AR_IS_STRING_TABLE (hdr))
+        {
+          if (sym_tab)
+            free (sym_tab);
+
+          sym_tab = (char *) new (hdr.ar_size);
+
+          if ((off_t) fread (sym_tab, 1, hdr.ar_size, libfp) != hdr.ar_size)
+            {
+              free (sym_tab);
+              sym_tab_size = 0;
+              return 0;
+            }
+          sym_tab_size = hdr.ar_size;
+        }
+      if (AR_IS_SYMBOL_TABLE (hdr) || 0 != stricmp (get_member_name (hdr.ar_name), adb_name))
+        {
+          /* skip the mamber */
+          fseek (libfp, hdr.ar_size + (hdr.ar_size & 1), SEEK_CUR);
+        }
+      else
+        {
+          long left = hdr.ar_size;
+          char buf[4096];
+
+          while (left)
+            {
+              size_t n = min (left, sizeof buf);
+
+              if (fread (buf, 1, n, libfp) != n)
+                {
+                  assert (0);
+                }
+
+              fwrite (buf, 1, n, dfp);
+
+              left -= n;
+            }
+
+          if (hdr.ar_size & 1)
+            {
+              int c = getc (libfp);
+              assert (c == EOF || c == '\n');
+            }
+
+          free (adb_name);
+          return 1;
+        }
+    }
+
+  free (adb_name);
+  return 0;
+}
+#endif
+
+static int
+fndsym_ar (const char *name, struct lbname *lbnh, FILE * libfp, int type)
+{
+  struct ar_hdr hdr;
+  int ret = 0;
+
+  /* walk trough all archive members */
+  while (ar_get_header (&hdr, libfp))
+    {
+      char filspc[PATH_MAX];
+
+      if (lbnh->path != NULL)
+        {
+          strcpy (filspc, lbnh->path);
+#ifdef  OTHERSYSTEM
+          if (*filspc != '\0' && (filspc[strlen (filspc) - 1] != '/') && (filspc[strlen (filspc) - 1] != LKDIRSEP))
+            {
+              strcat (filspc, LKDIRSEPSTR);
+            }
+#endif
+        }
+
+      if (AR_IS_SYMBOL_TABLE (hdr))
+        {
+          char *buf, *po, *ps;
+          int i;
+          long nsym;
+
+          buf = (char *) new (hdr.ar_size);
+
+          if ((off_t) fread (buf, 1, hdr.ar_size, libfp) != hdr.ar_size)
+            {
+              free (buf);
+              return 0;
+            }
+
+          nsym = sgetl (buf);
+
+          po = buf + 4;
+          ps = po + nsym * 4;
+
+          for (i = 0; i < nsym; ++i)
+            {
+              char *sym;
+              long offset;
+
+              offset = sgetl (po);
+              po += 4;
+
+              sym = ps;
+              while (*ps++ != '\0')
+                ;
+
+              if (0 == strcmp (name, sym))
+                {
+                  fseek (libfp, offset, SEEK_SET);
+                  if (ar_get_header (&hdr, libfp))
+                    {
+                      sprintf (&filspc[strlen (filspc)], "%s", hdr.ar_name);
+
+                      /* If this module has been loaded already don't load it again. */
+                      if (!is_module_loaded (filspc))
+                        {
+                          struct lbfile *lbfh, *lbf;
+
+                          lbfh = (struct lbfile *) new (sizeof (struct lbfile));
+                          lbfh->libspc = strdup (lbnh->libspc);
+                          lbfh->relfil = strdup (hdr.ar_name);
+                          lbfh->filspc = strdup (filspc);
+                          lbfh->offset = offset;
+                          lbfh->type = type;
+
+                          if (lbfhead == NULL)
+                            {
+                              lbfhead = lbfh;
+                            }
+                          else
+                            {
+                              for (lbf = lbfhead; lbf->next != NULL; lbf = lbf->next)
+                                ;
+
+                              lbf->next = lbfh;
+                            }
+
+                          D ("Loading module %s from file %s.\n", hdr.ar_name, lbfh->libspc);
+                          load_rel (libfp, hdr.ar_size);
+                          ///* if cdb information required & .adb file present */
+                          //if (dflag && dfp)
+                          //  {
+                          //    if (load_adb(FILE *libfp, struct lbfile *lbfh))
+                          //      SaveLinkedFilePath (filspc);
+                          //  }
+                          ret = 1;
+                          break;
+                        }
+                    }
+                  else
+                    {
+                      fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", lbnh->libspc, name);
+                      fclose (libfp);
+                      lkexit (1);
+                    }
+                }
+            }
+          free (buf);
+
+          break;
+        }
+      else if (AR_IS_STRING_TABLE (hdr))
+        {
+          if (sym_tab)
+            free (sym_tab);
+
+          sym_tab = (char *) new (hdr.ar_size);
+
+          if ((off_t) fread (sym_tab, 1, hdr.ar_size, libfp) != hdr.ar_size)
+            {
+              free (sym_tab);
+              sym_tab = NULL;
+              sym_tab_size = 0;
+              return 0;
+            }
+          sym_tab_size = hdr.ar_size;
+        }
+      else
+        {
+          long moduleOffset = ftell (libfp);
+
+          D ("  Module: %s\n", hdr.ar_name);
+
+          sprintf (&filspc[strlen (filspc)], "%s", hdr.ar_name);
+
+          /* Opened OK - create a new libraryfile object for it */
+          ret = add_rel_file (name, lbnh, hdr.ar_name, filspc, moduleOffset - ARHDR_LEN, libfp, hdr.ar_size, type);
+          ///* if cdb information required & .adb file present */
+          //if (dflag && dfp)
+          //  {
+          //    if (load_adb(FILE *libfp, struct lbfile *lbfh))
+          //      SaveLinkedFilePath (filspc);
+          //  }
+          if (ret)
+            break;
+
+          fseek (libfp, moduleOffset + hdr.ar_size, SEEK_SET);
+        }
+
+      if (hdr.ar_size & 1)
+        {
+          int c = getc (libfp);
+          assert (c == EOF || c == '\n');
+        }
+    }
+
+  if (NULL != sym_tab)
+    {
+      free (sym_tab);
+      sym_tab = NULL;
+      sym_tab_size = 0;
+    }
+
+  return ret;
+}
+#endif
+
+struct aslib_target aslib_target_ar = {
+  &is_ar,
+#ifdef INDEXLIB
+  &buildlibraryindex_ar,
+#else
+  &fndsym_ar,
+#endif
+  &loadfile_ar,
+};
diff --git a/as/link/lkar.h b/as/link/lkar.h
new file mode 100644 (file)
index 0000000..586c1b0
--- /dev/null
@@ -0,0 +1,86 @@
+/* lkar.h - ar library format handling
+
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef __LKAR_H
+#define __LKAR_H
+
+#include <sys/types.h>
+#include <string.h>
+
+
+#ifdef _WIN32
+typedef unsigned short mode_t;
+typedef short uid_t;
+typedef short gid_t;
+typedef _off_t off_t;
+#endif
+
+#ifdef WORDS_BIGENDIAN
+#define sgetl(buf)  (((((((unsigned char)(buf)[3] << 8) + (unsigned char)(buf)[2]) << 8) + (unsigned char)(buf)[1]) << 8) + (unsigned char)(buf)[0])
+#define sputl(value, buf)  ((buf)[3] = ((value) >> 24, (buf)[2] = (value) >> 16, (buf)[1] = (value) >> 8, (buf)[0] = (value))
+#else
+#define sgetl(buf)  (((((((unsigned char)(buf)[0] << 8) + (unsigned char)(buf)[1]) << 8) + (unsigned char)(buf)[2]) << 8) + (unsigned char)(buf)[3])
+#define sputl(value, buf)  ((buf)[0] = (value) >> 24, (buf)[1] = (value) >> 16, (buf)[2] = (value) >> 8, (buf)[3] = (value))
+#endif
+
+#define ARMAG   "!<arch>\n"           /* magic string */
+#define SARMAG  (sizeof (ARMAG) - 1)  /* length of magic string */
+
+#define ARFMAG  "`\n"                 /* header trailer string */
+
+#define AR_NAME_OFFSET  0
+#define AR_NAME_LEN     16
+
+#define AR_DATE_OFFSET  16
+#define AR_DATE_LEN     12
+
+#define AR_UID_OFFSET   28
+#define AR_UID_LEN      6
+
+#define AR_GID_OFFSET   34
+#define AR_GID_LEN      6
+
+#define AR_MODE_OFFSET  40
+#define AR_MODE_LEN     8
+
+#define AR_SIZE_OFFSET  48
+#define AR_SIZE_LEN     10
+
+#define AR_FMAG_OFFSET  58
+#define AR_FMAG_LEN     (sizeof (ARFMAG) - 1)
+
+#define ARHDR_LEN (AR_NAME_LEN + AR_DATE_LEN + AR_UID_LEN + AR_GID_LEN + AR_MODE_LEN + AR_SIZE_LEN + AR_FMAG_LEN)
+
+#define AR_SYMBOL_TABLE_NAME "/               "
+#define AR_STRING_TABLE_NAME "//              "
+
+#define AR_IS_SYMBOL_TABLE(hdr) (0 == strcmp((hdr).ar_name, AR_SYMBOL_TABLE_NAME))
+#define AR_IS_STRING_TABLE(hdr) (0 == strcmp((hdr).ar_name, AR_STRING_TABLE_NAME))
+
+
+struct ar_hdr                     /* archive member header */
+{
+  char ar_name[AR_NAME_LEN + 1];  /* archive member name */
+  time_t ar_date;                 /* archive member date */
+  uid_t ar_uid;                   /* archive member user identification */
+  gid_t ar_gid;                   /* archive member group identification */
+  mode_t ar_mode;                 /* archive member mode (octal) */
+  off_t ar_size;                  /* archive member size */
+};
+
+#endif /* __LKAR_H */
index b074351926c3ec33b62fae2962e2fb2126564c21..cab38d9a03c87c6ed13694bd8c393348436203ea 100644 (file)
@@ -1,13 +1,24 @@
-/* lklib.c */
+/* lklib.c
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
@@ -89,7 +100,7 @@ buildlibraryindex_lib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This, in
           This->loaded = -1;
           This->libspc = lbnh->libspc;
           This->relfil = strdup (relfil);
-          This->filename = strdup (str);
+          This->filspc = strdup (str);
           This->type = type;
 
           /* Start a new linked list of symbols for this module: */
@@ -114,6 +125,8 @@ fndsym_lib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
 {
   char relfil[NINPUT];
 
+  D ("Searching symbol: %s\n", name);
+
   while (getline (relfil, sizeof (relfil), libfp) != NULL)
     {
       char str[PATH_MAX];
@@ -153,6 +166,7 @@ fndsym_lib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
           fclose (fp);
           if (ret)
             {
+              D ("Loaded module %s from file %s.\n", str, str);
               /* if cdb information required & adb file present */
               if (dflag && dfp)
                 {
index b15fd8a8b70769b20ced4889881d9a98efc6f5a3..219e7e339083658fe2704f5e399922fdfbea3107 100644 (file)
@@ -1,13 +1,24 @@
-/* lklibr.c */
+/* lklibr.c
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
@@ -61,6 +72,7 @@ void freelibraryindex (void);
 
 struct aslib_target *aslib_targets[] = {
   &aslib_target_sdcclib,
+  &aslib_target_ar,
   &aslib_target_lib,
 };
 
@@ -464,19 +476,18 @@ fndsym (char *name)
   pmlibraryfile FirstFound;
   int numfound = 0;
 
+  D ("Searching symbol: %s\n", name);
+
   /* Build the index if this is the first call to fndsym */
   if (libr == NULL)
     buildlibraryindex ();
 
   /* Iterate through all library object files */
-  ThisLibr = libr;
-  FirstFound = libr;            /*So gcc stops whining */
-  while (ThisLibr)
+  FirstFound = libr;            /* So gcc stops whining */
+  for (ThisLibr = libr; ThisLibr != NULL; ThisLibr = ThisLibr->next)
     {
       /* Iterate through all symbols in an object file */
-      ThisSym = ThisLibr->symbols;
-
-      while (ThisSym)
+      for (ThisSym = ThisLibr->symbols; ThisSym != NULL; ThisSym = ThisSym->next)
         {
           if (!strcmp (ThisSym->name, name))
             {
@@ -490,15 +501,13 @@ fndsym (char *name)
                     }
                   else
                     {
-                      lbf = lbfhead;
-                      while (lbf->next)
-                        {
-                          lbf = lbf->next;
-                        }
+                      for (lbf = lbfhead; lbf->next != NULL; lbf = lbf->next)
+                        ;
+
                       lbf->next = lbfh;
                     }
                   lbfh->libspc = ThisLibr->libspc;
-                  lbfh->filspc = ThisLibr->filename;
+                  lbfh->filspc = ThisLibr->filspc;
                   lbfh->relfil = strdup (ThisLibr->relfil);
                   lbfh->offset = ThisLibr->offset;
                   lbfh->type = ThisLibr->type;
@@ -542,9 +551,7 @@ fndsym (char *name)
                     }
                 }
             }
-          ThisSym = ThisSym->next;      /* Next sym in library */
         }
-      ThisLibr = ThisLibr->next;        /* Next library in list */
     }
   return numfound;
 }
@@ -561,6 +568,8 @@ add_sybmol (const char *sym, void *param)
   struct add_sym_s *as = (struct add_sym_s *) param;
   pmlibrarysymbol ps = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
 
+  D ("    Indexing symbol: %s\n", sym);
+
   as->plf->loaded = 0;
   ps->next = NULL;
   ps->name = strdup (sym);
@@ -609,6 +618,8 @@ buildlibraryindex (void)
       FILE *libfp;
       int i;
 
+      D ("Indexing library: %s\n", lbnh->libspc);
+
       if ((libfp = fopen (lbnh->libspc, "rb")) == NULL)
         {
           fprintf (stderr, "?ASlink-Error-Cannot open library file %s\n", lbnh->libspc);
@@ -633,7 +644,7 @@ buildlibraryindex (void)
   return 0;
 }
 
-/*Release all memory allocated for the in-memory library index*/
+/* Release all memory allocated for the in-memory library index */
 void
 freelibraryindex (void)
 {
@@ -653,7 +664,7 @@ freelibraryindex (void)
           ThisSym = ThisSym->next;
           free (ThisSym2Free);
         }
-      free (ThisLibr->filename);
+      free (ThisLibr->filspc);
       free (ThisLibr->relfil);
       ThisLibr2Free = ThisLibr;
       ThisLibr = ThisLibr->next;
@@ -680,10 +691,14 @@ load_sybmol (const char *sym, void *params)
 {
   struct load_sym_s *ls = (struct load_sym_s *) params;
 
+  D ("    Symbol: %s\n", sym);
+
   if (strcmp (ls->name, sym) == 0)
     {
       struct lbfile *lbfh, *lbf;
 
+      D ("    Symbol %s found in module %s!\n", sym, ls->relfil);
+
       lbfh = (struct lbfile *) new (sizeof (struct lbfile));
       lbfh->libspc = ls->lbnh->libspc;
       lbfh->relfil = strdup (ls->relfil);
@@ -692,19 +707,13 @@ load_sybmol (const char *sym, void *params)
       lbfh->type = ls->type;
 
       if (lbfhead == NULL)
-        {
-          lbfhead = lbfh;
-        }
+        lbfhead = lbfh;
       else
         {
-          lbf = lbfhead;
-          while (lbf->next)
-            {
-              lbf = lbf->next;
-            }
+          for (lbf = lbfhead; lbf->next != NULL; lbf = lbf->next)
+              ;
           lbf->next = lbfh;
         }
-
       (*aslib_targets[ls->type]->loadfile) (lbfh);
 
       return 1;
@@ -713,19 +722,47 @@ load_sybmol (const char *sym, void *params)
     return 0;
 }
 
+/*)Function int is_module_loaded(filspc)
+ *
+ * If this module has been already loaded
+ */
+
+int
+is_module_loaded (const char *filspc)
+{
+  struct lbfile *lbf;
+
+  for (lbf = lbfhead; lbf != NULL; lbf = lbf->next)
+    {
+      if (EQ (filspc, lbf->filspc))
+        {
+          D ("  Module %s already loaded!\n", filspc);
+          return 1;       /* Module already loaded */
+        }
+    }
+  return 0;
+}
+
 int
 add_rel_file (const char *name, struct lbname *lbnh, const char *relfil,
               const char *filspc, int offset, FILE * fp, long size, int type)
 {
   struct load_sym_s ls;
-  ls.name = name;
-  ls.lbnh = lbnh;
-  ls.relfil = relfil;
-  ls.filspc = filspc;
-  ls.offset = offset;
-  ls.type = type;
-
-  return enum_symbols (fp, size, &load_sybmol, &ls);
+
+  /* If this module has been loaded already don't load it again. */
+  if (is_module_loaded (filspc))
+    return 0;
+  else
+    {
+      ls.name = name;
+      ls.lbnh = lbnh;
+      ls.relfil = relfil;
+      ls.filspc = filspc;
+      ls.offset = offset;
+      ls.type = type;
+
+      return enum_symbols (fp, size, &load_sybmol, &ls);
+  }
 }
 
 int
@@ -738,10 +775,15 @@ fndsym (const char *name)
   /*
    * Search through every library in the linked list "lbnhead".
    */
+
+  D ("Searching symbol: %s\n", name);
+
   for (lbnh = lbnhead; lbnh; lbnh = lbnh->next)
     {
       int ret = 0;
 
+      D ("Library: %s\n", lbnh->libspc);
+
       if ((libfp = fopen (lbnh->libspc, "rb")) == NULL)
         {
           fprintf (stderr, "?ASlink-Error-Cannot open library file %s\n", lbnh->libspc);
index 47dafe2f9d27617667397cbf3d534a7dc533effd..040fc17bb28eeaca3570f9ccdab3c3dc747b7f5b 100644 (file)
@@ -1,13 +1,24 @@
-/* lklibr.h */
+/* lklibr.h
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
 
 #include <stdio.h>
 
+#ifdef INDEXLIB
 typedef struct slibrarysymbol mlibrarysymbol;
 typedef struct slibrarysymbol *pmlibrarysymbol;
 
 struct slibrarysymbol
 {
-  char *name;                   /*Warning: allocate memory before using */
+  char *name;                   /* Warning: allocate memory before using */
   pmlibrarysymbol next;
 };
 
@@ -41,7 +53,7 @@ struct slibraryfile
   int loaded;
   char *libspc;
   char *relfil;                 /* Warning: allocate memory before using */
-  char *filename;               /* Warning: allocate memory before using */
+  char *filspc;                 /* Warning: allocate memory before using */
   long offset;                  /* The embedded file offset in the library file libspc */
   unsigned int type;
   pmlibrarysymbol symbols;
@@ -50,9 +62,9 @@ struct slibraryfile
 
 extern pmlibraryfile libr;
 
-#ifdef INDEXLIB
 pmlibrarysymbol add_rel_index (FILE * fp, long size, pmlibraryfile This);
 #else
+int is_module_loaded (const char *filspc);
 int add_rel_file (const char *name, struct lbname *lbnh, const char *relfil,
                   const char *filspc, int offset, FILE * fp, long size, int type);
 #endif
@@ -69,6 +81,16 @@ struct aslib_target
 };
 
 extern struct aslib_target aslib_target_sdcclib;
+extern struct aslib_target aslib_target_ar;
 extern struct aslib_target aslib_target_lib;
 
+////
+//#define DEBUG_PRINT
+
+#ifdef DEBUG_PRINT
+# define D  printf
+#else
+# define D  1 ? (void)0 : (*(void (*)(const char *, ...))0)
+#endif
+
 #endif /* __LKLIBR_H */
index 3914acedc96b80931c6dc2f5e1f7e90b1c6ffafb..7b5a931cfa02c68b2761a99dbaa9159a2b780498 100644 (file)
@@ -1,13 +1,24 @@
-/* lkrel.c */
+/* lkrel.c - .rel object file handling
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
@@ -37,22 +48,22 @@ is_rel (FILE * libfp)
   if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
     {
       switch (getc (libfp))
-       {
-       case '\r':
-         if (getc (libfp) == '\n')
-           ret = 1;
-         break;
-
-       case '\n':
-         ret = 1;
-       }
+        {
+        case '\r':
+          if (getc (libfp) == '\n')
+            ret = 1;
+          break;
+
+        case '\n':
+          ret = 1;
+        }
     }
   else if (c == ';')
     {
       char buf[6];
 
       if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
-       ret = 1;
+        ret = 1;
     }
   fseek (libfp, pos, SEEK_SET);
   return ret;
@@ -70,13 +81,13 @@ load_rel (FILE * libfp, long size)
       end = (size >= 0) ? ftell (libfp) + size : -1;
 
       while ((end < 0 || ftell (libfp) < end) && getline (str, sizeof (str), libfp) != NULL)
-       {
-         if (0 == strcmp (str, "</REL>"))
-           return 1;
+        {
+          if (0 == strcmp (str, "</REL>"))
+            return 1;
 
-         ip = str;
-         link_main ();
-       }
+          ip = str;
+          link_main ();
+        }
 
       return 1;
     }
@@ -100,7 +111,7 @@ enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *para
    * our object file and don't go into the next one.
    */
 
-  while ((end <= 0 || ftell (fp) < end) && getline (buf, sizeof (buf), fp) != NULL)
+  while ((end < 0 || ftell (fp) < end) && getline (buf, sizeof (buf), fp) != NULL)
     {
       char symname[NINPUT];
       char c;
@@ -110,22 +121,22 @@ enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *para
        * All 'S line's preceed 'T line's in .REL files.
        */
       if (buf[0] == 'T')
-       break;
+        break;
 
       /*
        * Skip everything that's not a symbol record.
        */
       if (buf[0] != 'S')
-       continue;
+        continue;
 
       sscanf (buf, "S %s %c", symname, &c);
 
       /* If it's an actual symbol, record it */
       if (c == 'D')
-       {
-         if ((*func) (symname, param))
-           return 1;
-       }
+        {
+          if ((*func) (symname, param))
+            return 1;
+        }
     }
 
   return 0;
index 68e84c247b2b831cbaf16835a140aa2e1e8dba6b..3d88d63a4e2f0dd926024567e25c7dee37a5b31a 100644 (file)
@@ -1,13 +1,24 @@
-/* lkrel.h */
+/* lkrel.h - .rel object file handling
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
  *
  */
 
+/*
+ * Extensions: P. Felber
+ */
+
 #ifndef __LKREL_H
 #define __LKREL_H
 
@@ -34,4 +49,4 @@ extern "C"
 }
 #endif
 
-#endif                         /* __LKREL_H */
+#endif                          /* __LKREL_H */
index a1c781c6e4775ceeee95aa8d1e9bbf81d2ea16f6..d45c0c39e1e8d11d9d20d64de2fecdd66a1d69c6 100644 (file)
@@ -1,13 +1,24 @@
-/* lksdcclib.c */
+/* lksdcclib.c - sdcc library format handling
+
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+   Copyright (C) 2008 Borut Razem, borut dot razem at siol dot net
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- *
  * With contributions for the
  * object libraries from
  * Ken Hornstein
@@ -90,11 +101,9 @@ LoadRel (char *libfname, FILE * libfp, char *ModName)
 static pmlibraryfile
 buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This, int type)
 {
-  char ModName[NCPS] = "";
   char FLine[MAXLINE];
-  char buff[PATH_MAX];
   int state = 0;
-  long IndexOffset = 0, FileOffset;
+  long IndexOffset = 0;
   pmlibrarysymbol ThisSym = NULL;
 
   while (getline (FLine, sizeof (FLine), libfp))
@@ -114,6 +123,10 @@ buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This
         case 1:
           if (EQ (FLine, "<MODULE>"))
             {
+              char buff[PATH_MAX];
+              char ModName[NCPS] = "";
+              long FileOffset;
+
               /* The next line has the name of the module and the offset
                  of the corresponding embedded file in the library */
               getline (FLine, sizeof (FLine), libfp);
@@ -136,7 +149,7 @@ buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This
               This->libspc = lbnh->libspc;
               This->relfil = strdup (ModName);
               sprintf (buff, "%s%s%c%s", lbnh->path, ModName, FSEPX, LKOBJEXT);
-              This->filename = strdup (buff);
+              This->filspc = strdup (buff);
               This->type = type;
 
               This->symbols = ThisSym = NULL;   /* Start a new linked list of symbols */
@@ -221,7 +234,7 @@ LoadAdb (FILE * libfp)
 static int
 findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
 {
-  struct lbfile *lbfh, *lbf;
+  struct lbfile *lbfh;
   char ModName[NCPS] = "";
   char FLine[MAXLINE];
   int state = 0;
@@ -229,15 +242,15 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
 
   while (getline (FLine, sizeof (FLine), libfp))
     {
-      char str[PATH_MAX];
+      char filspc[PATH_MAX];
 
       if (lbnh->path != NULL)
         {
-          strcpy (str, lbnh->path);
+          strcpy (filspc, lbnh->path);
 #ifdef  OTHERSYSTEM
-          if (*str != '\0' && (str[strlen (str) - 1] != '/') && (str[strlen (str) - 1] != LKDIRSEP))
+          if (*filspc != '\0' && (filspc[strlen (filspc) - 1] != '/') && (filspc[strlen (filspc) - 1] != LKDIRSEP))
             {
-              strcat (str, LKDIRSEPSTR);
+              strcat (filspc, LKDIRSEPSTR);
             }
 #endif
         }
@@ -285,16 +298,11 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
 
                   /* As in the original library format, it is assumed that the .rel
                      files reside in the same directory as the lib files. */
-                  sprintf (&str[strlen (str)], "%s%c%s", ModName, FSEPX, LKOBJEXT);
+                  sprintf (&filspc[strlen (filspc)], "%s%c%s", ModName, FSEPX, LKOBJEXT);
 
                   /* If this module has been loaded already don't load it again. */
-                  lbf = lbfhead;
-                  while (lbf)
-                    {
-                      if (EQ (str, lbf->filspc))
-                        return 1;       /* Already loaded */
-                      lbf = lbf->next;
-                    }
+                  if (is_module_loaded (filspc))
+                    return 1;
 
                   /* Add the embedded file to the list of files to be loaded in
                      the second pass.  That is performed latter by the function
@@ -306,16 +314,16 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
                     }
                   else
                     {
-                      lbf = lbfhead;
-                      while (lbf->next)
-                        {
-                          lbf = lbf->next;
-                        }
+                      struct lbfile *lbf;
+
+                      for (lbf = lbfhead; lbf->next; lbf = lbf->next)
+                        ;
+
                       lbf->next = lbfh;
                     }
 
                   lbfh->libspc = lbnh->libspc;
-                  lbfh->filspc = strdup (str);
+                  lbfh->filspc = strdup (filspc);
                   lbfh->relfil = strdup (ModName);
                   /* Library embedded file, so lbfh->offset must be >=0 */
                   lbfh->offset = IndexOffset + FileOffset;
@@ -332,7 +340,7 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
                   if (dflag && dfp)
                     {
                       if (LoadAdb (libfp))
-                        SaveLinkedFilePath (str);
+                        SaveLinkedFilePath (filspc);
                     }
                   return 1;     /* Found the symbol, so success! */
                 }
index 1935f360abb9f15224e6c1e38ccc70fbafb151ae..e14498d0548d5bc9db407f26f920c5af475fee8a 100644 (file)
@@ -46,7 +46,7 @@ LKLIB = $(srcdir)/..
 
 ASXXLIBSRC = strcmpi.c
 
-LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+LKLIBSRC = getline.c lkaomf51.c lkar.c lkdata.c lkeval.c \
            lkhead.c lklex.c lklib.c lklibr.c lklist.c \
            lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
index 481fc000d910de8160a58e7250c4a787e03bbcbd..4ac3540aa924cffae59f85ddd6ee717cd465c704 100644 (file)
@@ -96,6 +96,10 @@ SOURCE=..\lkaomf51.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkarea.c\r
 # End Source File\r
 # Begin Source File\r
@@ -188,6 +192,10 @@ SOURCE=..\getline.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.h\r
 # End Source File\r
 # Begin Source File\r
index dcb3202680f93331208cdd0fb4f340c314c4abb1..35374ec73f4b398938dcc62f5d6483077e6e049e 100644 (file)
@@ -13,7 +13,7 @@ ASXXLIBSRC = strcmpi.c
 
 LKLIB = $(srcdir)/..
 
-LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+LKLIBSRC = getline.c lkaomf51.c lkar.c lkdata.c lkeval.c \
            lkhead.c lklex.c lklib.c lklibr.c lklist.c \
            lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
index 3f82f08f40cc08bf580e8899ed3b43bca8093ef4..e762ed7800d69d8c6a7268ee952732ab59f6caeb 100644 (file)
@@ -97,6 +97,10 @@ SOURCE=..\lkaomf51.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkarea.c\r
 # End Source File\r
 # Begin Source File\r
@@ -193,6 +197,10 @@ SOURCE=..\getline.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.h\r
 # End Source File\r
 # Begin Source File\r
index 499e974cad8eafab03a9c86167d460fb12b6ca10..4f9e44bb8abd49c69887bffc1db9763b76e59c70 100644 (file)
@@ -97,6 +97,10 @@ SOURCE=..\lkaomf51.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkarea.c\r
 # End Source File\r
 # Begin Source File\r
@@ -193,6 +197,10 @@ SOURCE=..\getline.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkar.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.h\r
 # End Source File\r
 # Begin Source File\r
index 613a3b66a3f08431458c36a5c2089466c60a2ba1..d8f3cdf9878d95549c71a21aa1c124fc07852d46 100755 (executable)
--- a/configure
+++ b/configure
@@ -7681,7 +7681,7 @@ fi
 test $OPT_DISABLE_DEVICE_LIB = 0 && ac_config_files="$ac_config_files device/lib/Makefile"
 
 
-ac_config_files="$ac_config_files main.mk:main_in.mk src/Makefile device/include/Makefile support/librarian/Makefile support/makebin/Makefile support/regression/Makefile support/valdiag/Makefile Makefile Makefile.common:Makefile.common.in"
+ac_config_files="$ac_config_files main.mk:main_in.mk src/Makefile device/include/Makefile as/asranlib/Makefile support/librarian/Makefile support/makebin/Makefile support/regression/Makefile support/valdiag/Makefile Makefile Makefile.common:Makefile.common.in"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -8311,6 +8311,7 @@ do
     "main.mk") CONFIG_FILES="$CONFIG_FILES main.mk:main_in.mk" ;;
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "device/include/Makefile") CONFIG_FILES="$CONFIG_FILES device/include/Makefile" ;;
+    "as/asranlib/Makefile") CONFIG_FILES="$CONFIG_FILES as/asranlib/Makefile" ;;
     "support/librarian/Makefile") CONFIG_FILES="$CONFIG_FILES support/librarian/Makefile" ;;
     "support/makebin/Makefile") CONFIG_FILES="$CONFIG_FILES support/makebin/Makefile" ;;
     "support/regression/Makefile") CONFIG_FILES="$CONFIG_FILES support/regression/Makefile" ;;
index d7c6d33771f0fbc97e0c591ac6393a8b0c0f5332..0de9b1afa71e4082de9161391a522b1784f6deae 100644 (file)
@@ -767,6 +767,7 @@ test $OPT_DISABLE_DEVICE_LIB = 0 && AC_CONFIG_FILES([device/lib/Makefile])
 AC_CONFIG_FILES([main.mk:main_in.mk
 src/Makefile
 device/include/Makefile
+as/asranlib/Makefile
 support/librarian/Makefile
 support/makebin/Makefile
 support/regression/Makefile
index 3d5a6ad898309390cecad8b0ca85971bc32607d1..3f89a7ceef5654def26e4c851ed551809da60a52 100644 (file)
--- a/sdcc.dsw
+++ b/sdcc.dsw
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
 \r
 ###############################################################################\r
 \r
-Project: "all"=".\all.dsp" - Package Owner=<4>\r
+Project: "all"=.\all.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -51,7 +51,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "as_gbz80"=".\as\z80\as_gbz80.dsp" - Package Owner=<4>\r
+Project: "as_gbz80"=.\as\z80\as_gbz80.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -63,7 +63,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "as_hc08"=".\as\hc08\as_hc08.dsp" - Package Owner=<4>\r
+Project: "as_hc08"=.\as\hc08\as_hc08.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -75,7 +75,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "as_z80"=".\as\z80\as_z80.dsp" - Package Owner=<4>\r
+Project: "as_z80"=.\as\z80\as_z80.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -90,7 +90,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "aslink"=".\as\link\mcs51\aslink.dsp" - Package Owner=<4>\r
+Project: "aslink"=.\as\link\mcs51\aslink.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -105,7 +105,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "asx8051"=".\as\mcs51\asx8051.dsp" - Package Owner=<4>\r
+Project: "asranlib"=.\as\asranlib\asranlib.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -113,11 +113,26 @@ Package=<5>
 \r
 Package=<4>\r
 {{{\r
+    Begin Project Dependency\r
+    Project_Dep_Name config\r
+    End Project Dependency\r
 }}}\r
 \r
 ###############################################################################\r
 \r
-Project: "avr"=".\src\avr\avr.dsp" - Package Owner=<4>\r
+Project: "asx8051"=.\as\mcs51\asx8051.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "avr"=.\src\avr\avr.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -138,7 +153,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "avra"=".\src\avr\avra.dsp" - Package Owner=<4>\r
+Project: "avra"=.\src\avr\avra.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -150,7 +165,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "config"=".\config.dsp" - Package Owner=<4>\r
+Project: "config"=.\config.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -162,7 +177,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "ds390"=".\src\ds390\ds390.dsp" - Package Owner=<4>\r
+Project: "ds390"=.\src\ds390\ds390.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -183,7 +198,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "ds390a"=".\src\ds390\ds390a.dsp" - Package Owner=<4>\r
+Project: "ds390a"=.\src\ds390\ds390a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -195,7 +210,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "hc08"=".\src\hc08\hc08.dsp" - Package Owner=<4>\r
+Project: "hc08"=.\src\hc08\hc08.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -210,7 +225,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "hc08a"=".\src\hc08\hc08a.dsp" - Package Owner=<4>\r
+Project: "hc08a"=.\src\hc08\hc08a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -222,7 +237,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "librarian"=".\support\librarian\librarian.dsp" - Package Owner=<4>\r
+Project: "librarian"=.\support\librarian\librarian.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -234,7 +249,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "link_hc08"=".\as\link\hc08\link_hc08.dsp" - Package Owner=<4>\r
+Project: "link_hc08"=.\as\link\hc08\link_hc08.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -242,11 +257,14 @@ Package=<5>
 \r
 Package=<4>\r
 {{{\r
+    Begin Project Dependency\r
+    Project_Dep_Name config\r
+    End Project Dependency\r
 }}}\r
 \r
 ###############################################################################\r
 \r
-Project: "linkgbz80"=".\as\link\z80\linkgbz80.dsp" - Package Owner=<4>\r
+Project: "linkgbz80"=.\as\link\z80\linkgbz80.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -258,7 +276,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "linkz80"=".\as\link\z80\linkz80.dsp" - Package Owner=<4>\r
+Project: "linkz80"=.\as\link\z80\linkz80.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -270,7 +288,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "mcs51"=".\src\mcs51\mcs51.dsp" - Package Owner=<4>\r
+Project: "mcs51"=.\src\mcs51\mcs51.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -294,7 +312,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "mcs51a"=".\src\mcs51\mcs51a.dsp" - Package Owner=<4>\r
+Project: "mcs51a"=.\src\mcs51\mcs51a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -306,7 +324,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "packihx"=".\support\packihx\PackIhx.dsp" - Package Owner=<4>\r
+Project: "packihx"=.\support\packihx\PackIhx.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -318,7 +336,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "pic"=".\src\pic\pic.dsp" - Package Owner=<4>\r
+Project: "pic"=.\src\pic\pic.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -339,7 +357,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "pic16"=".\src\pic16\pic16.dsp" - Package Owner=<4>\r
+Project: "pic16"=.\src\pic16\pic16.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -354,7 +372,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "pic16a"=".\src\pic16\pic16a.dsp" - Package Owner=<4>\r
+Project: "pic16a"=.\src\pic16\pic16a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -366,7 +384,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "pica"=".\src\pic\pica.dsp" - Package Owner=<4>\r
+Project: "pica"=.\src\pic\pica.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -378,7 +396,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "sdcpp"=".\support\cpp\sdcpp.dsp" - Package Owner=<4>\r
+Project: "sdcpp"=.\support\cpp\sdcpp.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -393,7 +411,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "sdcppa"=".\support\cpp\sdcppa.dsp" - Package Owner=<4>\r
+Project: "sdcppa"=.\support\cpp\sdcppa.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -405,7 +423,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "src"=".\src\src.dsp" - Package Owner=<4>\r
+Project: "src"=.\src\src.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -447,7 +465,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "xa51"=".\src\xa51\xa51.dsp" - Package Owner=<4>\r
+Project: "xa51"=.\src\xa51\xa51.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -468,7 +486,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "xa51a"=".\src\xa51\xa51a.dsp" - Package Owner=<4>\r
+Project: "xa51a"=.\src\xa51\xa51a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -480,7 +498,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "yacc"=".\src\yacc.dsp" - Package Owner=<4>\r
+Project: "yacc"=.\src\yacc.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -492,7 +510,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "z80"=".\src\z80\z80.dsp" - Package Owner=<4>\r
+Project: "z80"=.\src\z80\z80.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r
@@ -513,7 +531,7 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
-Project: "z80a"=".\src\z80\z80a.dsp" - Package Owner=<4>\r
+Project: "z80a"=.\src\z80\z80a.dsp - Package Owner=<4>\r
 \r
 Package=<5>\r
 {{{\r