2917
# end: func_emit_wrapper
2926
# end: func_emit_wrapper_part2
2929
# func_emit_wrapper [arg=no]
2931
# Emit a libtool wrapper script on stdout.
2932
# Don't directly open a file because we may want to
2933
# incorporate the script contents within a cygwin/mingw
2934
# wrapper executable. Must ONLY be called from within
2935
# func_mode_link because it depends on a number of variables
2938
# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
2939
# variable will take. If 'yes', then the emitted script
2940
# will assume that the directory in which it is stored is
2941
# the $objdir directory. This is a cygwin/mingw-specific
2943
func_emit_wrapper ()
2945
func_emit_wrapper_arg1=no
2946
if test -n "$1" ; then
2947
func_emit_wrapper_arg1=$1
2950
# split this up so that func_emit_cwrapperexe_src
2951
# can call each part independently.
2952
func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
2953
func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
2957
# func_to_host_path arg
2959
# Convert paths to host format when used with build tools.
2960
# Intended for use with "native" mingw (where libtool itself
2961
# is running under the msys shell), or in the following cross-
2962
# build environments:
2964
# mingw (msys) mingw [e.g. native]
2967
# where wine is equipped with the `winepath' executable.
2968
# In the native mingw case, the (msys) shell automatically
2969
# converts paths for any non-msys applications it launches,
2970
# but that facility isn't available from inside the cwrapper.
2971
# Similar accommodations are necessary for $host mingw and
2972
# $build cygwin. Calling this function does no harm for other
2973
# $host/$build combinations not listed above.
2975
# ARG is the path (on $build) that should be converted to
2976
# the proper representation for $host. The result is stored
2977
# in $func_to_host_path_result.
2978
func_to_host_path ()
2980
func_to_host_path_result="$1"
2981
if test -n "$1" ; then
2984
lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
2986
*mingw* ) # actually, msys
2987
# awkward: cmd appends spaces to result
2988
lt_sed_strip_trailing_spaces="s/[ ]*\$//"
2989
func_to_host_path_tmp1=`( cmd //c echo "$1" |\
2990
$SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
2991
func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
2992
$SED -e "$lt_sed_naive_backslashify"`
2995
func_to_host_path_tmp1=`cygpath -w "$1"`
2996
func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
2997
$SED -e "$lt_sed_naive_backslashify"`
3000
# Unfortunately, winepath does not exit with a non-zero
3001
# error code, so we are forced to check the contents of
3002
# stdout. On the other hand, if the command is not
3003
# found, the shell will set an exit code of 127 and print
3004
# *an error message* to stdout. So we must check for both
3005
# error code of zero AND non-empty stdout, which explains
3006
# the odd construction:
3007
func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
3008
if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
3009
func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
3010
$SED -e "$lt_sed_naive_backslashify"`
3012
# Allow warning below.
3013
func_to_host_path_result=""
3017
if test -z "$func_to_host_path_result" ; then
3018
func_error "Could not determine host path corresponding to"
3020
func_error "Continuing, but uninstalled executables may not work."
3022
func_to_host_path_result="$1"
3028
# end: func_to_host_path
3030
# func_to_host_pathlist arg
3032
# Convert pathlists to host format when used with build tools.
3033
# See func_to_host_path(), above. This function supports the
3034
# following $build/$host combinations (but does no harm for
3035
# combinations not listed here):
3037
# mingw (msys) mingw [e.g. native]
3041
# Path separators are also converted from $build format to
3042
# $host format. If ARG begins or ends with a path separator
3043
# character, it is preserved (but converted to $host format)
3046
# ARG is a pathlist (on $build) that should be converted to
3047
# the proper representation on $host. The result is stored
3048
# in $func_to_host_pathlist_result.
3049
func_to_host_pathlist ()
3051
func_to_host_pathlist_result="$1"
3052
if test -n "$1" ; then
3055
lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3056
# Remove leading and trailing path separator characters from
3057
# ARG. msys behavior is inconsistent here, cygpath turns them
3058
# into '.;' and ';.', and winepath ignores them completely.
3059
func_to_host_pathlist_tmp2="$1"
3060
# Once set for this call, this variable should not be
3061
# reassigned. It is used in tha fallback case.
3062
func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
3063
$SED -e 's|^:*||' -e 's|:*$||'`
3065
*mingw* ) # Actually, msys.
3066
# Awkward: cmd appends spaces to result.
3067
lt_sed_strip_trailing_spaces="s/[ ]*\$//"
3068
func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
3069
$SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
3070
func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
3071
$SED -e "$lt_sed_naive_backslashify"`
3074
func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
3075
func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
3076
$SED -e "$lt_sed_naive_backslashify"`
3079
# unfortunately, winepath doesn't convert pathlists
3080
func_to_host_pathlist_result=""
3081
func_to_host_pathlist_oldIFS=$IFS
3083
for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
3084
IFS=$func_to_host_pathlist_oldIFS
3085
if test -n "$func_to_host_pathlist_f" ; then
3086
func_to_host_path "$func_to_host_pathlist_f"
3087
if test -n "$func_to_host_path_result" ; then
3088
if test -z "$func_to_host_pathlist_result" ; then
3089
func_to_host_pathlist_result="$func_to_host_path_result"
3091
func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
3097
IFS=$func_to_host_pathlist_oldIFS
3100
if test -z "$func_to_host_pathlist_result" ; then
3101
func_error "Could not determine the host path(s) corresponding to"
3103
func_error "Continuing, but uninstalled executables may not work."
3104
# Fallback. This may break if $1 contains DOS-style drive
3105
# specifications. The fix is not to complicate the expression
3106
# below, but for the user to provide a working wine installation
3107
# with winepath so that path translation in the cross-to-mingw
3108
# case works properly.
3109
lt_replace_pathsep_nix_to_dos="s|:|;|g"
3110
func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
3111
$SED -e "$lt_replace_pathsep_nix_to_dos"`
3113
# Now, add the leading and trailing path separators back
3115
:* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
3119
*: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
3126
# end: func_to_host_pathlist
2919
3128
# func_emit_cwrapperexe_src
2920
3129
# emit the source code for a wrapper executable on stdout
3057
3272
int check_executable (const char *path);
3058
3273
char *strendzap (char *str, const char *pat);
3059
3274
void lt_fatal (const char *message, ...);
3061
static const char *script_text =
3064
func_emit_wrapper yes |
3275
void lt_setenv (const char *name, const char *value);
3276
char *lt_extend_str (const char *orig_value, const char *add, int to_end);
3277
void lt_opt_process_env_set (const char *arg);
3278
void lt_opt_process_env_prepend (const char *arg);
3279
void lt_opt_process_env_append (const char *arg);
3280
int lt_split_name_value (const char *arg, char** name, char** value);
3281
void lt_update_exe_path (const char *name, const char *value);
3282
void lt_update_lib_path (const char *name, const char *value);
3284
static const char *script_text_part1 =
3287
func_emit_wrapper_part1 yes |
3288
$SED -e 's/\([\\"]\)/\\\1/g' \
3289
-e 's/^/ "/' -e 's/$/\\n"/'
3293
static const char *script_text_part2 =
3295
func_emit_wrapper_part2 yes |
3065
3296
$SED -e 's/\([\\"]\)/\\\1/g' \
3066
3297
-e 's/^/ "/' -e 's/$/\\n"/'
3070
3301
const char * MAGIC_EXE = "$magic_exe";
3302
const char * LIB_PATH_VARNAME = "$shlibpath_var";
3305
if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
3306
func_to_host_pathlist "$temp_rpath"
3308
const char * LIB_PATH_VALUE = "$func_to_host_pathlist_result";
3312
const char * LIB_PATH_VALUE = "";
3316
if test -n "$dllsearchpath"; then
3317
func_to_host_pathlist "$dllsearchpath:"
3319
const char * EXE_PATH_VARNAME = "PATH";
3320
const char * EXE_PATH_VALUE = "$func_to_host_pathlist_result";
3324
const char * EXE_PATH_VARNAME = "";
3325
const char * EXE_PATH_VALUE = "";
3329
if test "$fast_install" = yes; then
3331
const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
3335
const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
3342
#define LTWRAPPER_OPTION_PREFIX "--lt-"
3343
#define LTWRAPPER_OPTION_PREFIX_LENGTH 5
3345
static const size_t opt_prefix_len = LTWRAPPER_OPTION_PREFIX_LENGTH;
3346
static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
3348
static const char *dumpscript_opt = LTWRAPPER_OPTION_PREFIX "dump-script";
3350
static const size_t env_set_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
3351
static const char *env_set_opt = LTWRAPPER_OPTION_PREFIX "env-set";
3352
/* argument is putenv-style "foo=bar", value of foo is set to bar */
3354
static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
3355
static const char *env_prepend_opt = LTWRAPPER_OPTION_PREFIX "env-prepend";
3356
/* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
3358
static const size_t env_append_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
3359
static const char *env_append_opt = LTWRAPPER_OPTION_PREFIX "env-append";
3360
/* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
3073
3363
main (int argc, char *argv[])
3075
3365
char **newargz;
3076
3367
char *tmp_pathspec;
3077
3368
char *actual_cwrapper_path;
3078
char *shwrapper_name;
3369
char *actual_cwrapper_name;
3079
3372
intptr_t rval = 127;
3082
const char *dumpscript_opt = "--lt-dump-script";
3085
3376
program_name = (char *) xstrdup (base_name (argv[0]));
3142
3409
actual_cwrapper_path));
3143
3410
XFREE (tmp_pathspec);
3145
shwrapper_name = (char *) xstrdup (base_name (actual_cwrapper_path));
3146
strendzap (actual_cwrapper_path, shwrapper_name);
3148
/* shwrapper_name transforms */
3149
strendzap (shwrapper_name, ".exe");
3150
tmp_pathspec = XMALLOC (char, (strlen (shwrapper_name) +
3151
strlen ("_ltshwrapperTMP") + 1));
3152
strcpy (tmp_pathspec, shwrapper_name);
3153
strcat (tmp_pathspec, "_ltshwrapperTMP");
3154
XFREE (shwrapper_name);
3155
shwrapper_name = tmp_pathspec;
3157
LTWRAPPER_DEBUGPRINTF (("(main) libtool shell wrapper name: %s\n",
3412
actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
3413
strendzap (actual_cwrapper_path, actual_cwrapper_name);
3415
/* wrapper name transforms */
3416
strendzap (actual_cwrapper_name, ".exe");
3417
tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
3418
XFREE (actual_cwrapper_name);
3419
actual_cwrapper_name = tmp_pathspec;
3422
/* target_name transforms -- use actual target program name; might have lt- prefix */
3423
target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
3424
strendzap (target_name, ".exe");
3425
tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
3426
XFREE (target_name);
3427
target_name = tmp_pathspec;
3430
LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
3163
3436
XMALLOC (char, (strlen (actual_cwrapper_path) +
3164
strlen ("$objdir") + 1 + strlen (shwrapper_name) + 1));
3165
strcpy (newargz[1], actual_cwrapper_path);
3166
strcat (newargz[1], "$objdir");
3167
strcat (newargz[1], "/");
3168
strcat (newargz[1], shwrapper_name);
3437
strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
3438
strcpy (newargz[0], actual_cwrapper_path);
3439
strcat (newargz[0], "$objdir");
3440
strcat (newargz[0], "/");
3444
/* stop here, and copy so we don't have to do this twice */
3445
tmp_pathspec = xstrdup (newargz[0]);
3447
/* do NOT want the lt- prefix here, so use actual_cwrapper_name */
3448
strcat (newargz[0], actual_cwrapper_name);
3450
/* DO want the lt- prefix here if it exists, so use target_name */
3451
lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
3452
XFREE (tmp_pathspec);
3453
tmp_pathspec = NULL;
3172
3456
case $host_os in
3177
while ((p = strchr (newargz[1], '\\')) != NULL)
3461
while ((p = strchr (newargz[0], '\\')) != NULL)
3465
while ((p = strchr (lt_argv_zero, '\\')) != NULL)
3187
XFREE (shwrapper_name);
3475
XFREE (target_name);
3188
3476
XFREE (actual_cwrapper_path);
3190
/* always write in binary mode */
3191
if ((shwrapper = fopen (newargz[1], FOPEN_WB)) == 0)
3193
lt_fatal ("Could not open %s for writing", newargz[1]);
3195
fprintf (shwrapper, "%s", script_text);
3198
make_executable (newargz[1]);
3477
XFREE (actual_cwrapper_name);
3479
lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
3480
lt_setenv ("DUALCASE", "1"); /* for MSK sh */
3481
lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
3482
lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
3200
3485
for (i = 1; i < argc; i++)
3201
newargz[i + 1] = xstrdup (argv[i]);
3202
newargz[argc + 1] = NULL;
3487
if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
3489
if (argv[i][env_set_opt_len] == '=')
3491
const char *p = argv[i] + env_set_opt_len + 1;
3492
lt_opt_process_env_set (p);
3494
else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
3496
lt_opt_process_env_set (argv[++i]); /* don't copy */
3499
lt_fatal ("%s missing required argument", env_set_opt);
3502
if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
3504
if (argv[i][env_prepend_opt_len] == '=')
3506
const char *p = argv[i] + env_prepend_opt_len + 1;
3507
lt_opt_process_env_prepend (p);
3509
else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
3511
lt_opt_process_env_prepend (argv[++i]); /* don't copy */
3514
lt_fatal ("%s missing required argument", env_prepend_opt);
3517
if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
3519
if (argv[i][env_append_opt_len] == '=')
3521
const char *p = argv[i] + env_append_opt_len + 1;
3522
lt_opt_process_env_append (p);
3524
else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
3526
lt_opt_process_env_append (argv[++i]); /* don't copy */
3529
lt_fatal ("%s missing required argument", env_append_opt);
3532
if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
3534
/* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
3535
namespace, but it is not one of the ones we know about and
3536
have already dealt with, above (inluding dump-script), then
3537
report an error. Otherwise, targets might begin to believe
3538
they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
3539
namespace. The first time any user complains about this, we'll
3540
need to make LTWRAPPER_OPTION_PREFIX a configure-time option
3541
or a configure.ac-settable value.
3543
lt_fatal ("Unrecognized option in %s namespace: '%s'",
3544
ltwrapper_option_prefix, argv[i]);
3547
newargz[++newargc] = xstrdup (argv[i]);
3549
newargz[++newargc] = NULL;
3204
for (i = 0; i < argc + 1; i++)
3551
LTWRAPPER_DEBUGPRINTF (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
3552
for (i = 0; i < newargc; i++)
3206
LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d] : %s\n", i, newargz[i]));
3554
LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d] : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
3211
3559
case $host_os in
3214
3562
/* execv doesn't actually work on mingw as expected on unix */
3215
rval = _spawnv (_P_WAIT, "$lt_newargv0", (const char * const *) newargz);
3563
rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
3216
3564
if (rval == -1)
3218
3566
/* failed to start process */
3219
LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"$lt_newargv0\": errno = %d\n", errno));
3567
LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
3228
execv ("$lt_newargv0", newargz);
3575
execv (lt_argv_zero, newargz);
3229
3576
return rval; /* =127, but avoids unused variable warning */
3238
3585
xmalloc (size_t num)
3506
3853
lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
3858
lt_setenv (const char *name, const char *value)
3860
LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
3861
(name ? name : "<NULL>"),
3862
(value ? value : "<NULL>")));
3865
/* always make a copy, for consistency with !HAVE_SETENV */
3866
char *str = xstrdup (value);
3867
setenv (name, str, 1);
3869
int len = strlen (name) + 1 + strlen (value) + 1;
3870
char *str = XMALLOC (char, len);
3871
sprintf (str, "%s=%s", name, value);
3872
if (putenv (str) != EXIT_SUCCESS)
3881
lt_extend_str (const char *orig_value, const char *add, int to_end)
3884
if (orig_value && *orig_value)
3886
int orig_value_len = strlen (orig_value);
3887
int add_len = strlen (add);
3888
new_value = XMALLOC (char, add_len + orig_value_len + 1);
3891
strcpy (new_value, orig_value);
3892
strcpy (new_value + orig_value_len, add);
3896
strcpy (new_value, add);
3897
strcpy (new_value + add_len, orig_value);
3902
new_value = xstrdup (add);
3908
lt_split_name_value (const char *arg, char** name, char** value)
3915
p = strchr (arg, (int)'=');
3920
*value = xstrdup (++p);
3922
len = strlen (arg) - strlen (*value);
3923
*name = XMALLOC (char, len);
3924
strncpy (*name, arg, len-1);
3925
(*name)[len - 1] = '\0';
3931
lt_opt_process_env_set (const char *arg)
3936
if (lt_split_name_value (arg, &name, &value) != 0)
3940
lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
3943
lt_setenv (name, value);
3949
lt_opt_process_env_prepend (const char *arg)
3953
char *new_value = NULL;
3955
if (lt_split_name_value (arg, &name, &value) != 0)
3959
lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
3962
new_value = lt_extend_str (getenv (name), value, 0);
3963
lt_setenv (name, new_value);
3970
lt_opt_process_env_append (const char *arg)
3974
char *new_value = NULL;
3976
if (lt_split_name_value (arg, &name, &value) != 0)
3980
lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
3983
new_value = lt_extend_str (getenv (name), value, 1);
3984
lt_setenv (name, new_value);
3991
lt_update_exe_path (const char *name, const char *value)
3993
LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
3994
(name ? name : "<NULL>"),
3995
(value ? value : "<NULL>")));
3997
if (name && *name && value && *value)
3999
char *new_value = lt_extend_str (getenv (name), value, 0);
4000
/* some systems can't cope with a ':'-terminated path #' */
4001
int len = strlen (new_value);
4002
while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
4004
new_value[len-1] = '\0';
4006
lt_setenv (name, new_value);
4012
lt_update_lib_path (const char *name, const char *value)
4014
LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
4015
(name ? name : "<NULL>"),
4016
(value ? value : "<NULL>")));
4018
if (name && *name && value && *value)
4020
char *new_value = lt_extend_str (getenv (name), value, 0);
4021
lt_setenv (name, new_value);
3511
4029
# end: func_emit_cwrapperexe_src