ltmain.sh 194 KB
Newer Older
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
  if (stale) { free ((void *) stale); stale = 0; } \
} while (0)

/* -DDEBUG is fairly common in CFLAGS.  */
#undef DEBUG
#if defined DEBUGWRAPPER
# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__)
#else
# define DEBUG(format, ...)
#endif

const char *program_name = NULL;

void * xmalloc (size_t num);
char * xstrdup (const char *string);
const char * base_name (const char *name);
char * find_executable(const char *wrapper);
int    check_executable(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 (base_name (argv[0]));
  DEBUG("(main) argv[0]      : %s\n",argv[0]);
  DEBUG("(main) program_name : %s\n",program_name);
  newargz = XMALLOC(char *, argc+2);
EOF

            cat >> $cwrappersource <<EOF
  newargz[0] = (char *) xstrdup("$SHELL");
EOF

            cat >> $cwrappersource <<"EOF"
  newargz[1] = find_executable(argv[0]);
  if (newargz[1] == NULL)
    lt_fatal("Couldn't find %s", argv[0]);
  DEBUG("(main) found exe at : %s\n",newargz[1]);
  /* 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;

  for (i=0; i<argc+1; i++)
  {
    DEBUG("(main) newargz[%d]   : %s\n",i,newargz[i]);
    ;
  }

EOF

            case $host_os in
              mingw*)
                cat >> $cwrappersource <<EOF
  execv("$SHELL",(char const **)newargz);
EOF
              ;;
              *)
                cat >> $cwrappersource <<EOF
  execv("$SHELL",newargz);
EOF
              ;;
            esac

            cat >> $cwrappersource <<"EOF"
  return 127;
}

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
;
}

const char *
base_name (const char *name)
{
  const char *base;

#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
  /* Skip over the disk name in MSDOS pathnames. */
  if (isalpha ((unsigned char)name[0]) && name[1] == ':')
    name += 2;
#endif

  for (base = name; *name; name++)
    if (IS_DIR_SEPARATOR (*name))
      base = name + 1;
  return base;
}

int
check_executable(const char * path)
{
  struct stat st;

  DEBUG("(check_executable)  : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!");
  if ((!path) || (!*path))
    return 0;

  if ((stat (path, &st) >= 0) &&
      (
        /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */
#if defined (S_IXOTH)
       ((st.st_mode & S_IXOTH) == S_IXOTH) ||
#endif
#if defined (S_IXGRP)
       ((st.st_mode & S_IXGRP) == S_IXGRP) ||
#endif
       ((st.st_mode & S_IXUSR) == S_IXUSR))
      )
    return 1;
  else
    return 0;
}

/* Searches for the full path of the wrapper.  Returns
   newly allocated full path name if found, NULL otherwise */
char *
find_executable (const char* wrapper)
{
  int has_slash = 0;
  const char* p;
  const char* p_next;
  /* static buffer for getcwd */
  char tmp[LT_PATHMAX + 1];
  int tmp_len;
  char* concat_name;

  DEBUG("(find_executable)  : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!");

  if ((wrapper == NULL) || (*wrapper == '\0'))
    return NULL;

  /* Absolute path? */
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
  if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':')
  {
    concat_name = xstrdup (wrapper);
    if (check_executable(concat_name))
      return concat_name;
    XFREE(concat_name);
  }
  else
  {
#endif
    if (IS_DIR_SEPARATOR (wrapper[0]))
    {
      concat_name = xstrdup (wrapper);
      if (check_executable(concat_name))
        return concat_name;
      XFREE(concat_name);
    }
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
  }
#endif

  for (p = wrapper; *p; p++)
    if (*p == '/')
    {
      has_slash = 1;
      break;
    }
  if (!has_slash)
  {
    /* no slashes; search PATH */
    const char* path = getenv ("PATH");
    if (path != NULL)
    {
      for (p = path; *p; p = p_next)
      {
        const char* q;
        size_t p_len;
        for (q = p; *q; q++)
          if (IS_PATH_SEPARATOR(*q))
            break;
        p_len = q - p;
        p_next = (*q == '\0' ? q : q + 1);
        if (p_len == 0)
        {
          /* empty path: current directory */
          if (getcwd (tmp, LT_PATHMAX) == NULL)
            lt_fatal ("getcwd failed");
          tmp_len = strlen(tmp);
          concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
          memcpy (concat_name, tmp, tmp_len);
          concat_name[tmp_len] = '/';
          strcpy (concat_name + tmp_len + 1, wrapper);
        }
        else
        {
          concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1);
          memcpy (concat_name, p, p_len);
          concat_name[p_len] = '/';
          strcpy (concat_name + p_len + 1, wrapper);
        }
        if (check_executable(concat_name))
          return concat_name;
        XFREE(concat_name);
      }
    }
    /* not found in PATH; assume curdir */
  }
  /* Relative path | not found in path: prepend cwd */
  if (getcwd (tmp, LT_PATHMAX) == NULL)
    lt_fatal ("getcwd failed");
  tmp_len = strlen(tmp);
  concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
  memcpy (concat_name, tmp, tmp_len);
  concat_name[tmp_len] = '/';
  strcpy (concat_name + tmp_len + 1, wrapper);

  if (check_executable(concat_name))
    return concat_name;
  XFREE(concat_name);
  return NULL;
}

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 $LTCFLAGS -s -o $cwrapper $cwrappersource
          ;;
        esac
        $rm $output
        trap "$rm $output; exit $EXIT_FAILURE" 1 2 15
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301

	$echo > $output "\
#! $SHELL

# $output - temporary wrapper script 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 script should never be moved out of the build directory.
# If it is, it will not operate correctly.

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5302
Xsed='${SED} -e 1s/^X//'
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5303
5304
sed_quote_subst='$sed_quote_subst'

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE).
if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
  emulate sh
  NULLCMD=:
  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '\${1+\"\$@\"}'='\"\$@\"'
  setopt NO_GLOB_SUBST
else
  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
fi
BIN_SH=xpg4; export BIN_SH # for Tru64
DUALCASE=1; export DUALCASE # for MKS sh

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5319
5320
# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5321
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353

relink_command=\"$relink_command\"

# This environment variable determines our operation mode.
if test \"\$libtool_install_magic\" = \"$magic\"; then
  # install mode needs the following variable:
  notinst_deplibs='$notinst_deplibs'
else
  # When we are sourced in execute mode, \$file and \$echo are already set.
  if test \"\$libtool_execute_magic\" != \"$magic\"; then
    echo=\"$qecho\"
    file=\"\$0\"
    # Make sure echo works.
    if test \"X\$1\" = X--no-reexec; then
      # Discard the --no-reexec flag, and continue.
      shift
    elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then
      # Yippee, \$echo works!
      :
    else
      # Restart under the correct shell, and then maybe \$echo will work.
      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
    fi
  fi\
"
	$echo >> $output "\

  # Find the directory that this script lives in.
  thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
  test \"x\$thisdir\" = \"x\$file\" && thisdir=.

  # Follow symbolic links until we get to the real thisdir.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5354
  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
  while test -n \"\$file\"; do
    destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`

    # If there was a directory component, then change thisdir.
    if test \"x\$destdir\" != \"x\$file\"; then
      case \"\$destdir\" in
      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
      *) thisdir=\"\$thisdir/\$destdir\" ;;
      esac
    fi

    file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5367
    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5368
5369
5370
5371
5372
5373
5374
5375
  done

  # Try to get the absolute directory name.
  absdir=\`cd \"\$thisdir\" && pwd\`
  test -n \"\$absdir\" && thisdir=\"\$absdir\"
"

	if test "$fast_install" = yes; then
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5376
	  $echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5377
5378
5379
5380
  program=lt-'$outputname'$exeext
  progdir=\"\$thisdir/$objdir\"

  if test ! -f \"\$progdir/\$program\" || \\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5381
     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
       test \"X\$file\" != \"X\$progdir/\$program\"; }; then

    file=\"\$\$-\$program\"

    if test ! -d \"\$progdir\"; then
      $mkdir \"\$progdir\"
    else
      $rm \"\$progdir/\$file\"
    fi"

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5392
	  $echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5393
5394
5395
5396
5397
5398
5399

    # relink executable if necessary
    if test -n \"\$relink_command\"; then
      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
      else
	$echo \"\$relink_command_output\" >&2
	$rm \"\$progdir/\$file\"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5400
	exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5401
5402
5403
5404
5405
5406
5407
5408
5409
      fi
    fi

    $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
    { $rm \"\$progdir/\$program\";
      $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; }
    $rm \"\$progdir/\$file\"
  fi"
	else
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5410
	  $echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5411
5412
5413
5414
5415
  program='$outputname'
  progdir=\"\$thisdir/$objdir\"
"
	fi

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5416
	$echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449

  if test -f \"\$progdir/\$program\"; then"

	# Export our shlibpath_var if we have one.
	if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
	  $echo >> $output "\
    # Add our own library path to $shlibpath_var
    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"

    # Some systems cannot cope with colon-terminated $shlibpath_var
    # The second colon is a workaround for a bug in BeOS R4 sed
    $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`

    export $shlibpath_var
"
	fi

	# fixup the dll searchpath if we need to.
	if test -n "$dllsearchpath"; then
	  $echo >> $output "\
    # Add the dll search path components to the executable PATH
    PATH=$dllsearchpath:\$PATH
"
	fi

	$echo >> $output "\
    if test \"\$libtool_execute_magic\" != \"$magic\"; then
      # Run the actual program with our arguments.
"
	case $host in
	# Backslashes separate directories on plain windows
	*-*-mingw | *-*-os2*)
	  $echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5450
      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5451
5452
5453
5454
5455
"
	  ;;

	*)
	  $echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5456
      exec \"\$progdir/\$program\" \${1+\"\$@\"}
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5457
5458
5459
5460
"
	  ;;
	esac
	$echo >> $output "\
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5461
5462
      \$echo \"\$0: cannot exec \$program \$*\"
      exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5463
5464
5465
    fi
  else
    # The program doesn't exist.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5466
    \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5467
    \$echo \"This script is just a wrapper for \$program.\" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5468
5469
    $echo \"See the $PACKAGE documentation for more information.\" 1>&2
    exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5470
5471
5472
5473
5474
  fi
fi\
"
	chmod +x $output
      fi
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5475
      exit $EXIT_SUCCESS
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
      ;;
    esac

    # See if we need to build an old-fashioned archive.
    for oldlib in $oldlibs; do

      if test "$build_libtool_libs" = convenience; then
	oldobjs="$libobjs_save"
	addlibs="$convenience"
	build_libtool_libs=no
      else
	if test "$build_libtool_libs" = module; then
	  oldobjs="$libobjs_save"
	  build_libtool_libs=no
	else
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5491
	  oldobjs="$old_deplibs $non_pic_objects"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5492
5493
5494
5495
5496
5497
5498
5499
	fi
	addlibs="$old_convenience"
      fi

      if test -n "$addlibs"; then
	gentop="$output_objdir/${outputname}x"
	generated="$generated $gentop"

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5500
5501
	func_extract_archives $gentop $addlibs
	oldobjs="$oldobjs $func_extract_archives_result"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5502
5503
5504
5505
      fi

      # Do each command in the archive commands.
      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5506
       cmds=$old_archive_from_new_cmds
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5507
      else
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
	# POSIX demands no paths to be encoded in archives.  We have
	# to avoid creating archives with duplicate basenames if we
	# might have to extract them afterwards, e.g., when creating a
	# static archive out of a convenience library, or when linking
	# the entirety of a libtool archive into another (currently
	# not supported by libtool).
	if (for obj in $oldobjs
	    do
	      $echo "X$obj" | $Xsed -e 's%^.*/%%'
	    done | sort | sort -uc >/dev/null 2>&1); then
	  :
	else
	  $echo "copying selected object files to avoid basename conflicts..."

	  if test -z "$gentop"; then
	    gentop="$output_objdir/${outputname}x"
	    generated="$generated $gentop"

	    $show "${rm}r $gentop"
	    $run ${rm}r "$gentop"
	    $show "$mkdir $gentop"
	    $run $mkdir "$gentop"
	    exit_status=$?
	    if test "$exit_status" -ne 0 && test ! -d "$gentop"; then
	      exit $exit_status
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5533
5534
	    fi
	  fi
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563

	  save_oldobjs=$oldobjs
	  oldobjs=
	  counter=1
	  for obj in $save_oldobjs
	  do
	    objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
	    case " $oldobjs " in
	    " ") oldobjs=$obj ;;
	    *[\ /]"$objbase "*)
	      while :; do
		# Make sure we don't pick an alternate name that also
		# overlaps.
		newobj=lt$counter-$objbase
		counter=`expr $counter + 1`
		case " $oldobjs " in
		*[\ /]"$newobj "*) ;;
		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
		esac
	      done
	      $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
	      $run ln "$obj" "$gentop/$newobj" ||
	      $run cp "$obj" "$gentop/$newobj"
	      oldobjs="$oldobjs $gentop/$newobj"
	      ;;
	    *) oldobjs="$oldobjs $obj" ;;
	    esac
	  done
	fi
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5564
5565

	eval cmds=\"$old_archive_cmds\"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610

	if len=`expr "X$cmds" : ".*"` &&
	     test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
	  cmds=$old_archive_cmds
	else
	  # the command line is too long to link in one step, link in parts
	  $echo "using piecewise archive linking..."
	  save_RANLIB=$RANLIB
	  RANLIB=:
	  objlist=
	  concat_cmds=
	  save_oldobjs=$oldobjs

	  # Is there a better way of finding the last object in the list?
	  for obj in $save_oldobjs
	  do
	    last_oldobj=$obj
	  done
	  for obj in $save_oldobjs
	  do
	    oldobjs="$objlist $obj"
	    objlist="$objlist $obj"
	    eval test_cmds=\"$old_archive_cmds\"
	    if len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
	       test "$len" -le "$max_cmd_len"; then
	      :
	    else
	      # the above command should be used before it gets too long
	      oldobjs=$objlist
	      if test "$obj" = "$last_oldobj" ; then
	        RANLIB=$save_RANLIB
	      fi
	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
	      eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
	      objlist=
	    fi
	  done
	  RANLIB=$save_RANLIB
	  oldobjs=$objlist
	  if test "X$oldobjs" = "X" ; then
	    eval cmds=\"\$concat_cmds\"
	  else
	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
	  fi
	fi
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5611
5612
5613
      fi
      save_ifs="$IFS"; IFS='~'
      for cmd in $cmds; do
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5614
        eval cmd=\"$cmd\"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
	IFS="$save_ifs"
	$show "$cmd"
	$run eval "$cmd" || exit $?
      done
      IFS="$save_ifs"
    done

    if test -n "$generated"; then
      $show "${rm}r$generated"
      $run ${rm}r$generated
    fi

    # Now create the libtool archive.
    case $output in
    *.la)
      old_library=
      test "$build_old_libs" = yes && old_library="$libname.$libext"
      $show "creating $output"

      # Preserve any variables that may affect compiler behavior
      for var in $variables_saved_for_relink; do
	if eval test -z \"\${$var+set}\"; then
	  relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command"
	elif eval var_value=\$$var; test -z "$var_value"; then
	  relink_command="$var=; export $var; $relink_command"
	else
	  var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"`
	  relink_command="$var=\"$var_value\"; export $var; $relink_command"
	fi
      done
      # Quote the link command for shipping.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5646
5647
5648
5649
5650
5651
      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
      relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP`
      if test "$hardcode_automatic" = yes ; then
	relink_command=
      fi

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666

      # Only create the output if not a dry run.
      if test -z "$run"; then
	for installed in no yes; do
	  if test "$installed" = yes; then
	    if test -z "$install_libdir"; then
	      break
	    fi
	    output="$output_objdir/$outputname"i
	    # Replace all uninstalled libtool libraries with the installed ones
	    newdependency_libs=
	    for deplib in $dependency_libs; do
	      case $deplib in
	      *.la)
		name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5667
		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5668
5669
		if test -z "$libdir"; then
		  $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5670
		  exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
		fi
		newdependency_libs="$newdependency_libs $libdir/$name"
		;;
	      *) newdependency_libs="$newdependency_libs $deplib" ;;
	      esac
	    done
	    dependency_libs="$newdependency_libs"
	    newdlfiles=
	    for lib in $dlfiles; do
	      name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5681
	      eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5682
5683
	      if test -z "$libdir"; then
		$echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5684
		exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5685
5686
5687
5688
5689
5690
5691
	      fi
	      newdlfiles="$newdlfiles $libdir/$name"
	    done
	    dlfiles="$newdlfiles"
	    newdlprefiles=
	    for lib in $dlprefiles; do
	      name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5692
	      eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5693
5694
	      if test -z "$libdir"; then
		$echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5695
		exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5696
5697
5698
5699
	      fi
	      newdlprefiles="$newdlprefiles $libdir/$name"
	    done
	    dlprefiles="$newdlprefiles"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
	  else
	    newdlfiles=
	    for lib in $dlfiles; do
	      case $lib in
		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
		*) abs=`pwd`"/$lib" ;;
	      esac
	      newdlfiles="$newdlfiles $abs"
	    done
	    dlfiles="$newdlfiles"
	    newdlprefiles=
	    for lib in $dlprefiles; do
	      case $lib in
		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
		*) abs=`pwd`"/$lib" ;;
	      esac
	      newdlprefiles="$newdlprefiles $abs"
	    done
	    dlprefiles="$newdlprefiles"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5719
5720
5721
5722
5723
	  fi
	  $rm $output
	  # place dlname in correct position for cygwin
	  tdlname=$dlname
	  case $host,$output,$installed,$module,$dlname in
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5724
	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
	  esac
	  $echo > $output "\
# $outputname - a libtool library file
# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='$tdlname'

# Names of this library.
library_names='$library_names'

# The name of the static archive.
old_library='$old_library'

# Libraries that this one depends upon.
dependency_libs='$dependency_libs'

# Version information for $libname.
current=$current
age=$age
revision=$revision

# Is this an already installed library?
installed=$installed

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5753
5754
5755
# Should we warn about portability when linking against -modules?
shouldnotlink=$module

Emmanuel Bertin's avatar
Emmanuel Bertin committed
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
# Files to dlopen/dlpreopen
dlopen='$dlfiles'
dlpreopen='$dlprefiles'

# Directory that this library needs to be installed in:
libdir='$install_libdir'"
	  if test "$installed" = no && test "$need_relink" = yes; then
	    $echo >> $output "\
relink_command=\"$relink_command\""
	  fi
	done
      fi

      # Do a symbolic link so that the libtool archive can be found in
      # LD_LIBRARY_PATH before the program is installed.
      $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)"
      $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $?
      ;;
    esac
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5775
    exit $EXIT_SUCCESS
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
    ;;

  # libtool install mode
  install)
    modename="$modename: install"

    # There may be an optional sh(1) argument at the beginning of
    # install_prog (especially on Windows NT).
    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
       # Allow the use of GNU shtool's install command.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5786
       $echo "X$nonopt" | grep shtool > /dev/null; then
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5787
5788
5789
      # Aesthetically quote it.
      arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"`
      case $arg in
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5790
      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5791
5792
5793
5794
5795
5796
5797
5798
	arg="\"$arg\""
	;;
      esac
      install_prog="$arg "
      arg="$1"
      shift
    else
      install_prog=
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5799
      arg=$nonopt
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5800
5801
5802
5803
5804
5805
    fi

    # The real first argument should be the name of the installation program.
    # Aesthetically quote it.
    arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
    case $arg in
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5806
    *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
      arg="\"$arg\""
      ;;
    esac
    install_prog="$install_prog$arg"

    # We need to accept at least all the BSD install flags.
    dest=
    files=
    opts=
    prev=
    install_type=
    isdir=no
    stripme=
    for arg
    do
      if test -n "$dest"; then
	files="$files $dest"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5824
	dest=$arg
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5825
5826
5827
5828
5829
	continue
      fi

      case $arg in
      -d) isdir=yes ;;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5830
5831
5832
5833
5834
5835
5836
      -f) 
      	case " $install_prog " in
	*[\\\ /]cp\ *) ;;
	*) prev=$arg ;;
	esac
	;;
      -g | -m | -o) prev=$arg ;;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5837
5838
5839
5840
      -s)
	stripme=" -s"
	continue
	;;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5841
5842
      -*)
	;;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5843
5844
5845
5846
5847
      *)
	# If the previous option needed an argument, then skip it.
	if test -n "$prev"; then
	  prev=
	else
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5848
	  dest=$arg
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5849
5850
5851
5852
5853
5854
5855
5856
	  continue
	fi
	;;
      esac

      # Aesthetically quote the argument.
      arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
      case $arg in
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5857
      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5858
5859
5860
5861
5862
5863
5864
5865
5866
	arg="\"$arg\""
	;;
      esac
      install_prog="$install_prog $arg"
    done

    if test -z "$install_prog"; then
      $echo "$modename: you must specify an install program" 1>&2
      $echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5867
      exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5868
5869
5870
5871
5872
    fi

    if test -n "$prev"; then
      $echo "$modename: the \`$prev' option requires an argument" 1>&2
      $echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5873
      exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5874
5875
5876
5877
5878
5879
5880
5881
5882
    fi

    if test -z "$files"; then
      if test -z "$dest"; then
	$echo "$modename: no file or destination specified" 1>&2
      else
	$echo "$modename: you must specify a destination" 1>&2
      fi
      $echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5883
      exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
    fi

    # Strip any trailing slash from the destination.
    dest=`$echo "X$dest" | $Xsed -e 's%/$%%'`

    # Check to see that the destination is a directory.
    test -d "$dest" && isdir=yes
    if test "$isdir" = yes; then
      destdir="$dest"
      destname=
    else
      destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'`
      test "X$destdir" = "X$dest" && destdir=.
      destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'`

      # Not a directory, so check to see that there is only one file specified.
      set dummy $files
      if test "$#" -gt 2; then
	$echo "$modename: \`$dest' is not a directory" 1>&2
	$echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5904
	exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
      fi
    fi
    case $destdir in
    [\\/]* | [A-Za-z]:[\\/]*) ;;
    *)
      for file in $files; do
	case $file in
	*.lo) ;;
	*)
	  $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2
	  $echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5916
	  exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
	  ;;
	esac
      done
      ;;
    esac

    # This variable tells wrapper scripts just to set variables rather
    # than running their programs.
    libtool_install_magic="$magic"

    staticlibs=
    future_libdirs=
    current_libdirs=
    for file in $files; do

      # Do each installation.
      case $file in
      *.$libext)
	# Do the static libraries later.
	staticlibs="$staticlibs $file"
	;;

      *.la)
	# Check to see that this really is a libtool archive.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5941
	if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5942
5943
5944
	else
	  $echo "$modename: \`$file' is not a valid libtool archive" 1>&2
	  $echo "$help" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5945
	  exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
	fi

	library_names=
	old_library=
	relink_command=
	# If there is no directory component, then add one.
	case $file in
	*/* | *\\*) . $file ;;
	*) . ./$file ;;
	esac

	# Add the libdir to current_libdirs if it is the destination.
	if test "X$destdir" = "X$libdir"; then
	  case "$current_libdirs " in
	  *" $libdir "*) ;;
	  *) current_libdirs="$current_libdirs $libdir" ;;
	  esac
	else
	  # Note the libdir as a future libdir.
	  case "$future_libdirs " in
	  *" $libdir "*) ;;
	  *) future_libdirs="$future_libdirs $libdir" ;;
	  esac
	fi

	dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/
	test "X$dir" = "X$file/" && dir=
	dir="$dir$objdir"

	if test -n "$relink_command"; then
	  # Determine the prefix the user has applied to our future dir.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5977
	  inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5978
5979
5980
5981

	  # Don't allow the user to place us outside of our expected
	  # location b/c this prevents finding dependent libraries that
	  # are installed to the same prefix.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5982
5983
5984
	  # At present, this check doesn't affect windows .dll's that
	  # are installed into $libdir/../bin (currently, that works fine)
	  # but it's something to keep an eye on.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5985
5986
	  if test "$inst_prefix_dir" = "$destdir"; then
	    $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5987
	    exit $EXIT_FAILURE
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5988
5989
5990
5991
	  fi

	  if test -n "$inst_prefix_dir"; then
	    # Stick the inst_prefix_dir data into the link command.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5992
	    relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5993
	  else
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5994
	    relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP`
Emmanuel Bertin's avatar
Emmanuel Bertin committed
5995
5996
5997
5998
5999
6000
	  fi

	  $echo "$modename: warning: relinking \`$file'" 1>&2
	  $show "$relink_command"
	  if $run eval "$relink_command"; then :
	  else
For faster browsing, not all history is shown. View entire blame