1#!/bin/sh 2# 3# A helper script for Makeasm.am .S.lo rule. 4 5# Copyright 2001 Free Software Foundation, Inc. 6# 7# This file is part of the GNU MP Library. 8# 9# The GNU MP Library is free software; you can redistribute it and/or modify 10# it under the terms of the GNU Lesser General Public License as published by 11# the Free Software Foundation; either version 3 of the License, or (at your 12# option) any later version. 13# 14# The GNU MP Library is distributed in the hope that it will be useful, but 15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17# License for more details. 18# 19# You should have received a copy of the GNU Lesser General Public License 20# along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 21 22 23# Usage: cpp-cc --cpp=CPP CC ... file.S ... 24# 25# Process file.S with the given CPP command plus any -D options in the 26# rest of the arguments, then assemble with the given CC plus all 27# arguments. 28# 29# The CPP command must be in a single --cpp= argument, and will be 30# split on whitespace. It should include -I options required. 31# 32# When CC is invoked, file.S is replaced with a temporary .s file 33# which is the CPP output. 34# 35# Any lines starting with "#" are removed from the CPP output, usually 36# these will be #line and #file markers from CPP, but they might also 37# be comments from the .S. 38# 39# To allow parallel builds, the temp file name is based on the .S file 40# name, which will be the output object filename for all uses we put 41# this script to. 42 43CPP= 44CPPDEFS= 45CC= 46S= 47SEEN_O=no 48 49for i in "$@"; do 50 case $i in 51 --cpp=*) 52 CPP=`echo "$i" | sed 's/^--cpp=//'` 53 ;; 54 -D*) 55 CPPDEFS="$CPPDEFS $i" 56 CC="$CC $i" 57 ;; 58 *.S) 59 if test -n "$S"; then 60 echo "Only one .S file permitted" 61 exit 1 62 fi 63 BASENAME=`echo "$i" | sed -e 's/\.S$//' -e 's/^.*[\\/:]//'` 64 S=$i 65 TMP_I=tmp-$BASENAME.i 66 TMP_S=tmp-$BASENAME.s 67 CC="$CC $TMP_S" 68 ;; 69 -o) 70 SEEN_O=yes 71 CC="$CC $i" 72 ;; 73 *) 74 CC="$CC $i" 75 ;; 76 esac 77done 78 79if test -z "$CPP"; then 80 echo "No --cpp specified" 81 exit 1 82fi 83 84if test -z "$S"; then 85 echo "No .S specified" 86 exit 1 87fi 88 89# Libtool adds it's own -o when sending output to .libs/foo.o, but not 90# when just wanting foo.o in the current directory. We need an 91# explicit -o in both cases since we're assembling tmp-foo.s. 92# 93if test $SEEN_O = no; then 94 CC="$CC -o $BASENAME.o" 95fi 96 97echo "$CPP $CPPDEFS $S >$TMP_I" 98$CPP $CPPDEFS $S >$TMP_I || exit 99 100echo "grep -v '^#' $TMP_I >$TMP_S" 101grep -v '^#' $TMP_I >$TMP_S 102 103echo "$CC" 104$CC || exit 105 106# Comment this out to preserve .s intermediates 107rm -f $TMP 108