Changeset 918


Ignore:
Timestamp:
Jan 2, 2004, 3:47:31 AM (22 years ago)
Author:
bird
Message:

Added support for .dll's as libs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/ld/ld.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r917 r918  
    11/* ld.c -- changed for emx by Eberhard Mattes -- Sep 1998
     2           chagned for Innotek GCC by Andrew Zabolotny -- 2003
     3           chagned for Innotek GCC by knut st. osmundsen -- 2004
    24           changed for RSX by Rainer Schnitker -- Feb 1996 */
    35
     
    3638#include <sys/time.h>
    3739#include <sys/resource.h>
     40#endif
     41#ifdef __EMX__
     42#include <string.h>
    3843#endif
    3944
     
    892897void do_warnings ();
    893898void check_exe (void);
     899char *lx_to_aout (const char *pszFilename);
     900void cleanup (void);
    894901
    895902
     
    962969                                  * sizeof(struct glosym *));
    963970  *cmdline_references = 0;
     971
     972  /* Cleanup converted file on exit. */
     973
     974  atexit (cleanup);
    964975
    965976  /* Completely decode ARGV.  */
     
    12991310                --number_of_files;
    13001311                break;
     1312              }
     1313            else if (ext != NULL && stricmp (ext, ".dll") == 0
     1314                     && res_filename == NULL)
     1315              { /* convert .dll to temporary import library. */
     1316                p->filename = lx_to_aout (optarg);
     1317                p->local_sym_name = optarg;
     1318                p++;
     1319                break;
    13011320              }
    13021321          }
     
    53095328  return cplus_demangle (mangled, demangle_options);
    53105329}
     5330
     5331
     5332
     5333/**
     5334 * Generates an unique temporary file.
     5335 *
     5336 * @returns 0 on success.
     5337 * @returns -1 on failure.
     5338 * @param   pszFile     Where to put the filename.
     5339 * @param   pszPrefix   Prefix.
     5340 * @param   pszSuffix   Suffix.
     5341 * @remark  The code is nicked from the weak linker.
     5342 * @remark sorry about the convention here, this is borrowed from elsewhere.
     5343 */
     5344static int      make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix)
     5345{
     5346    struct stat     s;
     5347    unsigned        c = 0;
     5348    pid_t           pid = getpid();
     5349    const char *    pszTmp = getenv("TMP");
     5350    if (!pszTmp)    pszTmp = getenv("TMPDIR");
     5351    if (!pszTmp)    pszTmp = getenv("TEMP");
     5352    if (!pszTmp)    pszTmp = ".";
     5353
     5354    do
     5355    {
     5356        struct timeval  tv = {0,0};
     5357        if (c++ >= 200)
     5358            return -1;
     5359        gettimeofday(&tv, NULL);
     5360        sprintf(pszFile, "%s\\%s%x%lx%d%lx%s", pszTmp, pszPrefix, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix);
     5361    } while (!stat(pszFile, &s));
     5362
     5363    return 0;
     5364}
     5365
     5366/* list of converted libraries and objects which must be removed upon exit. */
     5367struct lx_tmp
     5368{
     5369    struct lx_tmp *next;
     5370    char *name;
     5371}   *conv_list = NULL;
     5372
     5373/** Converts a .DLL to an temporary import library.
     5374 * @remark sorry about the convention here, this is borrowed from elsewhere.
     5375 */
     5376char *lx_to_aout (const char *pszFilename)
     5377{
     5378    int             rc;
     5379    char *          pszNewFile;
     5380    struct lx_tmp  *pName;
     5381
     5382    /*
     5383     * Make temporary file.
     5384     */
     5385    pName = (struct lx_tmp *)xmalloc(sizeof(*pName));
     5386    pName->name = pszNewFile = xmalloc(_MAX_PATH);
     5387    if (make_tempfile(pszNewFile, "ldconv", ".a"))
     5388    {
     5389        free(pszNewFile);
     5390        return NULL;
     5391    }
     5392
     5393    /*
     5394     * Do the conversion.
     5395     */
     5396    rc = spawnlp(P_WAIT, "emximp.exe", "emximp.exe",
     5397                 "-o", pszNewFile, pszFilename, NULL);
     5398    if (!rc)
     5399    {
     5400        /* add to auto delete list for removal on exit(). */
     5401        pName->next = conv_list;
     5402        conv_list = pName;
     5403        return pName->name;
     5404
     5405    }
     5406    free(pszNewFile);
     5407    free(pName);
     5408
     5409    fprintf (stderr, "emxomfld: a.out to omf conversion failed for '%s'.\n",
     5410             pszFilename);
     5411    exit (2);
     5412    return NULL;
     5413}
     5414
     5415/* atexit worker */
     5416void cleanup (void)
     5417{
     5418  for (; conv_list; conv_list = conv_list->next)
     5419    unlink (conv_list->name);
     5420}
Note: See TracChangeset for help on using the changeset viewer.