Tanguy Pruvot
9 years ago
3 changed files with 660 additions and 591 deletions
@ -1,310 +1,347 @@ |
|||||||
#! /bin/sh |
#! /bin/sh |
||||||
# Wrapper for compilers which do not understand '-c -o'. |
# Wrapper for compilers which do not understand '-c -o'. |
||||||
|
|
||||||
scriptversion=2012-01-04.17; # UTC |
scriptversion=2012-10-14.11; # UTC |
||||||
|
|
||||||
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free |
# Copyright (C) 1999-2013 Free Software Foundation, Inc. |
||||||
# Software Foundation, Inc. |
# Written by Tom Tromey <tromey@cygnus.com>. |
||||||
# Written by Tom Tromey <tromey@cygnus.com>. |
# |
||||||
# |
# This program is free software; you can redistribute it and/or modify |
||||||
# This program is free software; you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
||||||
# it under the terms of the GNU General Public License as published by |
# the Free Software Foundation; either version 2, or (at your option) |
||||||
# the Free Software Foundation; either version 2, or (at your option) |
# any later version. |
||||||
# any later version. |
# |
||||||
# |
# This program is distributed in the hope that it will be useful, |
||||||
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# GNU General Public License for more details. |
||||||
# GNU General Public License for more details. |
# |
||||||
# |
# You should have received a copy of the GNU General Public License |
||||||
# You should have received a copy of the GNU General Public License |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||||
|
# As a special exception to the GNU General Public License, if you |
||||||
# As a special exception to the GNU General Public License, if you |
# distribute this file as part of a program that contains a |
||||||
# distribute this file as part of a program that contains a |
# configuration script generated by Autoconf, you may include it under |
||||||
# configuration script generated by Autoconf, you may include it under |
# the same distribution terms that you use for the rest of that program. |
||||||
# the same distribution terms that you use for the rest of that program. |
|
||||||
|
# This file is maintained in Automake, please report |
||||||
# This file is maintained in Automake, please report |
# bugs to <bug-automake@gnu.org> or send patches to |
||||||
# bugs to <bug-automake@gnu.org> or send patches to |
# <automake-patches@gnu.org>. |
||||||
# <automake-patches@gnu.org>. |
|
||||||
|
nl=' |
||||||
nl=' |
' |
||||||
' |
|
||||||
|
# We need space, tab and new line, in precisely that order. Quoting is |
||||||
# We need space, tab and new line, in precisely that order. Quoting is |
# there to prevent tools from complaining about whitespace usage. |
||||||
# there to prevent tools from complaining about whitespace usage. |
IFS=" "" $nl" |
||||||
IFS=" "" $nl" |
|
||||||
|
file_conv= |
||||||
file_conv= |
|
||||||
|
# func_file_conv build_file lazy |
||||||
# func_file_conv build_file lazy |
# Convert a $build file to $host form and store it in $file |
||||||
# Convert a $build file to $host form and store it in $file |
# Currently only supports Windows hosts. If the determined conversion |
||||||
# Currently only supports Windows hosts. If the determined conversion |
# type is listed in (the comma separated) LAZY, no conversion will |
||||||
# type is listed in (the comma separated) LAZY, no conversion will |
# take place. |
||||||
# take place. |
func_file_conv () |
||||||
func_file_conv () |
{ |
||||||
{ |
file=$1 |
||||||
file=$1 |
case $file in |
||||||
case $file in |
/ | /[!/]*) # absolute file, and not a UNC file |
||||||
/ | /[!/]*) # absolute file, and not a UNC file |
if test -z "$file_conv"; then |
||||||
if test -z "$file_conv"; then |
# lazily determine how to convert abs files |
||||||
# lazily determine how to convert abs files |
case `uname -s` in |
||||||
case `uname -s` in |
MINGW*) |
||||||
MINGW*) |
file_conv=mingw |
||||||
file_conv=mingw |
;; |
||||||
;; |
CYGWIN*) |
||||||
CYGWIN*) |
file_conv=cygwin |
||||||
file_conv=cygwin |
;; |
||||||
;; |
*) |
||||||
*) |
file_conv=wine |
||||||
file_conv=wine |
;; |
||||||
;; |
esac |
||||||
esac |
fi |
||||||
fi |
case $file_conv/,$2, in |
||||||
case $file_conv/,$2, in |
*,$file_conv,*) |
||||||
*,$file_conv,*) |
;; |
||||||
;; |
mingw/*) |
||||||
mingw/*) |
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` |
||||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` |
;; |
||||||
;; |
cygwin/*) |
||||||
cygwin/*) |
file=`cygpath -m "$file" || echo "$file"` |
||||||
file=`cygpath -m "$file" || echo "$file"` |
;; |
||||||
;; |
wine/*) |
||||||
wine/*) |
file=`winepath -w "$file" || echo "$file"` |
||||||
file=`winepath -w "$file" || echo "$file"` |
;; |
||||||
;; |
esac |
||||||
esac |
;; |
||||||
;; |
esac |
||||||
esac |
} |
||||||
} |
|
||||||
|
# func_cl_dashL linkdir |
||||||
# func_cl_wrapper cl arg... |
# Make cl look for libraries in LINKDIR |
||||||
# Adjust compile command to suit cl |
func_cl_dashL () |
||||||
func_cl_wrapper () |
{ |
||||||
{ |
func_file_conv "$1" |
||||||
# Assume a capable shell |
if test -z "$lib_path"; then |
||||||
lib_path= |
lib_path=$file |
||||||
shared=: |
else |
||||||
linker_opts= |
lib_path="$lib_path;$file" |
||||||
for arg |
fi |
||||||
do |
linker_opts="$linker_opts -LIBPATH:$file" |
||||||
if test -n "$eat"; then |
} |
||||||
eat= |
|
||||||
else |
# func_cl_dashl library |
||||||
case $1 in |
# Do a library search-path lookup for cl |
||||||
-o) |
func_cl_dashl () |
||||||
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
{ |
||||||
eat=1 |
lib=$1 |
||||||
case $2 in |
found=no |
||||||
*.o | *.[oO][bB][jJ]) |
save_IFS=$IFS |
||||||
func_file_conv "$2" |
IFS=';' |
||||||
set x "$@" -Fo"$file" |
for dir in $lib_path $LIB |
||||||
shift |
do |
||||||
;; |
IFS=$save_IFS |
||||||
*) |
if $shared && test -f "$dir/$lib.dll.lib"; then |
||||||
func_file_conv "$2" |
found=yes |
||||||
set x "$@" -Fe"$file" |
lib=$dir/$lib.dll.lib |
||||||
shift |
break |
||||||
;; |
fi |
||||||
esac |
if test -f "$dir/$lib.lib"; then |
||||||
;; |
found=yes |
||||||
-I*) |
lib=$dir/$lib.lib |
||||||
func_file_conv "${1#-I}" mingw |
break |
||||||
set x "$@" -I"$file" |
fi |
||||||
shift |
if test -f "$dir/lib$lib.a"; then |
||||||
;; |
found=yes |
||||||
-l*) |
lib=$dir/lib$lib.a |
||||||
lib=${1#-l} |
break |
||||||
found=no |
fi |
||||||
save_IFS=$IFS |
done |
||||||
IFS=';' |
IFS=$save_IFS |
||||||
for dir in $lib_path $LIB |
|
||||||
do |
if test "$found" != yes; then |
||||||
IFS=$save_IFS |
lib=$lib.lib |
||||||
if $shared && test -f "$dir/$lib.dll.lib"; then |
fi |
||||||
found=yes |
} |
||||||
set x "$@" "$dir/$lib.dll.lib" |
|
||||||
break |
# func_cl_wrapper cl arg... |
||||||
fi |
# Adjust compile command to suit cl |
||||||
if test -f "$dir/$lib.lib"; then |
func_cl_wrapper () |
||||||
found=yes |
{ |
||||||
set x "$@" "$dir/$lib.lib" |
# Assume a capable shell |
||||||
break |
lib_path= |
||||||
fi |
shared=: |
||||||
done |
linker_opts= |
||||||
IFS=$save_IFS |
for arg |
||||||
|
do |
||||||
test "$found" != yes && set x "$@" "$lib.lib" |
if test -n "$eat"; then |
||||||
shift |
eat= |
||||||
;; |
else |
||||||
-L*) |
case $1 in |
||||||
func_file_conv "${1#-L}" |
-o) |
||||||
if test -z "$lib_path"; then |
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
||||||
lib_path=$file |
eat=1 |
||||||
else |
case $2 in |
||||||
lib_path="$lib_path;$file" |
*.o | *.[oO][bB][jJ]) |
||||||
fi |
func_file_conv "$2" |
||||||
linker_opts="$linker_opts -LIBPATH:$file" |
set x "$@" -Fo"$file" |
||||||
;; |
shift |
||||||
-static) |
;; |
||||||
shared=false |
*) |
||||||
;; |
func_file_conv "$2" |
||||||
-Wl,*) |
set x "$@" -Fe"$file" |
||||||
arg=${1#-Wl,} |
shift |
||||||
save_ifs="$IFS"; IFS=',' |
;; |
||||||
for flag in $arg; do |
esac |
||||||
IFS="$save_ifs" |
;; |
||||||
linker_opts="$linker_opts $flag" |
-I) |
||||||
done |
eat=1 |
||||||
IFS="$save_ifs" |
func_file_conv "$2" mingw |
||||||
;; |
set x "$@" -I"$file" |
||||||
-Xlinker) |
shift |
||||||
eat=1 |
;; |
||||||
linker_opts="$linker_opts $2" |
-I*) |
||||||
;; |
func_file_conv "${1#-I}" mingw |
||||||
-*) |
set x "$@" -I"$file" |
||||||
set x "$@" "$1" |
shift |
||||||
shift |
;; |
||||||
;; |
-l) |
||||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++) |
eat=1 |
||||||
func_file_conv "$1" |
func_cl_dashl "$2" |
||||||
set x "$@" -Tp"$file" |
set x "$@" "$lib" |
||||||
shift |
shift |
||||||
;; |
;; |
||||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) |
-l*) |
||||||
func_file_conv "$1" mingw |
func_cl_dashl "${1#-l}" |
||||||
set x "$@" "$file" |
set x "$@" "$lib" |
||||||
shift |
shift |
||||||
;; |
;; |
||||||
*) |
-L) |
||||||
set x "$@" "$1" |
eat=1 |
||||||
shift |
func_cl_dashL "$2" |
||||||
;; |
;; |
||||||
esac |
-L*) |
||||||
fi |
func_cl_dashL "${1#-L}" |
||||||
shift |
;; |
||||||
done |
-static) |
||||||
if test -n "$linker_opts"; then |
shared=false |
||||||
linker_opts="-link$linker_opts" |
;; |
||||||
fi |
-Wl,*) |
||||||
exec "$@" $linker_opts |
arg=${1#-Wl,} |
||||||
exit 1 |
save_ifs="$IFS"; IFS=',' |
||||||
} |
for flag in $arg; do |
||||||
|
IFS="$save_ifs" |
||||||
eat= |
linker_opts="$linker_opts $flag" |
||||||
|
done |
||||||
case $1 in |
IFS="$save_ifs" |
||||||
'') |
;; |
||||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2 |
-Xlinker) |
||||||
exit 1; |
eat=1 |
||||||
;; |
linker_opts="$linker_opts $2" |
||||||
-h | --h*) |
;; |
||||||
cat <<\EOF |
-*) |
||||||
Usage: compile [--help] [--version] PROGRAM [ARGS] |
set x "$@" "$1" |
||||||
|
shift |
||||||
Wrapper for compilers which do not understand '-c -o'. |
;; |
||||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining |
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++) |
||||||
arguments, and rename the output as expected. |
func_file_conv "$1" |
||||||
|
set x "$@" -Tp"$file" |
||||||
If you are trying to build a whole package this is not the |
shift |
||||||
right script to run: please start by reading the file 'INSTALL'. |
;; |
||||||
|
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) |
||||||
Report bugs to <bug-automake@gnu.org>. |
func_file_conv "$1" mingw |
||||||
EOF |
set x "$@" "$file" |
||||||
exit $? |
shift |
||||||
;; |
;; |
||||||
-v | --v*) |
*) |
||||||
echo "compile $scriptversion" |
set x "$@" "$1" |
||||||
exit $? |
shift |
||||||
;; |
;; |
||||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) |
esac |
||||||
func_cl_wrapper "$@" # Doesn't return... |
fi |
||||||
;; |
shift |
||||||
esac |
done |
||||||
|
if test -n "$linker_opts"; then |
||||||
ofile= |
linker_opts="-link$linker_opts" |
||||||
cfile= |
fi |
||||||
|
exec "$@" $linker_opts |
||||||
for arg |
exit 1 |
||||||
do |
} |
||||||
if test -n "$eat"; then |
|
||||||
eat= |
eat= |
||||||
else |
|
||||||
case $1 in |
case $1 in |
||||||
-o) |
'') |
||||||
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
echo "$0: No command. Try '$0 --help' for more information." 1>&2 |
||||||
# So we strip '-o arg' only if arg is an object. |
exit 1; |
||||||
eat=1 |
;; |
||||||
case $2 in |
-h | --h*) |
||||||
*.o | *.obj) |
cat <<\EOF |
||||||
ofile=$2 |
Usage: compile [--help] [--version] PROGRAM [ARGS] |
||||||
;; |
|
||||||
*) |
Wrapper for compilers which do not understand '-c -o'. |
||||||
set x "$@" -o "$2" |
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining |
||||||
shift |
arguments, and rename the output as expected. |
||||||
;; |
|
||||||
esac |
If you are trying to build a whole package this is not the |
||||||
;; |
right script to run: please start by reading the file 'INSTALL'. |
||||||
*.c) |
|
||||||
cfile=$1 |
Report bugs to <bug-automake@gnu.org>. |
||||||
set x "$@" "$1" |
EOF |
||||||
shift |
exit $? |
||||||
;; |
;; |
||||||
*) |
-v | --v*) |
||||||
set x "$@" "$1" |
echo "compile $scriptversion" |
||||||
shift |
exit $? |
||||||
;; |
;; |
||||||
esac |
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) |
||||||
fi |
func_cl_wrapper "$@" # Doesn't return... |
||||||
shift |
;; |
||||||
done |
esac |
||||||
|
|
||||||
if test -z "$ofile" || test -z "$cfile"; then |
ofile= |
||||||
# If no '-o' option was seen then we might have been invoked from a |
cfile= |
||||||
# pattern rule where we don't need one. That is ok -- this is a |
|
||||||
# normal compilation that the losing compiler can handle. If no |
for arg |
||||||
# '.c' file was seen then we are probably linking. That is also |
do |
||||||
# ok. |
if test -n "$eat"; then |
||||||
exec "$@" |
eat= |
||||||
fi |
else |
||||||
|
case $1 in |
||||||
# Name of file we expect compiler to create. |
-o) |
||||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` |
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
||||||
|
# So we strip '-o arg' only if arg is an object. |
||||||
# Create the lock directory. |
eat=1 |
||||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name |
case $2 in |
||||||
# that we are using for the .o file. Also, base the name on the expected |
*.o | *.obj) |
||||||
# object file name, since that is what matters with a parallel build. |
ofile=$2 |
||||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d |
;; |
||||||
while true; do |
*) |
||||||
if mkdir "$lockdir" >/dev/null 2>&1; then |
set x "$@" -o "$2" |
||||||
break |
shift |
||||||
fi |
;; |
||||||
sleep 1 |
esac |
||||||
done |
;; |
||||||
# FIXME: race condition here if user kills between mkdir and trap. |
*.c) |
||||||
trap "rmdir '$lockdir'; exit 1" 1 2 15 |
cfile=$1 |
||||||
|
set x "$@" "$1" |
||||||
# Run the compile. |
shift |
||||||
"$@" |
;; |
||||||
ret=$? |
*) |
||||||
|
set x "$@" "$1" |
||||||
if test -f "$cofile"; then |
shift |
||||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile" |
;; |
||||||
elif test -f "${cofile}bj"; then |
esac |
||||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" |
fi |
||||||
fi |
shift |
||||||
|
done |
||||||
rmdir "$lockdir" |
|
||||||
exit $ret |
if test -z "$ofile" || test -z "$cfile"; then |
||||||
|
# If no '-o' option was seen then we might have been invoked from a |
||||||
# Local Variables: |
# pattern rule where we don't need one. That is ok -- this is a |
||||||
# mode: shell-script |
# normal compilation that the losing compiler can handle. If no |
||||||
# sh-indentation: 2 |
# '.c' file was seen then we are probably linking. That is also |
||||||
# eval: (add-hook 'write-file-hooks 'time-stamp) |
# ok. |
||||||
# time-stamp-start: "scriptversion=" |
exec "$@" |
||||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
fi |
||||||
# time-stamp-time-zone: "UTC" |
|
||||||
# time-stamp-end: "; # UTC" |
# Name of file we expect compiler to create. |
||||||
# End: |
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` |
||||||
|
|
||||||
|
# Create the lock directory. |
||||||
|
# Note: use '[/\\:.-]' here to ensure that we don't use the same name |
||||||
|
# that we are using for the .o file. Also, base the name on the expected |
||||||
|
# object file name, since that is what matters with a parallel build. |
||||||
|
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d |
||||||
|
while true; do |
||||||
|
if mkdir "$lockdir" >/dev/null 2>&1; then |
||||||
|
break |
||||||
|
fi |
||||||
|
sleep 1 |
||||||
|
done |
||||||
|
# FIXME: race condition here if user kills between mkdir and trap. |
||||||
|
trap "rmdir '$lockdir'; exit 1" 1 2 15 |
||||||
|
|
||||||
|
# Run the compile. |
||||||
|
"$@" |
||||||
|
ret=$? |
||||||
|
|
||||||
|
if test -f "$cofile"; then |
||||||
|
test "$cofile" = "$ofile" || mv "$cofile" "$ofile" |
||||||
|
elif test -f "${cofile}bj"; then |
||||||
|
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" |
||||||
|
fi |
||||||
|
|
||||||
|
rmdir "$lockdir" |
||||||
|
exit $ret |
||||||
|
|
||||||
|
# Local Variables: |
||||||
|
# mode: shell-script |
||||||
|
# sh-indentation: 2 |
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp) |
||||||
|
# time-stamp-start: "scriptversion=" |
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||||
|
# time-stamp-time-zone: "UTC" |
||||||
|
# time-stamp-end: "; # UTC" |
||||||
|
# End: |
||||||
|
Loading…
Reference in new issue