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