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