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


_______________________________________________
http://lists.gnu.org/mailman/listinfo/libtool

Reply via email to