4755 |
esac |
esac |
4756 |
case $host in |
case $host in |
4757 |
*cygwin* | *mingw* ) |
*cygwin* | *mingw* ) |
4758 |
cwrappersource=`$echo ${objdir}/lt-${outputname}.c` |
output_name=`basename $output` |
4759 |
cwrapper=`$echo ${output}.exe` |
output_path=`dirname $output` |
4760 |
$rm $cwrappersource $cwrapper |
cwrappersource="$output_path/$objdir/lt-$output_name.c" |
4761 |
trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 |
cwrapper="$output_path/$output_name.exe" |
4762 |
|
$rm $cwrappersource $cwrapper |
4763 |
|
trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 |
4764 |
|
|
4765 |
cat > $cwrappersource <<EOF |
cat > $cwrappersource <<EOF |
4766 |
|
|
4785 |
#include <malloc.h> |
#include <malloc.h> |
4786 |
#include <stdarg.h> |
#include <stdarg.h> |
4787 |
#include <assert.h> |
#include <assert.h> |
4788 |
|
#include <string.h> |
4789 |
|
#include <ctype.h> |
4790 |
|
#include <sys/stat.h> |
4791 |
|
|
4792 |
#if defined(PATH_MAX) |
#if defined(PATH_MAX) |
4793 |
# define LT_PATHMAX PATH_MAX |
# define LT_PATHMAX PATH_MAX |
4798 |
#endif |
#endif |
4799 |
|
|
4800 |
#ifndef DIR_SEPARATOR |
#ifndef DIR_SEPARATOR |
4801 |
#define DIR_SEPARATOR '/' |
# define DIR_SEPARATOR '/' |
4802 |
|
# define PATH_SEPARATOR ':' |
4803 |
#endif |
#endif |
4804 |
|
|
4805 |
#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ |
#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ |
4806 |
defined (__OS2__) |
defined (__OS2__) |
4807 |
#define HAVE_DOS_BASED_FILE_SYSTEM |
# define HAVE_DOS_BASED_FILE_SYSTEM |
4808 |
#ifndef DIR_SEPARATOR_2 |
# ifndef DIR_SEPARATOR_2 |
4809 |
#define DIR_SEPARATOR_2 '\\' |
# define DIR_SEPARATOR_2 '\\' |
4810 |
#endif |
# endif |
4811 |
|
# ifndef PATH_SEPARATOR_2 |
4812 |
|
# define PATH_SEPARATOR_2 ';' |
4813 |
|
# endif |
4814 |
#endif |
#endif |
4815 |
|
|
4816 |
#ifndef DIR_SEPARATOR_2 |
#ifndef DIR_SEPARATOR_2 |
4820 |
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) |
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) |
4821 |
#endif /* DIR_SEPARATOR_2 */ |
#endif /* DIR_SEPARATOR_2 */ |
4822 |
|
|
4823 |
|
#ifndef PATH_SEPARATOR_2 |
4824 |
|
# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) |
4825 |
|
#else /* PATH_SEPARATOR_2 */ |
4826 |
|
# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) |
4827 |
|
#endif /* PATH_SEPARATOR_2 */ |
4828 |
|
|
4829 |
#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) |
#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) |
4830 |
#define XFREE(stale) do { \ |
#define XFREE(stale) do { \ |
4831 |
if (stale) { free ((void *) stale); stale = 0; } \ |
if (stale) { free ((void *) stale); stale = 0; } \ |
4832 |
} while (0) |
} while (0) |
4833 |
|
|
4834 |
|
/* -DDEBUG is fairly common in CFLAGS. */ |
4835 |
|
#undef DEBUG |
4836 |
|
#if defined DEBUGWRAPPER |
4837 |
|
# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) |
4838 |
|
#else |
4839 |
|
# define DEBUG(format, ...) |
4840 |
|
#endif |
4841 |
|
|
4842 |
const char *program_name = NULL; |
const char *program_name = NULL; |
4843 |
|
|
4844 |
void * xmalloc (size_t num); |
void * xmalloc (size_t num); |
4845 |
char * xstrdup (const char *string); |
char * xstrdup (const char *string); |
4846 |
char * basename (const char *name); |
const char * base_name (const char *name); |
4847 |
char * fnqualify(const char *path); |
char * find_executable(const char *wrapper); |
4848 |
|
int check_executable(const char *path); |
4849 |
char * strendzap(char *str, const char *pat); |
char * strendzap(char *str, const char *pat); |
4850 |
void lt_fatal (const char *message, ...); |
void lt_fatal (const char *message, ...); |
4851 |
|
|
4855 |
char **newargz; |
char **newargz; |
4856 |
int i; |
int i; |
4857 |
|
|
4858 |
program_name = (char *) xstrdup ((char *) basename (argv[0])); |
program_name = (char *) xstrdup (base_name (argv[0])); |
4859 |
|
DEBUG("(main) argv[0] : %s\n",argv[0]); |
4860 |
|
DEBUG("(main) program_name : %s\n",program_name); |
4861 |
newargz = XMALLOC(char *, argc+2); |
newargz = XMALLOC(char *, argc+2); |
4862 |
EOF |
EOF |
4863 |
|
|
4864 |
cat >> $cwrappersource <<EOF |
cat >> $cwrappersource <<EOF |
4865 |
newargz[0] = "$SHELL"; |
newargz[0] = (char *) xstrdup("$SHELL"); |
4866 |
EOF |
EOF |
4867 |
|
|
4868 |
cat >> $cwrappersource <<"EOF" |
cat >> $cwrappersource <<"EOF" |
4869 |
newargz[1] = fnqualify(argv[0]); |
newargz[1] = find_executable(argv[0]); |
4870 |
|
if (newargz[1] == NULL) |
4871 |
|
lt_fatal("Couldn't find %s", argv[0]); |
4872 |
|
DEBUG("(main) found exe at : %s\n",newargz[1]); |
4873 |
/* we know the script has the same name, without the .exe */ |
/* we know the script has the same name, without the .exe */ |
4874 |
/* so make sure newargz[1] doesn't end in .exe */ |
/* so make sure newargz[1] doesn't end in .exe */ |
4875 |
strendzap(newargz[1],".exe"); |
strendzap(newargz[1],".exe"); |
4876 |
for (i = 1; i < argc; i++) |
for (i = 1; i < argc; i++) |
4877 |
newargz[i+1] = xstrdup(argv[i]); |
newargz[i+1] = xstrdup(argv[i]); |
4878 |
newargz[argc+1] = NULL; |
newargz[argc+1] = NULL; |
4879 |
|
|
4880 |
|
for (i=0; i<argc+1; i++) |
4881 |
|
{ |
4882 |
|
DEBUG("(main) newargz[%d] : %s\n",i,newargz[i]); |
4883 |
|
; |
4884 |
|
} |
4885 |
|
|
4886 |
EOF |
EOF |
4887 |
|
|
4888 |
cat >> $cwrappersource <<EOF |
case $host_os in |
4889 |
|
mingw*) |
4890 |
|
cat >> $cwrappersource <<EOF |
4891 |
|
execv("$SHELL",(char const **)newargz); |
4892 |
|
EOF |
4893 |
|
;; |
4894 |
|
*) |
4895 |
|
cat >> $cwrappersource <<EOF |
4896 |
execv("$SHELL",newargz); |
execv("$SHELL",newargz); |
4897 |
EOF |
EOF |
4898 |
|
;; |
4899 |
|
esac |
4900 |
|
|
4901 |
cat >> $cwrappersource <<"EOF" |
cat >> $cwrappersource <<"EOF" |
4902 |
return 127; |
return 127; |
4903 |
} |
} |
4904 |
|
|
4919 |
; |
; |
4920 |
} |
} |
4921 |
|
|
4922 |
char * |
const char * |
4923 |
basename (const char *name) |
base_name (const char *name) |
4924 |
{ |
{ |
4925 |
const char *base; |
const char *base; |
4926 |
|
|
4927 |
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) |
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) |
4928 |
/* Skip over the disk name in MSDOS pathnames. */ |
/* Skip over the disk name in MSDOS pathnames. */ |
4929 |
if (isalpha (name[0]) && name[1] == ':') |
if (isalpha ((unsigned char)name[0]) && name[1] == ':') |
4930 |
name += 2; |
name += 2; |
4931 |
#endif |
#endif |
4932 |
|
|
4933 |
for (base = name; *name; name++) |
for (base = name; *name; name++) |
4934 |
if (IS_DIR_SEPARATOR (*name)) |
if (IS_DIR_SEPARATOR (*name)) |
4935 |
base = name + 1; |
base = name + 1; |
4936 |
return (char *) base; |
return base; |
4937 |
} |
} |
4938 |
|
|
4939 |
|
int |
4940 |
|
check_executable(const char * path) |
4941 |
|
{ |
4942 |
|
struct stat st; |
4943 |
|
|
4944 |
|
DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!" |
4945 |
|
); |
4946 |
|
if ((!path) || (!*path)) |
4947 |
|
return 0; |
4948 |
|
|
4949 |
|
if ((stat (path, &st) >= 0) && |
4950 |
|
( |
4951 |
|
/* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ |
4952 |
|
#if defined (S_IXOTH) |
4953 |
|
((st.st_mode & S_IXOTH) == S_IXOTH) || |
4954 |
|
#endif |
4955 |
|
#if defined (S_IXGRP) |
4956 |
|
((st.st_mode & S_IXGRP) == S_IXGRP) || |
4957 |
|
#endif |
4958 |
|
((st.st_mode & S_IXUSR) == S_IXUSR)) |
4959 |
|
) |
4960 |
|
return 1; |
4961 |
|
else |
4962 |
|
return 0; |
4963 |
|
} |
4964 |
|
|
4965 |
|
/* Searches for the full path of the wrapper. Returns |
4966 |
|
newly allocated full path name if found, NULL otherwise */ |
4967 |
char * |
char * |
4968 |
fnqualify(const char *path) |
find_executable (const char* wrapper) |
4969 |
{ |
{ |
4970 |
size_t size; |
int has_slash = 0; |
4971 |
char *p; |
const char* p; |
4972 |
|
const char* p_next; |
4973 |
|
/* static buffer for getcwd */ |
4974 |
char tmp[LT_PATHMAX + 1]; |
char tmp[LT_PATHMAX + 1]; |
4975 |
|
int tmp_len; |
4976 |
|
char* concat_name; |
4977 |
|
|
4978 |
|
DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : |
4979 |
|
"NULL!"); |
4980 |
|
|
4981 |
assert(path != NULL); |
if ((wrapper == NULL) || (*wrapper == '\0')) |
4982 |
|
return NULL; |
4983 |
|
|
4984 |
/* Is it qualified already? */ |
/* Absolute path? */ |
4985 |
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) |
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) |
4986 |
if (isalpha (path[0]) && path[1] == ':') |
if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') |
4987 |
return xstrdup (path); |
{ |
4988 |
|
concat_name = xstrdup (wrapper); |
4989 |
|
if (check_executable(concat_name)) |
4990 |
|
return concat_name; |
4991 |
|
XFREE(concat_name); |
4992 |
|
} |
4993 |
|
else |
4994 |
|
{ |
4995 |
|
#endif |
4996 |
|
if (IS_DIR_SEPARATOR (wrapper[0])) |
4997 |
|
{ |
4998 |
|
concat_name = xstrdup (wrapper); |
4999 |
|
if (check_executable(concat_name)) |
5000 |
|
return concat_name; |
5001 |
|
XFREE(concat_name); |
5002 |
|
} |
5003 |
|
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) |
5004 |
|
} |
5005 |
#endif |
#endif |
|
if (IS_DIR_SEPARATOR (path[0])) |
|
|
return xstrdup (path); |
|
5006 |
|
|
5007 |
/* prepend the current directory */ |
for (p = wrapper; *p; p++) |
5008 |
/* doesn't handle '~' */ |
if (*p == '/') |
5009 |
|
{ |
5010 |
|
has_slash = 1; |
5011 |
|
break; |
5012 |
|
} |
5013 |
|
if (!has_slash) |
5014 |
|
{ |
5015 |
|
/* no slashes; search PATH */ |
5016 |
|
const char* path = getenv ("PATH"); |
5017 |
|
if (path != NULL) |
5018 |
|
{ |
5019 |
|
for (p = path; *p; p = p_next) |
5020 |
|
{ |
5021 |
|
const char* q; |
5022 |
|
size_t p_len; |
5023 |
|
for (q = p; *q; q++) |
5024 |
|
if (IS_PATH_SEPARATOR(*q)) |
5025 |
|
break; |
5026 |
|
p_len = q - p; |
5027 |
|
p_next = (*q == '\0' ? q : q + 1); |
5028 |
|
if (p_len == 0) |
5029 |
|
{ |
5030 |
|
/* empty path: current directory */ |
5031 |
|
if (getcwd (tmp, LT_PATHMAX) == NULL) |
5032 |
|
lt_fatal ("getcwd failed"); |
5033 |
|
tmp_len = strlen(tmp); |
5034 |
|
concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); |
5035 |
|
memcpy (concat_name, tmp, tmp_len); |
5036 |
|
concat_name[tmp_len] = '/'; |
5037 |
|
strcpy (concat_name + tmp_len + 1, wrapper); |
5038 |
|
} |
5039 |
|
else |
5040 |
|
{ |
5041 |
|
concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); |
5042 |
|
memcpy (concat_name, p, p_len); |
5043 |
|
concat_name[p_len] = '/'; |
5044 |
|
strcpy (concat_name + p_len + 1, wrapper); |
5045 |
|
} |
5046 |
|
if (check_executable(concat_name)) |
5047 |
|
return concat_name; |
5048 |
|
XFREE(concat_name); |
5049 |
|
} |
5050 |
|
} |
5051 |
|
/* not found in PATH; assume curdir */ |
5052 |
|
} |
5053 |
|
/* Relative path | not found in path: prepend cwd */ |
5054 |
if (getcwd (tmp, LT_PATHMAX) == NULL) |
if (getcwd (tmp, LT_PATHMAX) == NULL) |
5055 |
lt_fatal ("getcwd failed"); |
lt_fatal ("getcwd failed"); |
5056 |
size = strlen(tmp) + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */ |
tmp_len = strlen(tmp); |
5057 |
p = XMALLOC(char, size); |
concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); |
5058 |
sprintf(p, "%s%c%s", tmp, DIR_SEPARATOR, path); |
memcpy (concat_name, tmp, tmp_len); |
5059 |
return p; |
concat_name[tmp_len] = '/'; |
5060 |
|
strcpy (concat_name + tmp_len + 1, wrapper); |
5061 |
|
|
5062 |
|
if (check_executable(concat_name)) |
5063 |
|
return concat_name; |
5064 |
|
XFREE(concat_name); |
5065 |
|
return NULL; |
5066 |
} |
} |
5067 |
|
|
5068 |
char * |
char * |