xref: /netbsd-src/external/bsd/openpam/dist/compile (revision 024a2e8c049a7132c2274c1f5271ae54063f3c4d)
10bbc3b9fSchristos#! /bin/sh
20bbc3b9fSchristos# Wrapper for compilers which do not understand '-c -o'.
30bbc3b9fSchristos
477513ecfSchristosscriptversion=2018-03-07.03; # UTC
50bbc3b9fSchristos
6*024a2e8cSchristos# Copyright (C) 1999-2021 Free Software Foundation, Inc.
70bbc3b9fSchristos# Written by Tom Tromey <tromey@cygnus.com>.
80bbc3b9fSchristos#
90bbc3b9fSchristos# This program is free software; you can redistribute it and/or modify
100bbc3b9fSchristos# it under the terms of the GNU General Public License as published by
110bbc3b9fSchristos# the Free Software Foundation; either version 2, or (at your option)
120bbc3b9fSchristos# any later version.
130bbc3b9fSchristos#
140bbc3b9fSchristos# This program is distributed in the hope that it will be useful,
150bbc3b9fSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
160bbc3b9fSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
170bbc3b9fSchristos# GNU General Public License for more details.
180bbc3b9fSchristos#
190bbc3b9fSchristos# You should have received a copy of the GNU General Public License
2077513ecfSchristos# along with this program.  If not, see <https://www.gnu.org/licenses/>.
210bbc3b9fSchristos
220bbc3b9fSchristos# As a special exception to the GNU General Public License, if you
230bbc3b9fSchristos# distribute this file as part of a program that contains a
240bbc3b9fSchristos# configuration script generated by Autoconf, you may include it under
250bbc3b9fSchristos# the same distribution terms that you use for the rest of that program.
260bbc3b9fSchristos
270bbc3b9fSchristos# This file is maintained in Automake, please report
280bbc3b9fSchristos# bugs to <bug-automake@gnu.org> or send patches to
290bbc3b9fSchristos# <automake-patches@gnu.org>.
300bbc3b9fSchristos
310bbc3b9fSchristosnl='
320bbc3b9fSchristos'
330bbc3b9fSchristos
340bbc3b9fSchristos# We need space, tab and new line, in precisely that order.  Quoting is
350bbc3b9fSchristos# there to prevent tools from complaining about whitespace usage.
360bbc3b9fSchristosIFS=" ""	$nl"
370bbc3b9fSchristos
380bbc3b9fSchristosfile_conv=
390bbc3b9fSchristos
400bbc3b9fSchristos# func_file_conv build_file lazy
410bbc3b9fSchristos# Convert a $build file to $host form and store it in $file
420bbc3b9fSchristos# Currently only supports Windows hosts. If the determined conversion
430bbc3b9fSchristos# type is listed in (the comma separated) LAZY, no conversion will
440bbc3b9fSchristos# take place.
450bbc3b9fSchristosfunc_file_conv ()
460bbc3b9fSchristos{
470bbc3b9fSchristos  file=$1
480bbc3b9fSchristos  case $file in
490bbc3b9fSchristos    / | /[!/]*) # absolute file, and not a UNC file
500bbc3b9fSchristos      if test -z "$file_conv"; then
510bbc3b9fSchristos	# lazily determine how to convert abs files
520bbc3b9fSchristos	case `uname -s` in
530bbc3b9fSchristos	  MINGW*)
540bbc3b9fSchristos	    file_conv=mingw
550bbc3b9fSchristos	    ;;
56*024a2e8cSchristos	  CYGWIN* | MSYS*)
570bbc3b9fSchristos	    file_conv=cygwin
580bbc3b9fSchristos	    ;;
590bbc3b9fSchristos	  *)
600bbc3b9fSchristos	    file_conv=wine
610bbc3b9fSchristos	    ;;
620bbc3b9fSchristos	esac
630bbc3b9fSchristos      fi
640bbc3b9fSchristos      case $file_conv/,$2, in
650bbc3b9fSchristos	*,$file_conv,*)
660bbc3b9fSchristos	  ;;
670bbc3b9fSchristos	mingw/*)
680bbc3b9fSchristos	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
690bbc3b9fSchristos	  ;;
70*024a2e8cSchristos	cygwin/* | msys/*)
710bbc3b9fSchristos	  file=`cygpath -m "$file" || echo "$file"`
720bbc3b9fSchristos	  ;;
730bbc3b9fSchristos	wine/*)
740bbc3b9fSchristos	  file=`winepath -w "$file" || echo "$file"`
750bbc3b9fSchristos	  ;;
760bbc3b9fSchristos      esac
770bbc3b9fSchristos      ;;
780bbc3b9fSchristos  esac
790bbc3b9fSchristos}
800bbc3b9fSchristos
810bbc3b9fSchristos# func_cl_dashL linkdir
820bbc3b9fSchristos# Make cl look for libraries in LINKDIR
830bbc3b9fSchristosfunc_cl_dashL ()
840bbc3b9fSchristos{
850bbc3b9fSchristos  func_file_conv "$1"
860bbc3b9fSchristos  if test -z "$lib_path"; then
870bbc3b9fSchristos    lib_path=$file
880bbc3b9fSchristos  else
890bbc3b9fSchristos    lib_path="$lib_path;$file"
900bbc3b9fSchristos  fi
910bbc3b9fSchristos  linker_opts="$linker_opts -LIBPATH:$file"
920bbc3b9fSchristos}
930bbc3b9fSchristos
940bbc3b9fSchristos# func_cl_dashl library
950bbc3b9fSchristos# Do a library search-path lookup for cl
960bbc3b9fSchristosfunc_cl_dashl ()
970bbc3b9fSchristos{
980bbc3b9fSchristos  lib=$1
990bbc3b9fSchristos  found=no
1000bbc3b9fSchristos  save_IFS=$IFS
1010bbc3b9fSchristos  IFS=';'
1020bbc3b9fSchristos  for dir in $lib_path $LIB
1030bbc3b9fSchristos  do
1040bbc3b9fSchristos    IFS=$save_IFS
1050bbc3b9fSchristos    if $shared && test -f "$dir/$lib.dll.lib"; then
1060bbc3b9fSchristos      found=yes
1070bbc3b9fSchristos      lib=$dir/$lib.dll.lib
1080bbc3b9fSchristos      break
1090bbc3b9fSchristos    fi
1100bbc3b9fSchristos    if test -f "$dir/$lib.lib"; then
1110bbc3b9fSchristos      found=yes
1120bbc3b9fSchristos      lib=$dir/$lib.lib
1130bbc3b9fSchristos      break
1140bbc3b9fSchristos    fi
1150bbc3b9fSchristos    if test -f "$dir/lib$lib.a"; then
1160bbc3b9fSchristos      found=yes
1170bbc3b9fSchristos      lib=$dir/lib$lib.a
1180bbc3b9fSchristos      break
1190bbc3b9fSchristos    fi
1200bbc3b9fSchristos  done
1210bbc3b9fSchristos  IFS=$save_IFS
1220bbc3b9fSchristos
1230bbc3b9fSchristos  if test "$found" != yes; then
1240bbc3b9fSchristos    lib=$lib.lib
1250bbc3b9fSchristos  fi
1260bbc3b9fSchristos}
1270bbc3b9fSchristos
1280bbc3b9fSchristos# func_cl_wrapper cl arg...
1290bbc3b9fSchristos# Adjust compile command to suit cl
1300bbc3b9fSchristosfunc_cl_wrapper ()
1310bbc3b9fSchristos{
1320bbc3b9fSchristos  # Assume a capable shell
1330bbc3b9fSchristos  lib_path=
1340bbc3b9fSchristos  shared=:
1350bbc3b9fSchristos  linker_opts=
1360bbc3b9fSchristos  for arg
1370bbc3b9fSchristos  do
1380bbc3b9fSchristos    if test -n "$eat"; then
1390bbc3b9fSchristos      eat=
1400bbc3b9fSchristos    else
1410bbc3b9fSchristos      case $1 in
1420bbc3b9fSchristos	-o)
1430bbc3b9fSchristos	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
1440bbc3b9fSchristos	  eat=1
1450bbc3b9fSchristos	  case $2 in
1460bbc3b9fSchristos	    *.o | *.[oO][bB][jJ])
1470bbc3b9fSchristos	      func_file_conv "$2"
1480bbc3b9fSchristos	      set x "$@" -Fo"$file"
1490bbc3b9fSchristos	      shift
1500bbc3b9fSchristos	      ;;
1510bbc3b9fSchristos	    *)
1520bbc3b9fSchristos	      func_file_conv "$2"
1530bbc3b9fSchristos	      set x "$@" -Fe"$file"
1540bbc3b9fSchristos	      shift
1550bbc3b9fSchristos	      ;;
1560bbc3b9fSchristos	  esac
1570bbc3b9fSchristos	  ;;
1580bbc3b9fSchristos	-I)
1590bbc3b9fSchristos	  eat=1
1600bbc3b9fSchristos	  func_file_conv "$2" mingw
1610bbc3b9fSchristos	  set x "$@" -I"$file"
1620bbc3b9fSchristos	  shift
1630bbc3b9fSchristos	  ;;
1640bbc3b9fSchristos	-I*)
1650bbc3b9fSchristos	  func_file_conv "${1#-I}" mingw
1660bbc3b9fSchristos	  set x "$@" -I"$file"
1670bbc3b9fSchristos	  shift
1680bbc3b9fSchristos	  ;;
1690bbc3b9fSchristos	-l)
1700bbc3b9fSchristos	  eat=1
1710bbc3b9fSchristos	  func_cl_dashl "$2"
1720bbc3b9fSchristos	  set x "$@" "$lib"
1730bbc3b9fSchristos	  shift
1740bbc3b9fSchristos	  ;;
1750bbc3b9fSchristos	-l*)
1760bbc3b9fSchristos	  func_cl_dashl "${1#-l}"
1770bbc3b9fSchristos	  set x "$@" "$lib"
1780bbc3b9fSchristos	  shift
1790bbc3b9fSchristos	  ;;
1800bbc3b9fSchristos	-L)
1810bbc3b9fSchristos	  eat=1
1820bbc3b9fSchristos	  func_cl_dashL "$2"
1830bbc3b9fSchristos	  ;;
1840bbc3b9fSchristos	-L*)
1850bbc3b9fSchristos	  func_cl_dashL "${1#-L}"
1860bbc3b9fSchristos	  ;;
1870bbc3b9fSchristos	-static)
1880bbc3b9fSchristos	  shared=false
1890bbc3b9fSchristos	  ;;
1900bbc3b9fSchristos	-Wl,*)
1910bbc3b9fSchristos	  arg=${1#-Wl,}
1920bbc3b9fSchristos	  save_ifs="$IFS"; IFS=','
1930bbc3b9fSchristos	  for flag in $arg; do
1940bbc3b9fSchristos	    IFS="$save_ifs"
1950bbc3b9fSchristos	    linker_opts="$linker_opts $flag"
1960bbc3b9fSchristos	  done
1970bbc3b9fSchristos	  IFS="$save_ifs"
1980bbc3b9fSchristos	  ;;
1990bbc3b9fSchristos	-Xlinker)
2000bbc3b9fSchristos	  eat=1
2010bbc3b9fSchristos	  linker_opts="$linker_opts $2"
2020bbc3b9fSchristos	  ;;
2030bbc3b9fSchristos	-*)
2040bbc3b9fSchristos	  set x "$@" "$1"
2050bbc3b9fSchristos	  shift
2060bbc3b9fSchristos	  ;;
2070bbc3b9fSchristos	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
2080bbc3b9fSchristos	  func_file_conv "$1"
2090bbc3b9fSchristos	  set x "$@" -Tp"$file"
2100bbc3b9fSchristos	  shift
2110bbc3b9fSchristos	  ;;
2120bbc3b9fSchristos	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
2130bbc3b9fSchristos	  func_file_conv "$1" mingw
2140bbc3b9fSchristos	  set x "$@" "$file"
2150bbc3b9fSchristos	  shift
2160bbc3b9fSchristos	  ;;
2170bbc3b9fSchristos	*)
2180bbc3b9fSchristos	  set x "$@" "$1"
2190bbc3b9fSchristos	  shift
2200bbc3b9fSchristos	  ;;
2210bbc3b9fSchristos      esac
2220bbc3b9fSchristos    fi
2230bbc3b9fSchristos    shift
2240bbc3b9fSchristos  done
2250bbc3b9fSchristos  if test -n "$linker_opts"; then
2260bbc3b9fSchristos    linker_opts="-link$linker_opts"
2270bbc3b9fSchristos  fi
2280bbc3b9fSchristos  exec "$@" $linker_opts
2290bbc3b9fSchristos  exit 1
2300bbc3b9fSchristos}
2310bbc3b9fSchristos
2320bbc3b9fSchristoseat=
2330bbc3b9fSchristos
2340bbc3b9fSchristoscase $1 in
2350bbc3b9fSchristos  '')
2360bbc3b9fSchristos     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2370bbc3b9fSchristos     exit 1;
2380bbc3b9fSchristos     ;;
2390bbc3b9fSchristos  -h | --h*)
2400bbc3b9fSchristos    cat <<\EOF
2410bbc3b9fSchristosUsage: compile [--help] [--version] PROGRAM [ARGS]
2420bbc3b9fSchristos
2430bbc3b9fSchristosWrapper for compilers which do not understand '-c -o'.
2440bbc3b9fSchristosRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2450bbc3b9fSchristosarguments, and rename the output as expected.
2460bbc3b9fSchristos
2470bbc3b9fSchristosIf you are trying to build a whole package this is not the
2480bbc3b9fSchristosright script to run: please start by reading the file 'INSTALL'.
2490bbc3b9fSchristos
2500bbc3b9fSchristosReport bugs to <bug-automake@gnu.org>.
2510bbc3b9fSchristosEOF
2520bbc3b9fSchristos    exit $?
2530bbc3b9fSchristos    ;;
2540bbc3b9fSchristos  -v | --v*)
2550bbc3b9fSchristos    echo "compile $scriptversion"
2560bbc3b9fSchristos    exit $?
2570bbc3b9fSchristos    ;;
25877513ecfSchristos  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
25977513ecfSchristos  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
2600bbc3b9fSchristos    func_cl_wrapper "$@"      # Doesn't return...
2610bbc3b9fSchristos    ;;
2620bbc3b9fSchristosesac
2630bbc3b9fSchristos
2640bbc3b9fSchristosofile=
2650bbc3b9fSchristoscfile=
2660bbc3b9fSchristos
2670bbc3b9fSchristosfor arg
2680bbc3b9fSchristosdo
2690bbc3b9fSchristos  if test -n "$eat"; then
2700bbc3b9fSchristos    eat=
2710bbc3b9fSchristos  else
2720bbc3b9fSchristos    case $1 in
2730bbc3b9fSchristos      -o)
2740bbc3b9fSchristos	# configure might choose to run compile as 'compile cc -o foo foo.c'.
2750bbc3b9fSchristos	# So we strip '-o arg' only if arg is an object.
2760bbc3b9fSchristos	eat=1
2770bbc3b9fSchristos	case $2 in
2780bbc3b9fSchristos	  *.o | *.obj)
2790bbc3b9fSchristos	    ofile=$2
2800bbc3b9fSchristos	    ;;
2810bbc3b9fSchristos	  *)
2820bbc3b9fSchristos	    set x "$@" -o "$2"
2830bbc3b9fSchristos	    shift
2840bbc3b9fSchristos	    ;;
2850bbc3b9fSchristos	esac
2860bbc3b9fSchristos	;;
2870bbc3b9fSchristos      *.c)
2880bbc3b9fSchristos	cfile=$1
2890bbc3b9fSchristos	set x "$@" "$1"
2900bbc3b9fSchristos	shift
2910bbc3b9fSchristos	;;
2920bbc3b9fSchristos      *)
2930bbc3b9fSchristos	set x "$@" "$1"
2940bbc3b9fSchristos	shift
2950bbc3b9fSchristos	;;
2960bbc3b9fSchristos    esac
2970bbc3b9fSchristos  fi
2980bbc3b9fSchristos  shift
2990bbc3b9fSchristosdone
3000bbc3b9fSchristos
3010bbc3b9fSchristosif test -z "$ofile" || test -z "$cfile"; then
3020bbc3b9fSchristos  # If no '-o' option was seen then we might have been invoked from a
3030bbc3b9fSchristos  # pattern rule where we don't need one.  That is ok -- this is a
3040bbc3b9fSchristos  # normal compilation that the losing compiler can handle.  If no
3050bbc3b9fSchristos  # '.c' file was seen then we are probably linking.  That is also
3060bbc3b9fSchristos  # ok.
3070bbc3b9fSchristos  exec "$@"
3080bbc3b9fSchristosfi
3090bbc3b9fSchristos
3100bbc3b9fSchristos# Name of file we expect compiler to create.
3110bbc3b9fSchristoscofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
3120bbc3b9fSchristos
3130bbc3b9fSchristos# Create the lock directory.
3140bbc3b9fSchristos# Note: use '[/\\:.-]' here to ensure that we don't use the same name
3150bbc3b9fSchristos# that we are using for the .o file.  Also, base the name on the expected
3160bbc3b9fSchristos# object file name, since that is what matters with a parallel build.
3170bbc3b9fSchristoslockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
3180bbc3b9fSchristoswhile true; do
3190bbc3b9fSchristos  if mkdir "$lockdir" >/dev/null 2>&1; then
3200bbc3b9fSchristos    break
3210bbc3b9fSchristos  fi
3220bbc3b9fSchristos  sleep 1
3230bbc3b9fSchristosdone
3240bbc3b9fSchristos# FIXME: race condition here if user kills between mkdir and trap.
3250bbc3b9fSchristostrap "rmdir '$lockdir'; exit 1" 1 2 15
3260bbc3b9fSchristos
3270bbc3b9fSchristos# Run the compile.
3280bbc3b9fSchristos"$@"
3290bbc3b9fSchristosret=$?
3300bbc3b9fSchristos
3310bbc3b9fSchristosif test -f "$cofile"; then
3320bbc3b9fSchristos  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3330bbc3b9fSchristoselif test -f "${cofile}bj"; then
3340bbc3b9fSchristos  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
3350bbc3b9fSchristosfi
3360bbc3b9fSchristos
3370bbc3b9fSchristosrmdir "$lockdir"
3380bbc3b9fSchristosexit $ret
3390bbc3b9fSchristos
3400bbc3b9fSchristos# Local Variables:
3410bbc3b9fSchristos# mode: shell-script
3420bbc3b9fSchristos# sh-indentation: 2
34377513ecfSchristos# eval: (add-hook 'before-save-hook 'time-stamp)
3440bbc3b9fSchristos# time-stamp-start: "scriptversion="
3450bbc3b9fSchristos# time-stamp-format: "%:y-%02m-%02d.%02H"
34677513ecfSchristos# time-stamp-time-zone: "UTC0"
3470bbc3b9fSchristos# time-stamp-end: "; # UTC"
3480bbc3b9fSchristos# End:
349