11cb0ef41Sopenharmony_ci#! /bin/sh 21cb0ef41Sopenharmony_ci# Wrapper for compilers which do not understand '-c -o'. 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciscriptversion=2018-03-07.03; # UTC 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci# Copyright (C) 1999-2021 Free Software Foundation, Inc. 71cb0ef41Sopenharmony_ci# Written by Tom Tromey <tromey@cygnus.com>. 81cb0ef41Sopenharmony_ci# 91cb0ef41Sopenharmony_ci# This program is free software; you can redistribute it and/or modify 101cb0ef41Sopenharmony_ci# it under the terms of the GNU General Public License as published by 111cb0ef41Sopenharmony_ci# the Free Software Foundation; either version 2, or (at your option) 121cb0ef41Sopenharmony_ci# any later version. 131cb0ef41Sopenharmony_ci# 141cb0ef41Sopenharmony_ci# This program is distributed in the hope that it will be useful, 151cb0ef41Sopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of 161cb0ef41Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171cb0ef41Sopenharmony_ci# GNU General Public License for more details. 181cb0ef41Sopenharmony_ci# 191cb0ef41Sopenharmony_ci# You should have received a copy of the GNU General Public License 201cb0ef41Sopenharmony_ci# along with this program. If not, see <https://www.gnu.org/licenses/>. 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci# As a special exception to the GNU General Public License, if you 231cb0ef41Sopenharmony_ci# distribute this file as part of a program that contains a 241cb0ef41Sopenharmony_ci# configuration script generated by Autoconf, you may include it under 251cb0ef41Sopenharmony_ci# the same distribution terms that you use for the rest of that program. 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci# This file is maintained in Automake, please report 281cb0ef41Sopenharmony_ci# bugs to <bug-automake@gnu.org> or send patches to 291cb0ef41Sopenharmony_ci# <automake-patches@gnu.org>. 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cinl=' 321cb0ef41Sopenharmony_ci' 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci# We need space, tab and new line, in precisely that order. Quoting is 351cb0ef41Sopenharmony_ci# there to prevent tools from complaining about whitespace usage. 361cb0ef41Sopenharmony_ciIFS=" "" $nl" 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_cifile_conv= 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci# func_file_conv build_file lazy 411cb0ef41Sopenharmony_ci# Convert a $build file to $host form and store it in $file 421cb0ef41Sopenharmony_ci# Currently only supports Windows hosts. If the determined conversion 431cb0ef41Sopenharmony_ci# type is listed in (the comma separated) LAZY, no conversion will 441cb0ef41Sopenharmony_ci# take place. 451cb0ef41Sopenharmony_cifunc_file_conv () 461cb0ef41Sopenharmony_ci{ 471cb0ef41Sopenharmony_ci file=$1 481cb0ef41Sopenharmony_ci case $file in 491cb0ef41Sopenharmony_ci / | /[!/]*) # absolute file, and not a UNC file 501cb0ef41Sopenharmony_ci if test -z "$file_conv"; then 511cb0ef41Sopenharmony_ci # lazily determine how to convert abs files 521cb0ef41Sopenharmony_ci case `uname -s` in 531cb0ef41Sopenharmony_ci MINGW*) 541cb0ef41Sopenharmony_ci file_conv=mingw 551cb0ef41Sopenharmony_ci ;; 561cb0ef41Sopenharmony_ci CYGWIN* | MSYS*) 571cb0ef41Sopenharmony_ci file_conv=cygwin 581cb0ef41Sopenharmony_ci ;; 591cb0ef41Sopenharmony_ci *) 601cb0ef41Sopenharmony_ci file_conv=wine 611cb0ef41Sopenharmony_ci ;; 621cb0ef41Sopenharmony_ci esac 631cb0ef41Sopenharmony_ci fi 641cb0ef41Sopenharmony_ci case $file_conv/,$2, in 651cb0ef41Sopenharmony_ci *,$file_conv,*) 661cb0ef41Sopenharmony_ci ;; 671cb0ef41Sopenharmony_ci mingw/*) 681cb0ef41Sopenharmony_ci file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 691cb0ef41Sopenharmony_ci ;; 701cb0ef41Sopenharmony_ci cygwin/* | msys/*) 711cb0ef41Sopenharmony_ci file=`cygpath -m "$file" || echo "$file"` 721cb0ef41Sopenharmony_ci ;; 731cb0ef41Sopenharmony_ci wine/*) 741cb0ef41Sopenharmony_ci file=`winepath -w "$file" || echo "$file"` 751cb0ef41Sopenharmony_ci ;; 761cb0ef41Sopenharmony_ci esac 771cb0ef41Sopenharmony_ci ;; 781cb0ef41Sopenharmony_ci esac 791cb0ef41Sopenharmony_ci} 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci# func_cl_dashL linkdir 821cb0ef41Sopenharmony_ci# Make cl look for libraries in LINKDIR 831cb0ef41Sopenharmony_cifunc_cl_dashL () 841cb0ef41Sopenharmony_ci{ 851cb0ef41Sopenharmony_ci func_file_conv "$1" 861cb0ef41Sopenharmony_ci if test -z "$lib_path"; then 871cb0ef41Sopenharmony_ci lib_path=$file 881cb0ef41Sopenharmony_ci else 891cb0ef41Sopenharmony_ci lib_path="$lib_path;$file" 901cb0ef41Sopenharmony_ci fi 911cb0ef41Sopenharmony_ci linker_opts="$linker_opts -LIBPATH:$file" 921cb0ef41Sopenharmony_ci} 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci# func_cl_dashl library 951cb0ef41Sopenharmony_ci# Do a library search-path lookup for cl 961cb0ef41Sopenharmony_cifunc_cl_dashl () 971cb0ef41Sopenharmony_ci{ 981cb0ef41Sopenharmony_ci lib=$1 991cb0ef41Sopenharmony_ci found=no 1001cb0ef41Sopenharmony_ci save_IFS=$IFS 1011cb0ef41Sopenharmony_ci IFS=';' 1021cb0ef41Sopenharmony_ci for dir in $lib_path $LIB 1031cb0ef41Sopenharmony_ci do 1041cb0ef41Sopenharmony_ci IFS=$save_IFS 1051cb0ef41Sopenharmony_ci if $shared && test -f "$dir/$lib.dll.lib"; then 1061cb0ef41Sopenharmony_ci found=yes 1071cb0ef41Sopenharmony_ci lib=$dir/$lib.dll.lib 1081cb0ef41Sopenharmony_ci break 1091cb0ef41Sopenharmony_ci fi 1101cb0ef41Sopenharmony_ci if test -f "$dir/$lib.lib"; then 1111cb0ef41Sopenharmony_ci found=yes 1121cb0ef41Sopenharmony_ci lib=$dir/$lib.lib 1131cb0ef41Sopenharmony_ci break 1141cb0ef41Sopenharmony_ci fi 1151cb0ef41Sopenharmony_ci if test -f "$dir/lib$lib.a"; then 1161cb0ef41Sopenharmony_ci found=yes 1171cb0ef41Sopenharmony_ci lib=$dir/lib$lib.a 1181cb0ef41Sopenharmony_ci break 1191cb0ef41Sopenharmony_ci fi 1201cb0ef41Sopenharmony_ci done 1211cb0ef41Sopenharmony_ci IFS=$save_IFS 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci if test "$found" != yes; then 1241cb0ef41Sopenharmony_ci lib=$lib.lib 1251cb0ef41Sopenharmony_ci fi 1261cb0ef41Sopenharmony_ci} 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci# func_cl_wrapper cl arg... 1291cb0ef41Sopenharmony_ci# Adjust compile command to suit cl 1301cb0ef41Sopenharmony_cifunc_cl_wrapper () 1311cb0ef41Sopenharmony_ci{ 1321cb0ef41Sopenharmony_ci # Assume a capable shell 1331cb0ef41Sopenharmony_ci lib_path= 1341cb0ef41Sopenharmony_ci shared=: 1351cb0ef41Sopenharmony_ci linker_opts= 1361cb0ef41Sopenharmony_ci for arg 1371cb0ef41Sopenharmony_ci do 1381cb0ef41Sopenharmony_ci if test -n "$eat"; then 1391cb0ef41Sopenharmony_ci eat= 1401cb0ef41Sopenharmony_ci else 1411cb0ef41Sopenharmony_ci case $1 in 1421cb0ef41Sopenharmony_ci -o) 1431cb0ef41Sopenharmony_ci # configure might choose to run compile as 'compile cc -o foo foo.c'. 1441cb0ef41Sopenharmony_ci eat=1 1451cb0ef41Sopenharmony_ci case $2 in 1461cb0ef41Sopenharmony_ci *.o | *.[oO][bB][jJ]) 1471cb0ef41Sopenharmony_ci func_file_conv "$2" 1481cb0ef41Sopenharmony_ci set x "$@" -Fo"$file" 1491cb0ef41Sopenharmony_ci shift 1501cb0ef41Sopenharmony_ci ;; 1511cb0ef41Sopenharmony_ci *) 1521cb0ef41Sopenharmony_ci func_file_conv "$2" 1531cb0ef41Sopenharmony_ci set x "$@" -Fe"$file" 1541cb0ef41Sopenharmony_ci shift 1551cb0ef41Sopenharmony_ci ;; 1561cb0ef41Sopenharmony_ci esac 1571cb0ef41Sopenharmony_ci ;; 1581cb0ef41Sopenharmony_ci -I) 1591cb0ef41Sopenharmony_ci eat=1 1601cb0ef41Sopenharmony_ci func_file_conv "$2" mingw 1611cb0ef41Sopenharmony_ci set x "$@" -I"$file" 1621cb0ef41Sopenharmony_ci shift 1631cb0ef41Sopenharmony_ci ;; 1641cb0ef41Sopenharmony_ci -I*) 1651cb0ef41Sopenharmony_ci func_file_conv "${1#-I}" mingw 1661cb0ef41Sopenharmony_ci set x "$@" -I"$file" 1671cb0ef41Sopenharmony_ci shift 1681cb0ef41Sopenharmony_ci ;; 1691cb0ef41Sopenharmony_ci -l) 1701cb0ef41Sopenharmony_ci eat=1 1711cb0ef41Sopenharmony_ci func_cl_dashl "$2" 1721cb0ef41Sopenharmony_ci set x "$@" "$lib" 1731cb0ef41Sopenharmony_ci shift 1741cb0ef41Sopenharmony_ci ;; 1751cb0ef41Sopenharmony_ci -l*) 1761cb0ef41Sopenharmony_ci func_cl_dashl "${1#-l}" 1771cb0ef41Sopenharmony_ci set x "$@" "$lib" 1781cb0ef41Sopenharmony_ci shift 1791cb0ef41Sopenharmony_ci ;; 1801cb0ef41Sopenharmony_ci -L) 1811cb0ef41Sopenharmony_ci eat=1 1821cb0ef41Sopenharmony_ci func_cl_dashL "$2" 1831cb0ef41Sopenharmony_ci ;; 1841cb0ef41Sopenharmony_ci -L*) 1851cb0ef41Sopenharmony_ci func_cl_dashL "${1#-L}" 1861cb0ef41Sopenharmony_ci ;; 1871cb0ef41Sopenharmony_ci -static) 1881cb0ef41Sopenharmony_ci shared=false 1891cb0ef41Sopenharmony_ci ;; 1901cb0ef41Sopenharmony_ci -Wl,*) 1911cb0ef41Sopenharmony_ci arg=${1#-Wl,} 1921cb0ef41Sopenharmony_ci save_ifs="$IFS"; IFS=',' 1931cb0ef41Sopenharmony_ci for flag in $arg; do 1941cb0ef41Sopenharmony_ci IFS="$save_ifs" 1951cb0ef41Sopenharmony_ci linker_opts="$linker_opts $flag" 1961cb0ef41Sopenharmony_ci done 1971cb0ef41Sopenharmony_ci IFS="$save_ifs" 1981cb0ef41Sopenharmony_ci ;; 1991cb0ef41Sopenharmony_ci -Xlinker) 2001cb0ef41Sopenharmony_ci eat=1 2011cb0ef41Sopenharmony_ci linker_opts="$linker_opts $2" 2021cb0ef41Sopenharmony_ci ;; 2031cb0ef41Sopenharmony_ci -*) 2041cb0ef41Sopenharmony_ci set x "$@" "$1" 2051cb0ef41Sopenharmony_ci shift 2061cb0ef41Sopenharmony_ci ;; 2071cb0ef41Sopenharmony_ci *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2081cb0ef41Sopenharmony_ci func_file_conv "$1" 2091cb0ef41Sopenharmony_ci set x "$@" -Tp"$file" 2101cb0ef41Sopenharmony_ci shift 2111cb0ef41Sopenharmony_ci ;; 2121cb0ef41Sopenharmony_ci *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2131cb0ef41Sopenharmony_ci func_file_conv "$1" mingw 2141cb0ef41Sopenharmony_ci set x "$@" "$file" 2151cb0ef41Sopenharmony_ci shift 2161cb0ef41Sopenharmony_ci ;; 2171cb0ef41Sopenharmony_ci *) 2181cb0ef41Sopenharmony_ci set x "$@" "$1" 2191cb0ef41Sopenharmony_ci shift 2201cb0ef41Sopenharmony_ci ;; 2211cb0ef41Sopenharmony_ci esac 2221cb0ef41Sopenharmony_ci fi 2231cb0ef41Sopenharmony_ci shift 2241cb0ef41Sopenharmony_ci done 2251cb0ef41Sopenharmony_ci if test -n "$linker_opts"; then 2261cb0ef41Sopenharmony_ci linker_opts="-link$linker_opts" 2271cb0ef41Sopenharmony_ci fi 2281cb0ef41Sopenharmony_ci exec "$@" $linker_opts 2291cb0ef41Sopenharmony_ci exit 1 2301cb0ef41Sopenharmony_ci} 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_cieat= 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_cicase $1 in 2351cb0ef41Sopenharmony_ci '') 2361cb0ef41Sopenharmony_ci echo "$0: No command. Try '$0 --help' for more information." 1>&2 2371cb0ef41Sopenharmony_ci exit 1; 2381cb0ef41Sopenharmony_ci ;; 2391cb0ef41Sopenharmony_ci -h | --h*) 2401cb0ef41Sopenharmony_ci cat <<\EOF 2411cb0ef41Sopenharmony_ciUsage: compile [--help] [--version] PROGRAM [ARGS] 2421cb0ef41Sopenharmony_ci 2431cb0ef41Sopenharmony_ciWrapper for compilers which do not understand '-c -o'. 2441cb0ef41Sopenharmony_ciRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2451cb0ef41Sopenharmony_ciarguments, and rename the output as expected. 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ciIf you are trying to build a whole package this is not the 2481cb0ef41Sopenharmony_ciright script to run: please start by reading the file 'INSTALL'. 2491cb0ef41Sopenharmony_ci 2501cb0ef41Sopenharmony_ciReport bugs to <bug-automake@gnu.org>. 2511cb0ef41Sopenharmony_ciEOF 2521cb0ef41Sopenharmony_ci exit $? 2531cb0ef41Sopenharmony_ci ;; 2541cb0ef41Sopenharmony_ci -v | --v*) 2551cb0ef41Sopenharmony_ci echo "compile $scriptversion" 2561cb0ef41Sopenharmony_ci exit $? 2571cb0ef41Sopenharmony_ci ;; 2581cb0ef41Sopenharmony_ci cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2591cb0ef41Sopenharmony_ci icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2601cb0ef41Sopenharmony_ci func_cl_wrapper "$@" # Doesn't return... 2611cb0ef41Sopenharmony_ci ;; 2621cb0ef41Sopenharmony_ciesac 2631cb0ef41Sopenharmony_ci 2641cb0ef41Sopenharmony_ciofile= 2651cb0ef41Sopenharmony_cicfile= 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_cifor arg 2681cb0ef41Sopenharmony_cido 2691cb0ef41Sopenharmony_ci if test -n "$eat"; then 2701cb0ef41Sopenharmony_ci eat= 2711cb0ef41Sopenharmony_ci else 2721cb0ef41Sopenharmony_ci case $1 in 2731cb0ef41Sopenharmony_ci -o) 2741cb0ef41Sopenharmony_ci # configure might choose to run compile as 'compile cc -o foo foo.c'. 2751cb0ef41Sopenharmony_ci # So we strip '-o arg' only if arg is an object. 2761cb0ef41Sopenharmony_ci eat=1 2771cb0ef41Sopenharmony_ci case $2 in 2781cb0ef41Sopenharmony_ci *.o | *.obj) 2791cb0ef41Sopenharmony_ci ofile=$2 2801cb0ef41Sopenharmony_ci ;; 2811cb0ef41Sopenharmony_ci *) 2821cb0ef41Sopenharmony_ci set x "$@" -o "$2" 2831cb0ef41Sopenharmony_ci shift 2841cb0ef41Sopenharmony_ci ;; 2851cb0ef41Sopenharmony_ci esac 2861cb0ef41Sopenharmony_ci ;; 2871cb0ef41Sopenharmony_ci *.c) 2881cb0ef41Sopenharmony_ci cfile=$1 2891cb0ef41Sopenharmony_ci set x "$@" "$1" 2901cb0ef41Sopenharmony_ci shift 2911cb0ef41Sopenharmony_ci ;; 2921cb0ef41Sopenharmony_ci *) 2931cb0ef41Sopenharmony_ci set x "$@" "$1" 2941cb0ef41Sopenharmony_ci shift 2951cb0ef41Sopenharmony_ci ;; 2961cb0ef41Sopenharmony_ci esac 2971cb0ef41Sopenharmony_ci fi 2981cb0ef41Sopenharmony_ci shift 2991cb0ef41Sopenharmony_cidone 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_ciif test -z "$ofile" || test -z "$cfile"; then 3021cb0ef41Sopenharmony_ci # If no '-o' option was seen then we might have been invoked from a 3031cb0ef41Sopenharmony_ci # pattern rule where we don't need one. That is ok -- this is a 3041cb0ef41Sopenharmony_ci # normal compilation that the losing compiler can handle. If no 3051cb0ef41Sopenharmony_ci # '.c' file was seen then we are probably linking. That is also 3061cb0ef41Sopenharmony_ci # ok. 3071cb0ef41Sopenharmony_ci exec "$@" 3081cb0ef41Sopenharmony_cifi 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci# Name of file we expect compiler to create. 3111cb0ef41Sopenharmony_cicofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ci# Create the lock directory. 3141cb0ef41Sopenharmony_ci# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3151cb0ef41Sopenharmony_ci# that we are using for the .o file. Also, base the name on the expected 3161cb0ef41Sopenharmony_ci# object file name, since that is what matters with a parallel build. 3171cb0ef41Sopenharmony_cilockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3181cb0ef41Sopenharmony_ciwhile true; do 3191cb0ef41Sopenharmony_ci if mkdir "$lockdir" >/dev/null 2>&1; then 3201cb0ef41Sopenharmony_ci break 3211cb0ef41Sopenharmony_ci fi 3221cb0ef41Sopenharmony_ci sleep 1 3231cb0ef41Sopenharmony_cidone 3241cb0ef41Sopenharmony_ci# FIXME: race condition here if user kills between mkdir and trap. 3251cb0ef41Sopenharmony_citrap "rmdir '$lockdir'; exit 1" 1 2 15 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_ci# Run the compile. 3281cb0ef41Sopenharmony_ci"$@" 3291cb0ef41Sopenharmony_ciret=$? 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ciif test -f "$cofile"; then 3321cb0ef41Sopenharmony_ci test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3331cb0ef41Sopenharmony_cielif test -f "${cofile}bj"; then 3341cb0ef41Sopenharmony_ci test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3351cb0ef41Sopenharmony_cifi 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_cirmdir "$lockdir" 3381cb0ef41Sopenharmony_ciexit $ret 3391cb0ef41Sopenharmony_ci 3401cb0ef41Sopenharmony_ci# Local Variables: 3411cb0ef41Sopenharmony_ci# mode: shell-script 3421cb0ef41Sopenharmony_ci# sh-indentation: 2 3431cb0ef41Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp) 3441cb0ef41Sopenharmony_ci# time-stamp-start: "scriptversion=" 3451cb0ef41Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H" 3461cb0ef41Sopenharmony_ci# time-stamp-time-zone: "UTC0" 3471cb0ef41Sopenharmony_ci# time-stamp-end: "; # UTC" 3481cb0ef41Sopenharmony_ci# End: 349