Home | History | Annotate | Line # | Download | only in dist
compile revision 1.1.1.1.8.1
      1          1.1  mrg #! /bin/sh
      2  1.1.1.1.8.1  tls # Wrapper for compilers which do not understand '-c -o'.
      3          1.1  mrg 
      4  1.1.1.1.8.1  tls scriptversion=2012-03-05.13; # UTC
      5          1.1  mrg 
      6  1.1.1.1.8.1  tls # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
      7  1.1.1.1.8.1  tls # Software Foundation, Inc.
      8          1.1  mrg # Written by Tom Tromey <tromey (at] cygnus.com>.
      9          1.1  mrg #
     10          1.1  mrg # This program is free software; you can redistribute it and/or modify
     11          1.1  mrg # it under the terms of the GNU General Public License as published by
     12          1.1  mrg # the Free Software Foundation; either version 2, or (at your option)
     13          1.1  mrg # any later version.
     14          1.1  mrg #
     15          1.1  mrg # This program is distributed in the hope that it will be useful,
     16          1.1  mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
     17          1.1  mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18          1.1  mrg # GNU General Public License for more details.
     19          1.1  mrg #
     20          1.1  mrg # You should have received a copy of the GNU General Public License
     21          1.1  mrg # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22          1.1  mrg 
     23          1.1  mrg # As a special exception to the GNU General Public License, if you
     24          1.1  mrg # distribute this file as part of a program that contains a
     25          1.1  mrg # configuration script generated by Autoconf, you may include it under
     26          1.1  mrg # the same distribution terms that you use for the rest of that program.
     27          1.1  mrg 
     28          1.1  mrg # This file is maintained in Automake, please report
     29          1.1  mrg # bugs to <bug-automake (at] gnu.org> or send patches to
     30          1.1  mrg # <automake-patches (at] gnu.org>.
     31          1.1  mrg 
     32  1.1.1.1.8.1  tls nl='
     33  1.1.1.1.8.1  tls '
     34  1.1.1.1.8.1  tls 
     35  1.1.1.1.8.1  tls # We need space, tab and new line, in precisely that order.  Quoting is
     36  1.1.1.1.8.1  tls # there to prevent tools from complaining about whitespace usage.
     37  1.1.1.1.8.1  tls IFS=" ""	$nl"
     38  1.1.1.1.8.1  tls 
     39  1.1.1.1.8.1  tls file_conv=
     40  1.1.1.1.8.1  tls 
     41  1.1.1.1.8.1  tls # func_file_conv build_file lazy
     42  1.1.1.1.8.1  tls # Convert a $build file to $host form and store it in $file
     43  1.1.1.1.8.1  tls # Currently only supports Windows hosts. If the determined conversion
     44  1.1.1.1.8.1  tls # type is listed in (the comma separated) LAZY, no conversion will
     45  1.1.1.1.8.1  tls # take place.
     46  1.1.1.1.8.1  tls func_file_conv ()
     47  1.1.1.1.8.1  tls {
     48  1.1.1.1.8.1  tls   file=$1
     49  1.1.1.1.8.1  tls   case $file in
     50  1.1.1.1.8.1  tls     / | /[!/]*) # absolute file, and not a UNC file
     51  1.1.1.1.8.1  tls       if test -z "$file_conv"; then
     52  1.1.1.1.8.1  tls 	# lazily determine how to convert abs files
     53  1.1.1.1.8.1  tls 	case `uname -s` in
     54  1.1.1.1.8.1  tls 	  MINGW*)
     55  1.1.1.1.8.1  tls 	    file_conv=mingw
     56  1.1.1.1.8.1  tls 	    ;;
     57  1.1.1.1.8.1  tls 	  CYGWIN*)
     58  1.1.1.1.8.1  tls 	    file_conv=cygwin
     59  1.1.1.1.8.1  tls 	    ;;
     60  1.1.1.1.8.1  tls 	  *)
     61  1.1.1.1.8.1  tls 	    file_conv=wine
     62  1.1.1.1.8.1  tls 	    ;;
     63  1.1.1.1.8.1  tls 	esac
     64  1.1.1.1.8.1  tls       fi
     65  1.1.1.1.8.1  tls       case $file_conv/,$2, in
     66  1.1.1.1.8.1  tls 	*,$file_conv,*)
     67  1.1.1.1.8.1  tls 	  ;;
     68  1.1.1.1.8.1  tls 	mingw/*)
     69  1.1.1.1.8.1  tls 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
     70  1.1.1.1.8.1  tls 	  ;;
     71  1.1.1.1.8.1  tls 	cygwin/*)
     72  1.1.1.1.8.1  tls 	  file=`cygpath -m "$file" || echo "$file"`
     73  1.1.1.1.8.1  tls 	  ;;
     74  1.1.1.1.8.1  tls 	wine/*)
     75  1.1.1.1.8.1  tls 	  file=`winepath -w "$file" || echo "$file"`
     76  1.1.1.1.8.1  tls 	  ;;
     77  1.1.1.1.8.1  tls       esac
     78  1.1.1.1.8.1  tls       ;;
     79  1.1.1.1.8.1  tls   esac
     80  1.1.1.1.8.1  tls }
     81  1.1.1.1.8.1  tls 
     82  1.1.1.1.8.1  tls # func_cl_dashL linkdir
     83  1.1.1.1.8.1  tls # Make cl look for libraries in LINKDIR
     84  1.1.1.1.8.1  tls func_cl_dashL ()
     85  1.1.1.1.8.1  tls {
     86  1.1.1.1.8.1  tls   func_file_conv "$1"
     87  1.1.1.1.8.1  tls   if test -z "$lib_path"; then
     88  1.1.1.1.8.1  tls     lib_path=$file
     89  1.1.1.1.8.1  tls   else
     90  1.1.1.1.8.1  tls     lib_path="$lib_path;$file"
     91  1.1.1.1.8.1  tls   fi
     92  1.1.1.1.8.1  tls   linker_opts="$linker_opts -LIBPATH:$file"
     93  1.1.1.1.8.1  tls }
     94  1.1.1.1.8.1  tls 
     95  1.1.1.1.8.1  tls # func_cl_dashl library
     96  1.1.1.1.8.1  tls # Do a library search-path lookup for cl
     97  1.1.1.1.8.1  tls func_cl_dashl ()
     98  1.1.1.1.8.1  tls {
     99  1.1.1.1.8.1  tls   lib=$1
    100  1.1.1.1.8.1  tls   found=no
    101  1.1.1.1.8.1  tls   save_IFS=$IFS
    102  1.1.1.1.8.1  tls   IFS=';'
    103  1.1.1.1.8.1  tls   for dir in $lib_path $LIB
    104  1.1.1.1.8.1  tls   do
    105  1.1.1.1.8.1  tls     IFS=$save_IFS
    106  1.1.1.1.8.1  tls     if $shared && test -f "$dir/$lib.dll.lib"; then
    107  1.1.1.1.8.1  tls       found=yes
    108  1.1.1.1.8.1  tls       lib=$dir/$lib.dll.lib
    109  1.1.1.1.8.1  tls       break
    110  1.1.1.1.8.1  tls     fi
    111  1.1.1.1.8.1  tls     if test -f "$dir/$lib.lib"; then
    112  1.1.1.1.8.1  tls       found=yes
    113  1.1.1.1.8.1  tls       lib=$dir/$lib.lib
    114  1.1.1.1.8.1  tls       break
    115  1.1.1.1.8.1  tls     fi
    116  1.1.1.1.8.1  tls   done
    117  1.1.1.1.8.1  tls   IFS=$save_IFS
    118  1.1.1.1.8.1  tls 
    119  1.1.1.1.8.1  tls   if test "$found" != yes; then
    120  1.1.1.1.8.1  tls     lib=$lib.lib
    121  1.1.1.1.8.1  tls   fi
    122  1.1.1.1.8.1  tls }
    123  1.1.1.1.8.1  tls 
    124  1.1.1.1.8.1  tls # func_cl_wrapper cl arg...
    125  1.1.1.1.8.1  tls # Adjust compile command to suit cl
    126  1.1.1.1.8.1  tls func_cl_wrapper ()
    127  1.1.1.1.8.1  tls {
    128  1.1.1.1.8.1  tls   # Assume a capable shell
    129  1.1.1.1.8.1  tls   lib_path=
    130  1.1.1.1.8.1  tls   shared=:
    131  1.1.1.1.8.1  tls   linker_opts=
    132  1.1.1.1.8.1  tls   for arg
    133  1.1.1.1.8.1  tls   do
    134  1.1.1.1.8.1  tls     if test -n "$eat"; then
    135  1.1.1.1.8.1  tls       eat=
    136  1.1.1.1.8.1  tls     else
    137  1.1.1.1.8.1  tls       case $1 in
    138  1.1.1.1.8.1  tls 	-o)
    139  1.1.1.1.8.1  tls 	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
    140  1.1.1.1.8.1  tls 	  eat=1
    141  1.1.1.1.8.1  tls 	  case $2 in
    142  1.1.1.1.8.1  tls 	    *.o | *.[oO][bB][jJ])
    143  1.1.1.1.8.1  tls 	      func_file_conv "$2"
    144  1.1.1.1.8.1  tls 	      set x "$@" -Fo"$file"
    145  1.1.1.1.8.1  tls 	      shift
    146  1.1.1.1.8.1  tls 	      ;;
    147  1.1.1.1.8.1  tls 	    *)
    148  1.1.1.1.8.1  tls 	      func_file_conv "$2"
    149  1.1.1.1.8.1  tls 	      set x "$@" -Fe"$file"
    150  1.1.1.1.8.1  tls 	      shift
    151  1.1.1.1.8.1  tls 	      ;;
    152  1.1.1.1.8.1  tls 	  esac
    153  1.1.1.1.8.1  tls 	  ;;
    154  1.1.1.1.8.1  tls 	-I)
    155  1.1.1.1.8.1  tls 	  eat=1
    156  1.1.1.1.8.1  tls 	  func_file_conv "$2" mingw
    157  1.1.1.1.8.1  tls 	  set x "$@" -I"$file"
    158  1.1.1.1.8.1  tls 	  shift
    159  1.1.1.1.8.1  tls 	  ;;
    160  1.1.1.1.8.1  tls 	-I*)
    161  1.1.1.1.8.1  tls 	  func_file_conv "${1#-I}" mingw
    162  1.1.1.1.8.1  tls 	  set x "$@" -I"$file"
    163  1.1.1.1.8.1  tls 	  shift
    164  1.1.1.1.8.1  tls 	  ;;
    165  1.1.1.1.8.1  tls 	-l)
    166  1.1.1.1.8.1  tls 	  eat=1
    167  1.1.1.1.8.1  tls 	  func_cl_dashl "$2"
    168  1.1.1.1.8.1  tls 	  set x "$@" "$lib"
    169  1.1.1.1.8.1  tls 	  shift
    170  1.1.1.1.8.1  tls 	  ;;
    171  1.1.1.1.8.1  tls 	-l*)
    172  1.1.1.1.8.1  tls 	  func_cl_dashl "${1#-l}"
    173  1.1.1.1.8.1  tls 	  set x "$@" "$lib"
    174  1.1.1.1.8.1  tls 	  shift
    175  1.1.1.1.8.1  tls 	  ;;
    176  1.1.1.1.8.1  tls 	-L)
    177  1.1.1.1.8.1  tls 	  eat=1
    178  1.1.1.1.8.1  tls 	  func_cl_dashL "$2"
    179  1.1.1.1.8.1  tls 	  ;;
    180  1.1.1.1.8.1  tls 	-L*)
    181  1.1.1.1.8.1  tls 	  func_cl_dashL "${1#-L}"
    182  1.1.1.1.8.1  tls 	  ;;
    183  1.1.1.1.8.1  tls 	-static)
    184  1.1.1.1.8.1  tls 	  shared=false
    185  1.1.1.1.8.1  tls 	  ;;
    186  1.1.1.1.8.1  tls 	-Wl,*)
    187  1.1.1.1.8.1  tls 	  arg=${1#-Wl,}
    188  1.1.1.1.8.1  tls 	  save_ifs="$IFS"; IFS=','
    189  1.1.1.1.8.1  tls 	  for flag in $arg; do
    190  1.1.1.1.8.1  tls 	    IFS="$save_ifs"
    191  1.1.1.1.8.1  tls 	    linker_opts="$linker_opts $flag"
    192  1.1.1.1.8.1  tls 	  done
    193  1.1.1.1.8.1  tls 	  IFS="$save_ifs"
    194  1.1.1.1.8.1  tls 	  ;;
    195  1.1.1.1.8.1  tls 	-Xlinker)
    196  1.1.1.1.8.1  tls 	  eat=1
    197  1.1.1.1.8.1  tls 	  linker_opts="$linker_opts $2"
    198  1.1.1.1.8.1  tls 	  ;;
    199  1.1.1.1.8.1  tls 	-*)
    200  1.1.1.1.8.1  tls 	  set x "$@" "$1"
    201  1.1.1.1.8.1  tls 	  shift
    202  1.1.1.1.8.1  tls 	  ;;
    203  1.1.1.1.8.1  tls 	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
    204  1.1.1.1.8.1  tls 	  func_file_conv "$1"
    205  1.1.1.1.8.1  tls 	  set x "$@" -Tp"$file"
    206  1.1.1.1.8.1  tls 	  shift
    207  1.1.1.1.8.1  tls 	  ;;
    208  1.1.1.1.8.1  tls 	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
    209  1.1.1.1.8.1  tls 	  func_file_conv "$1" mingw
    210  1.1.1.1.8.1  tls 	  set x "$@" "$file"
    211  1.1.1.1.8.1  tls 	  shift
    212  1.1.1.1.8.1  tls 	  ;;
    213  1.1.1.1.8.1  tls 	*)
    214  1.1.1.1.8.1  tls 	  set x "$@" "$1"
    215  1.1.1.1.8.1  tls 	  shift
    216  1.1.1.1.8.1  tls 	  ;;
    217  1.1.1.1.8.1  tls       esac
    218  1.1.1.1.8.1  tls     fi
    219  1.1.1.1.8.1  tls     shift
    220  1.1.1.1.8.1  tls   done
    221  1.1.1.1.8.1  tls   if test -n "$linker_opts"; then
    222  1.1.1.1.8.1  tls     linker_opts="-link$linker_opts"
    223  1.1.1.1.8.1  tls   fi
    224  1.1.1.1.8.1  tls   exec "$@" $linker_opts
    225  1.1.1.1.8.1  tls   exit 1
    226  1.1.1.1.8.1  tls }
    227  1.1.1.1.8.1  tls 
    228  1.1.1.1.8.1  tls eat=
    229  1.1.1.1.8.1  tls 
    230          1.1  mrg case $1 in
    231          1.1  mrg   '')
    232  1.1.1.1.8.1  tls      echo "$0: No command.  Try '$0 --help' for more information." 1>&2
    233          1.1  mrg      exit 1;
    234          1.1  mrg      ;;
    235          1.1  mrg   -h | --h*)
    236          1.1  mrg     cat <<\EOF
    237          1.1  mrg Usage: compile [--help] [--version] PROGRAM [ARGS]
    238          1.1  mrg 
    239  1.1.1.1.8.1  tls Wrapper for compilers which do not understand '-c -o'.
    240  1.1.1.1.8.1  tls Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
    241          1.1  mrg arguments, and rename the output as expected.
    242          1.1  mrg 
    243          1.1  mrg If you are trying to build a whole package this is not the
    244  1.1.1.1.8.1  tls right script to run: please start by reading the file 'INSTALL'.
    245          1.1  mrg 
    246          1.1  mrg Report bugs to <bug-automake@gnu.org>.
    247          1.1  mrg EOF
    248          1.1  mrg     exit $?
    249          1.1  mrg     ;;
    250          1.1  mrg   -v | --v*)
    251          1.1  mrg     echo "compile $scriptversion"
    252          1.1  mrg     exit $?
    253          1.1  mrg     ;;
    254  1.1.1.1.8.1  tls   cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
    255  1.1.1.1.8.1  tls     func_cl_wrapper "$@"      # Doesn't return...
    256  1.1.1.1.8.1  tls     ;;
    257          1.1  mrg esac
    258          1.1  mrg 
    259          1.1  mrg ofile=
    260          1.1  mrg cfile=
    261          1.1  mrg 
    262          1.1  mrg for arg
    263          1.1  mrg do
    264          1.1  mrg   if test -n "$eat"; then
    265          1.1  mrg     eat=
    266          1.1  mrg   else
    267          1.1  mrg     case $1 in
    268          1.1  mrg       -o)
    269  1.1.1.1.8.1  tls 	# configure might choose to run compile as 'compile cc -o foo foo.c'.
    270  1.1.1.1.8.1  tls 	# So we strip '-o arg' only if arg is an object.
    271          1.1  mrg 	eat=1
    272          1.1  mrg 	case $2 in
    273          1.1  mrg 	  *.o | *.obj)
    274          1.1  mrg 	    ofile=$2
    275          1.1  mrg 	    ;;
    276          1.1  mrg 	  *)
    277          1.1  mrg 	    set x "$@" -o "$2"
    278          1.1  mrg 	    shift
    279          1.1  mrg 	    ;;
    280          1.1  mrg 	esac
    281          1.1  mrg 	;;
    282          1.1  mrg       *.c)
    283          1.1  mrg 	cfile=$1
    284          1.1  mrg 	set x "$@" "$1"
    285          1.1  mrg 	shift
    286          1.1  mrg 	;;
    287          1.1  mrg       *)
    288          1.1  mrg 	set x "$@" "$1"
    289          1.1  mrg 	shift
    290          1.1  mrg 	;;
    291          1.1  mrg     esac
    292          1.1  mrg   fi
    293          1.1  mrg   shift
    294          1.1  mrg done
    295          1.1  mrg 
    296          1.1  mrg if test -z "$ofile" || test -z "$cfile"; then
    297  1.1.1.1.8.1  tls   # If no '-o' option was seen then we might have been invoked from a
    298          1.1  mrg   # pattern rule where we don't need one.  That is ok -- this is a
    299          1.1  mrg   # normal compilation that the losing compiler can handle.  If no
    300  1.1.1.1.8.1  tls   # '.c' file was seen then we are probably linking.  That is also
    301          1.1  mrg   # ok.
    302          1.1  mrg   exec "$@"
    303          1.1  mrg fi
    304          1.1  mrg 
    305          1.1  mrg # Name of file we expect compiler to create.
    306          1.1  mrg cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
    307          1.1  mrg 
    308          1.1  mrg # Create the lock directory.
    309  1.1.1.1.8.1  tls # Note: use '[/\\:.-]' here to ensure that we don't use the same name
    310          1.1  mrg # that we are using for the .o file.  Also, base the name on the expected
    311          1.1  mrg # object file name, since that is what matters with a parallel build.
    312          1.1  mrg lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
    313          1.1  mrg while true; do
    314          1.1  mrg   if mkdir "$lockdir" >/dev/null 2>&1; then
    315          1.1  mrg     break
    316          1.1  mrg   fi
    317          1.1  mrg   sleep 1
    318          1.1  mrg done
    319          1.1  mrg # FIXME: race condition here if user kills between mkdir and trap.
    320          1.1  mrg trap "rmdir '$lockdir'; exit 1" 1 2 15
    321          1.1  mrg 
    322          1.1  mrg # Run the compile.
    323          1.1  mrg "$@"
    324          1.1  mrg ret=$?
    325          1.1  mrg 
    326          1.1  mrg if test -f "$cofile"; then
    327          1.1  mrg   test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
    328          1.1  mrg elif test -f "${cofile}bj"; then
    329          1.1  mrg   test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
    330          1.1  mrg fi
    331          1.1  mrg 
    332          1.1  mrg rmdir "$lockdir"
    333          1.1  mrg exit $ret
    334          1.1  mrg 
    335          1.1  mrg # Local Variables:
    336          1.1  mrg # mode: shell-script
    337          1.1  mrg # sh-indentation: 2
    338          1.1  mrg # eval: (add-hook 'write-file-hooks 'time-stamp)
    339          1.1  mrg # time-stamp-start: "scriptversion="
    340          1.1  mrg # time-stamp-format: "%:y-%02m-%02d.%02H"
    341          1.1  mrg # time-stamp-time-zone: "UTC"
    342          1.1  mrg # time-stamp-end: "; # UTC"
    343          1.1  mrg # End:
    344