* ltmain.in: add code for a binary wrapper

to use with uninstalled executables on cygwin/mingw.
Make sure that --mode=clean gets shell wrapper and
binary wrapper.  When sourcing the shell wrapper,
invoke using a terminal `.' on cygwin/mingw to
avoid the automatic append-.exe behavior.
This commit is contained in:
Charles Wilson 2003-01-29 04:53:18 +00:00 committed by Robert Boehne
parent 1f2222e418
commit 6ab1e4099d
2 changed files with 264 additions and 12 deletions

View File

@ -1,3 +1,12 @@
2003-01-28 Charles Wilson <cwilson@ece.gatech.edu>
* ltmain.in: add code for a binary wrapper
to use with uninstalled executables on cygwin/mingw.
Make sure that --mode=clean gets shell wrapper and
binary wrapper. When sourcing the shell wrapper,
invoke using a terminal `.' on cygwin/mingw to
avoid the automatic append-.exe behavior.
2003-01-28 Albert Chin-A-Young <china@thewrittenword.com>
* libtool.m4: Hardcode library paths into libraries on IRIX.

267
ltmain.in
View File

@ -4343,6 +4343,219 @@ static const void *lt_preloaded_setup() {
outputname=`echo $outputname|${SED} 's,.exe$,,'` ;;
*) exeext= ;;
esac
case $host in
*cygwin* | *mingw* )
cwrappersource=`echo ${objdir}/lt-${output}.c`
cwrapper=`echo ${output}.exe`
$rm $cwrappersource $cwrapper
trap "$rm $cwrappersource $cwrapper; exit 1" 1 2 15
cat > $cwrappersource <<EOF
/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
The $output program cannot be directly executed until all the libtool
libraries that it depends on are installed.
This wrapper executable should never be moved out of the build directory.
If it is, it will not operate correctly.
Currently, it simply execs the wrapper *script* "/bin/sh $output",
but could eventually absorb all of the scripts functionality and
exec $objdir/$outputname directly.
*/
EOF
cat >> $cwrappersource<<"EOF"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <stdarg.h>
#include <assert.h>
#if defined(PATH_MAX)
# define LT_PATHMAX PATH_MAX
#elif defined(MAXPATHLEN)
# define LT_PATHMAX MAXPATHLEN
#else
# define LT_PATHMAX 1024
#endif
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
defined (__OS2__)
#define HAVE_DOS_BASED_FILE_SYSTEM
#ifndef DIR_SEPARATOR_2
#define DIR_SEPARATOR_2 '\\'
#endif
#endif
#ifndef DIR_SEPARATOR_2
# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
#else /* DIR_SEPARATOR_2 */
# define IS_DIR_SEPARATOR(ch) \
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
#endif /* DIR_SEPARATOR_2 */
#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type)))
#define XFREE(stale) do { \
if (stale) { free ((void *) stale); stale = 0; } \
} while (0)
const char *program_name = NULL;
void * xmalloc (size_t num);
char * xstrdup (const char *string);
char * basename (const char *name);
char * fnqualify(const char *path);
char * strendzap(char *str, const char *pat);
void lt_fatal (const char *message, ...);
int
main (int argc, char *argv[])
{
char **newargz;
int i;
program_name = (char *) xstrdup ((char *) basename (argv[0]));
newargz = XMALLOC(char *, argc+2);
EOF
cat >> $cwrappersource <<EOF
newargz[0] = "$SHELL";
EOF
cat >> $cwrappersource <<"EOF"
newargz[1] = fnqualify(argv[0]);
/* we know the script has the same name, without the .exe */
/* so make sure newargz[1] doesn't end in .exe */
strendzap(newargz[1],".exe");
for (i = 1; i < argc; i++)
newargz[i+1] = xstrdup(argv[i]);
newargz[argc+1] = NULL;
EOF
cat >> $cwrappersource <<EOF
execv("$SHELL",newargz);
EOF
cat >> $cwrappersource <<"EOF"
}
void *
xmalloc (size_t num)
{
void * p = (void *) malloc (num);
if (!p)
lt_fatal ("Memory exhausted");
return p;
}
char *
xstrdup (const char *string)
{
return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL
;
}
char *
basename (const char *name)
{
const char *base;
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over the disk name in MSDOS pathnames. */
if (isalpha (name[0]) && name[1] == ':')
name += 2;
#endif
for (base = name; *name; name++)
if (IS_DIR_SEPARATOR (*name))
base = name + 1;
return (char *) base;
}
char *
fnqualify(const char *path)
{
size_t size;
char *p;
char tmp[LT_PATHMAX + 1];
assert(path != NULL);
/* Is it qualified already? */
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
if (isalpha (path[0]) && path[1] == ':')
return xstrdup (path);
#endif
if (IS_DIR_SEPARATOR (path[0]))
return xstrdup (path);
/* prepend the current directory */
/* doesn't handle '~' */
if (getcwd (tmp, LT_PATHMAX) == NULL)
lt_fatal ("getcwd failed");
size = strlen(tmp) + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */
p = XMALLOC(char, size);
sprintf(p, "%s%c%s", tmp, DIR_SEPARATOR, path);
return p;
}
char *
strendzap(char *str, const char *pat)
{
size_t len, patlen;
assert(str != NULL);
assert(pat != NULL);
len = strlen(str);
patlen = strlen(pat);
if (patlen <= len)
{
str += len - patlen;
if (strcmp(str, pat) == 0)
*str = '\0';
}
return str;
}
static void
lt_error_core (int exit_status, const char * mode,
const char * message, va_list ap)
{
fprintf (stderr, "%s: %s: ", program_name, mode);
vfprintf (stderr, message, ap);
fprintf (stderr, ".\n");
if (exit_status >= 0)
exit (exit_status);
}
void
lt_fatal (const char *message, ...)
{
va_list ap;
va_start (ap, message);
lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
va_end (ap);
}
EOF
# we should really use a build-platform specific compiler
# here, but OTOH, the wrappers (shell script and this C one)
# are only useful if you want to execute the "real" binary.
# Since the "real" binary is built for $host, then this
# wrapper might as well be built for $host, too.
$run $LTCC -s -o $cwrapper $cwrappersource
;;
esac
$rm $output
trap "$rm $output; exit 1" 1 2 15
@ -5153,10 +5366,17 @@ relink_command=\"$relink_command\""
notinst_deplibs=
relink_command=
# To insure that "foo" is sourced, and not "foo.exe",
# finese the cygwin/MSYS system by explicitly sourcing "foo."
# which disallows the automatic-append-.exe behavior.
case $host in
*cygwin* | *mingw*) wrapperdot=${wrapper}. ;;
*) wrapperdot=${wrapper} ;;
esac
# If there is no directory component, then add one.
case $file in
*/* | *\\*) . $wrapper ;;
*) . ./$wrapper ;;
*/* | *\\*) . ${wrapperdot} ;;
*) . ./${wrapperdot} ;;
esac
# Check the variables that should have been set.
@ -5184,10 +5404,17 @@ relink_command=\"$relink_command\""
done
relink_command=
# To insure that "foo" is sourced, and not "foo.exe",
# finese the cygwin/MSYS system by explicitly sourcing "foo."
# which disallows the automatic-append-.exe behavior.
case $host in
*cygwin* | *mingw*) wrapperdot=${wrapper}. ;;
*) wrapperdot=${wrapper} ;;
esac
# If there is no directory component, then add one.
case $file in
*/* | *\\*) . $file ;;
*) . ./$file ;;
*/* | *\\*) . ${wrapperdot} ;;
*) . ./${wrapperdot} ;;
esac
outputname=
@ -5630,15 +5857,31 @@ relink_command=\"$relink_command\""
;;
*)
# Do a test to see if this is a libtool program.
if test "$mode" = clean &&
(${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
relink_command=
. $dir/$file
if test "$mode" = clean ; then
noexename=$name
case $file in
*.exe)
file=`echo $file|${SED} 's,.exe$,,'`
noexename=`echo $name|${SED} 's,.exe$,,'`
# $file with .exe has already been added to rmfiles,
# add $file without .exe
rmfiles="$rmfiles $file"
;;
esac
# Do a test to see if this is a libtool program.
if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
relink_command=
. $dir/$file
rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
if test "$fast_install" = yes && test -n "$relink_command"; then
rmfiles="$rmfiles $objdir/lt-$name"
# note $name still contains .exe if it was in $file originally
# as does the version of $file that was added into $rmfiles
rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
if test "$fast_install" = yes && test -n "$relink_command"; then
rmfiles="$rmfiles $objdir/lt-$name"
fi
if test "X$noexename" != "X$name" ; then
rmfiles="$rmfiles $objdir/lt-${noexename}.c"
fi
fi
fi
;;