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