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