libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multipurpose binaries with different names


From: Paolo Bonzini
Subject: Re: Multipurpose binaries with different names
Date: Wed, 29 Jul 2009 01:07:29 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2

On 07/24/2009 11:25 AM, Jan Engelhardt wrote:
Hi,


when one has a program that does something like

   if(strcmp(argv[0], "gunzip") == 0)
     uncompress();
   else
     compress();

and this program also uses a libtool library, then the - lets use this
example - just-built "gzip" file will be around 4 kilobytes only, it is
a libtool wrapper scripts for .libs/gzip. "gunzip" would then be a
symlink to "gzip", but calling gunzip results in the libtool script
calling gzip instead, thereby leading to the wrong mode of operation.

This makes it hard to run libtooled programs from within the compilation
directory. A possible workaround is that the libtool wrapper script
honors $0 a little more:

Since anyway you have to use install-programs-hook to create the multipurpose binary, you can add another name (e.g. gztool) and invoke it like "gztool gzip" or "gztool gunzip" while uninstalled:

#ifdef _WIN32
  executable_name = strrchr (argv[0], '\\');
  if (!executable_name || strchr (executable_name, '/'))
    executable_name = strrchr (argv[0], '/');
#else
  executable_name = strrchr (argv[0], '/');
#endif /* _WIN32 */

  if (executable_name)
    executable_name++;
  else
    executable_name = argv[0];

  if (!strcasecmp (executable_name, "gztool" EXEEXT)
      || (EXEEXT[0] && !strcasecmp (executable_name, "gztool")
      || !strcasecmp (executable_name, "lt-gztool" EXEEXT)
      || (EXEEXT[0] && !strcasecmp (executable_name, "lt-gztool")))
    {
      program_name = strdup (argv[1]);
      argv++, argc--;
    }
  else
    {
      int n = strlen (executable_name);
      program_name = strdup (executable_name);

      /* Strip the executable extension if needed.  */
      if (EXEEXT[0]
          && n > strlen (EXEEXT)
          && !strcasecmp (program_name + n - strlen (EXEEXT), EXEEXT))
        program_name[n - strlen (EXEEXT)] = 0;
    }

  if (strcmp (program_name, "gzip"))
    exit (compress ());
  else
    exit (uncompress ());

Make gztool noinst_PROGRAMS and you're done.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]