173
175
# Shell function definitions:
174
176
# This seems to be the best place for them
178
# func_mktempdir [string]
179
# Make a temporary directory that won't clash with other running
180
# libtool processes, and avoids race conditions if possible. If
181
# given, STRING is the basename for that directory.
184
my_template="${TMPDIR-/tmp}/${1-$progname}"
186
if test "$run" = ":"; then
187
# Return a directory name, but don't create it in dry-run mode
188
my_tmpdir="${my_template}-$$"
191
# If mktemp works, use that first and foremost
192
my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
194
if test ! -d "$my_tmpdir"; then
195
# Failing that, at least try and use $RANDOM to avoid a race
196
my_tmpdir="${my_template}-${RANDOM-0}$$"
198
save_mktempdir_umask=`umask`
201
umask $save_mktempdir_umask
204
# If we're not in dry-run mode, bomb out on failure
205
test -d "$my_tmpdir" || {
206
$echo "cannot create temporary directory \`$my_tmpdir'" 1>&2
211
$echo "X$my_tmpdir" | $Xsed
176
215
# func_win32_libid arg
177
216
# return the library type of file 'arg'
191
230
if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \
192
231
$EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
193
232
win32_nmres=`eval $NM -f posix -A $1 | \
194
sed -n -e '1,100{/ I /{x;/import/!{s/^/import/;h;p;};x;};}'`
195
if test "X$win32_nmres" = "Ximport" ; then
196
win32_libid_type="x86 archive import"
198
win32_libid_type="x86 archive static"
233
$SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'`
235
import*) win32_libid_type="x86 archive import";;
236
*) win32_libid_type="x86 archive static";;
782
842
qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"`
784
*$quote_scanset* | *]* | *\|* | *\&* | *\(* | *\)* | "")
844
*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
785
845
qlibobj="\"$qlibobj\"" ;;
787
if test "X$libobj" != "X$qlibobj"; then
788
$echo "$modename: libobj name \`$libobj' may not contain shell special characters."
847
test "X$libobj" != "X$qlibobj" \
848
&& $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \
849
&& $echo "$modename: libobj name \`$libobj' may not contain shell special characters."
791
850
objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
792
851
xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
793
852
if test "X$xdir" = "X$obj"; then
1581
1666
# +DA*, +DD* enable 64-bit mode on the HP compiler
1582
1667
# -q* pass through compiler args for the IBM compiler
1583
1668
# -m* pass through architecture-specific compiler args for GCC
1584
-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*)
1669
# -m*, -t[45]*, -txscale* pass through architecture-specific
1670
# compiler args for GCC
1671
# -pg pass through profiling flag for GCC
1672
# @file GCC response files
1673
-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \
1674
-t[45]*|-txscale*|@*)
1586
1676
# Unknown arguments in both finalize_command and compile_command need
1587
1677
# to be aesthetically quoted because they are evaled later.
1588
1678
arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
1590
*$quote_scanset* | *]* | *\|* | *\&* | *\(* | *\)* | "")
1680
*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
1594
1684
compile_command="$compile_command $arg"
1595
1685
finalize_command="$finalize_command $arg"
1596
if test "$with_gcc" = "yes" ; then
1597
compiler_flags="$compiler_flags $arg"
1686
compiler_flags="$compiler_flags $arg"
2609
2700
if test "$hardcode_direct" = no; then
2610
2701
add="$dir/$linklib"
2612
*-*-sco3.2v5* ) add_dir="-L$dir" ;;
2703
*-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
2704
*-*-sysv4*uw2*) add_dir="-L$dir" ;;
2705
*-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
2706
*-*-unixware7*) add_dir="-L$dir" ;;
2614
2708
# if the lib is a module then we can not link against
2615
2709
# it, someone is ignoring the new warnings I added
2616
if /usr/bin/file -L $add 2> /dev/null | $EGREP "bundle" >/dev/null ; then
2710
if /usr/bin/file -L $add 2> /dev/null |
2711
$EGREP ": [^:]* bundle" >/dev/null ; then
2617
2712
$echo "** Warning, lib $linklib is a module, not a shared library"
2618
2713
if test -z "$old_library" ; then
4410
# move library search paths that coincide with paths to not yet
4411
# installed libraries to the beginning of the library search list
4413
for path in $notinst_path; do
4414
case " $new_libs " in
4415
*" -L$path/$objdir "*) ;;
4417
case " $compile_deplibs " in
4418
*" -L$path/$objdir "*)
4419
new_libs="$new_libs -L$path/$objdir" ;;
4424
for deplib in $compile_deplibs; do
4427
case " $new_libs " in
4429
*) new_libs="$new_libs $deplib" ;;
4432
*) new_libs="$new_libs $deplib" ;;
4435
compile_deplibs="$new_libs"
4260
4438
compile_command="$compile_command $compile_deplibs"
4261
4439
finalize_command="$finalize_command $finalize_deplibs"
4420
4603
if test -z "$export_symbols"; then
4421
4604
export_symbols="$output_objdir/$outputname.exp"
4422
4605
$run $rm $export_symbols
4423
$run eval "${SED} -n -e '/^: @PROGRAM@$/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4606
$run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4608
*cygwin* | *mingw* )
4609
$run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4610
$run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4425
$run eval "${SED} -e 's/\([ ][.*^$]\)/\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4614
$run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4426
4615
$run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4427
4616
$run eval 'mv "$nlist"T "$nlist"'
4618
*cygwin* | *mingw* )
4619
$run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4620
$run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4543
4738
# Now compile the dynamic symbol file.
4544
$show "(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")"
4545
$run eval '(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $?
4739
$show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")"
4740
$run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $?
4547
4742
# Clean up the generated files.
4548
4743
$show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T"
4549
4744
$run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T"
4551
4746
# Transform the symbol file into the correct name.
4552
compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4553
finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4748
*cygwin* | *mingw* )
4749
if test -f "$output_objdir/${outputname}.def" ; then
4750
compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
4751
finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
4753
compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4754
finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4758
compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4759
finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
4556
4764
$echo "$modename: unknown suffix for \`$dlsyms'" 1>&2
4779
4996
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
4780
4997
#endif /* DIR_SEPARATOR_2 */
4999
#ifndef PATH_SEPARATOR_2
5000
# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5001
#else /* PATH_SEPARATOR_2 */
5002
# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5003
#endif /* PATH_SEPARATOR_2 */
4782
5005
#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type)))
4783
5006
#define XFREE(stale) do { \
4784
5007
if (stale) { free ((void *) stale); stale = 0; } \
5010
/* -DDEBUG is fairly common in CFLAGS. */
5012
#if defined DEBUGWRAPPER
5013
# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__)
5015
# define DEBUG(format, ...)
4787
5018
const char *program_name = NULL;
4789
5020
void * xmalloc (size_t num);
4790
5021
char * xstrdup (const char *string);
4791
char * basename (const char *name);
4792
char * fnqualify(const char *path);
5022
const char * base_name (const char *name);
5023
char * find_executable(const char *wrapper);
5024
int check_executable(const char *path);
4793
5025
char * strendzap(char *str, const char *pat);
4794
5026
void lt_fatal (const char *message, ...);
4799
5031
char **newargz;
4802
program_name = (char *) xstrdup ((char *) basename (argv[0]));
5034
program_name = (char *) xstrdup (base_name (argv[0]));
5035
DEBUG("(main) argv[0] : %s\n",argv[0]);
5036
DEBUG("(main) program_name : %s\n",program_name);
4803
5037
newargz = XMALLOC(char *, argc+2);
4806
cat >> $cwrappersource <<EOF
4807
newargz[0] = "$SHELL";
5040
cat >> $cwrappersource <<EOF
5041
newargz[0] = (char *) xstrdup("$SHELL");
4810
cat >> $cwrappersource <<"EOF"
4811
newargz[1] = fnqualify(argv[0]);
5044
cat >> $cwrappersource <<"EOF"
5045
newargz[1] = find_executable(argv[0]);
5046
if (newargz[1] == NULL)
5047
lt_fatal("Couldn't find %s", argv[0]);
5048
DEBUG("(main) found exe at : %s\n",newargz[1]);
4812
5049
/* we know the script has the same name, without the .exe */
4813
5050
/* so make sure newargz[1] doesn't end in .exe */
4814
5051
strendzap(newargz[1],".exe");
4815
5052
for (i = 1; i < argc; i++)
4816
5053
newargz[i+1] = xstrdup(argv[i]);
4817
5054
newargz[argc+1] = NULL;
4820
cat >> $cwrappersource <<EOF
5056
for (i=0; i<argc+1; i++)
5058
DEBUG("(main) newargz[%d] : %s\n",i,newargz[i]);
5066
cat >> $cwrappersource <<EOF
5067
execv("$SHELL",(char const **)newargz);
5071
cat >> $cwrappersource <<EOF
4821
5072
execv("$SHELL",newargz);
4824
cat >> $cwrappersource <<"EOF"
5077
cat >> $cwrappersource <<"EOF"
4845
basename (const char *name)
5099
base_name (const char *name)
4847
5101
const char *base;
4849
5103
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
4850
5104
/* Skip over the disk name in MSDOS pathnames. */
4851
if (isalpha (name[0]) && name[1] == ':')
5105
if (isalpha ((unsigned char)name[0]) && name[1] == ':')
4855
5109
for (base = name; *name; name++)
4856
5110
if (IS_DIR_SEPARATOR (*name))
4857
5111
base = name + 1;
4858
return (char *) base;
5116
check_executable(const char * path)
5120
DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!");
5121
if ((!path) || (!*path))
5124
if ((stat (path, &st) >= 0) &&
5126
/* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */
5127
#if defined (S_IXOTH)
5128
((st.st_mode & S_IXOTH) == S_IXOTH) ||
5130
#if defined (S_IXGRP)
5131
((st.st_mode & S_IXGRP) == S_IXGRP) ||
5133
((st.st_mode & S_IXUSR) == S_IXUSR))
5140
/* Searches for the full path of the wrapper. Returns
5141
newly allocated full path name if found, NULL otherwise */
4862
fnqualify(const char *path)
5143
find_executable (const char* wrapper)
5148
/* static buffer for getcwd */
4866
5149
char tmp[LT_PATHMAX + 1];
4868
assert(path != NULL);
4870
/* Is it qualified already? */
4871
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
4872
if (isalpha (path[0]) && path[1] == ':')
4873
return xstrdup (path);
4875
if (IS_DIR_SEPARATOR (path[0]))
4876
return xstrdup (path);
4878
/* prepend the current directory */
4879
/* doesn't handle '~' */
5153
DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!");
5155
if ((wrapper == NULL) || (*wrapper == '\0'))
5158
/* Absolute path? */
5159
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
5160
if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':')
5162
concat_name = xstrdup (wrapper);
5163
if (check_executable(concat_name))
5170
if (IS_DIR_SEPARATOR (wrapper[0]))
5172
concat_name = xstrdup (wrapper);
5173
if (check_executable(concat_name))
5177
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
5181
for (p = wrapper; *p; p++)
5189
/* no slashes; search PATH */
5190
const char* path = getenv ("PATH");
5193
for (p = path; *p; p = p_next)
5197
for (q = p; *q; q++)
5198
if (IS_PATH_SEPARATOR(*q))
5201
p_next = (*q == '\0' ? q : q + 1);
5204
/* empty path: current directory */
5205
if (getcwd (tmp, LT_PATHMAX) == NULL)
5206
lt_fatal ("getcwd failed");
5207
tmp_len = strlen(tmp);
5208
concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
5209
memcpy (concat_name, tmp, tmp_len);
5210
concat_name[tmp_len] = '/';
5211
strcpy (concat_name + tmp_len + 1, wrapper);
5215
concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1);
5216
memcpy (concat_name, p, p_len);
5217
concat_name[p_len] = '/';
5218
strcpy (concat_name + p_len + 1, wrapper);
5220
if (check_executable(concat_name))
5225
/* not found in PATH; assume curdir */
5227
/* Relative path | not found in path: prepend cwd */
4880
5228
if (getcwd (tmp, LT_PATHMAX) == NULL)
4881
5229
lt_fatal ("getcwd failed");
4882
size = strlen(tmp) + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */
4883
p = XMALLOC(char, size);
4884
sprintf(p, "%s%c%s", tmp, DIR_SEPARATOR, path);
5230
tmp_len = strlen(tmp);
5231
concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
5232
memcpy (concat_name, tmp, tmp_len);
5233
concat_name[tmp_len] = '/';
5234
strcpy (concat_name + tmp_len + 1, wrapper);
5236
if (check_executable(concat_name))
4929
# we should really use a build-platform specific compiler
4930
# here, but OTOH, the wrappers (shell script and this C one)
4931
# are only useful if you want to execute the "real" binary.
4932
# Since the "real" binary is built for $host, then this
4933
# wrapper might as well be built for $host, too.
4934
$run $LTCC -s -o $cwrapper $cwrappersource
4938
trap "$rm $output; exit $EXIT_FAILURE" 1 2 15
5283
# we should really use a build-platform specific compiler
5284
# here, but OTOH, the wrappers (shell script and this C one)
5285
# are only useful if you want to execute the "real" binary.
5286
# Since the "real" binary is built for $host, then this
5287
# wrapper might as well be built for $host, too.
5288
$run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource
5292
trap "$rm $output; exit $EXIT_FAILURE" 1 2 15
4940
5294
$echo > $output "\
5817
6191
notinst_deplibs=
5818
6192
relink_command=
5820
# To insure that "foo" is sourced, and not "foo.exe",
5821
# finese the cygwin/MSYS system by explicitly sourcing "foo."
5822
# which disallows the automatic-append-.exe behavior.
5824
*cygwin* | *mingw*) wrapperdot=${wrapper}. ;;
5825
*) wrapperdot=${wrapper} ;;
6194
# Note that it is not necessary on cygwin/mingw to append a dot to
6195
# foo even if both foo and FILE.exe exist: automatic-append-.exe
6196
# behavior happens only for exec(3), not for open(2)! Also, sourcing
6197
# `FILE.' does not work on cygwin managed mounts.
5827
6199
# If there is no directory component, then add one.
5829
*/* | *\\*) . ${wrapperdot} ;;
5830
*) . ./${wrapperdot} ;;
6201
*/* | *\\*) . ${wrapper} ;;
6202
*) . ./${wrapper} ;;
5833
6205
# Check the variables that should have been set.
5857
6229
relink_command=
5858
# To insure that "foo" is sourced, and not "foo.exe",
5859
# finese the cygwin/MSYS system by explicitly sourcing "foo."
5860
# which disallows the automatic-append-.exe behavior.
5862
*cygwin* | *mingw*) wrapperdot=${wrapper}. ;;
5863
*) wrapperdot=${wrapper} ;;
6230
# Note that it is not necessary on cygwin/mingw to append a dot to
6231
# foo even if both foo and FILE.exe exist: automatic-append-.exe
6232
# behavior happens only for exec(3), not for open(2)! Also, sourcing
6233
# `FILE.' does not work on cygwin managed mounts.
5865
6235
# If there is no directory component, then add one.
5867
*/* | *\\*) . ${wrapperdot} ;;
5868
*) . ./${wrapperdot} ;;
6237
*/* | *\\*) . ${wrapper} ;;
6238
*) . ./${wrapper} ;;
5872
6242
if test "$fast_install" = no && test -n "$relink_command"; then
5873
6243
if test "$finalize" = yes && test -z "$run"; then
5875
test -n "$TMPDIR" && tmpdir="$TMPDIR"
5876
tmpdir="$tmpdir/libtool-$$"
5879
if $mkdir "$tmpdir"; then
5883
$echo "$modename: error: cannot create temporary directory \`$tmpdir'" 1>&2
6244
tmpdir=`func_mktempdir`
5886
6245
file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'`
5887
6246
outputname="$tmpdir/$file"
5888
6247
# Replace the output file specification.