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