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