Blame mpn/cpp-ccas

Packit 5c3484
#!/bin/sh
Packit 5c3484
#
Packit 5c3484
# A helper script for Makeasm.am .S.lo rule.
Packit 5c3484
Packit 5c3484
# Copyright 2001 Free Software Foundation, Inc.
Packit 5c3484
#
Packit 5c3484
#  This file is part of the GNU MP Library.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
#  it under the terms of either:
Packit 5c3484
#
Packit 5c3484
#    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
#      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
#      option) any later version.
Packit 5c3484
#
Packit 5c3484
#  or
Packit 5c3484
#
Packit 5c3484
#    * the GNU General Public License as published by the Free Software
Packit 5c3484
#      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
#      later version.
Packit 5c3484
#
Packit 5c3484
#  or both in parallel, as here.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
#  for more details.
Packit 5c3484
#
Packit 5c3484
#  You should have received copies of the GNU General Public License and the
Packit 5c3484
#  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
#  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Usage: cpp-cc --cpp=CPP CC ... file.S ...
Packit 5c3484
#
Packit 5c3484
# Process file.S with the given CPP command plus any -D options in the
Packit 5c3484
# rest of the arguments, then assemble with the given CC plus all
Packit 5c3484
# arguments.
Packit 5c3484
#
Packit 5c3484
# The CPP command must be in a single --cpp= argument, and will be
Packit 5c3484
# split on whitespace.  It should include -I options required.
Packit 5c3484
#
Packit 5c3484
# When CC is invoked, file.S is replaced with a temporary .s file
Packit 5c3484
# which is the CPP output.
Packit 5c3484
#
Packit 5c3484
# Any lines starting with "#" are removed from the CPP output, usually
Packit 5c3484
# these will be #line and #file markers from CPP, but they might also
Packit 5c3484
# be comments from the .S.
Packit 5c3484
#
Packit 5c3484
# To allow parallel builds, the temp file name is based on the .S file
Packit 5c3484
# name, which will be the output object filename for all uses we put
Packit 5c3484
# this script to.
Packit 5c3484
Packit 5c3484
CPP=
Packit 5c3484
CPPDEFS=
Packit 5c3484
CC=
Packit 5c3484
S=
Packit 5c3484
SEEN_O=no
Packit 5c3484
Packit 5c3484
for i in "$@"; do
Packit 5c3484
  case $i in
Packit 5c3484
    --cpp=*)
Packit 5c3484
      CPP=`echo "$i" | sed 's/^--cpp=//'`
Packit 5c3484
      ;;
Packit 5c3484
    -D*)
Packit 5c3484
      CPPDEFS="$CPPDEFS $i"
Packit 5c3484
      CC="$CC $i"
Packit 5c3484
      ;;
Packit 5c3484
    *.S)
Packit 5c3484
      if test -n "$S"; then
Packit 5c3484
        echo "Only one .S file permitted"
Packit 5c3484
        exit 1
Packit 5c3484
      fi
Packit 5c3484
      BASENAME=`echo "$i" | sed -e 's/\.S$//' -e 's/^.*[\\/:]//'`
Packit 5c3484
      S=$i
Packit 5c3484
      TMP_I=tmp-$BASENAME.i
Packit 5c3484
      TMP_S=tmp-$BASENAME.s
Packit 5c3484
      CC="$CC $TMP_S"
Packit 5c3484
      ;;
Packit 5c3484
    -o)
Packit 5c3484
      SEEN_O=yes
Packit 5c3484
      CC="$CC $i"
Packit 5c3484
      ;;
Packit 5c3484
    *)
Packit 5c3484
      CC="$CC $i"
Packit 5c3484
      ;;
Packit 5c3484
  esac
Packit 5c3484
done
Packit 5c3484
Packit 5c3484
if test -z "$CPP"; then
Packit 5c3484
  echo "No --cpp specified"
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
if test -z "$S"; then
Packit 5c3484
  echo "No .S specified"
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
# Libtool adds it's own -o when sending output to .libs/foo.o, but not
Packit 5c3484
# when just wanting foo.o in the current directory.  We need an
Packit 5c3484
# explicit -o in both cases since we're assembling tmp-foo.s.
Packit 5c3484
#
Packit 5c3484
if test $SEEN_O = no; then
Packit 5c3484
  CC="$CC -o $BASENAME.o"
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
echo "$CPP $CPPDEFS $S >$TMP_I"
Packit 5c3484
$CPP $CPPDEFS $S >$TMP_I || exit
Packit 5c3484
Packit 5c3484
echo "grep -v '^#' $TMP_I >$TMP_S"
Packit 5c3484
grep -v '^#' $TMP_I >$TMP_S
Packit 5c3484
Packit 5c3484
echo "$CC"
Packit 5c3484
$CC || exit
Packit 5c3484
Packit 5c3484
# Comment this out to preserve .s intermediates
Packit 5c3484
rm -f $TMP