Upload Tizen:Base source
[external/gmp.git] / mpn / m4-ccas
1 #!/bin/sh
2 #
3 # A helper script for Makeasm.am .asm.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: m4-ccas --m4=M4 CC ... file.asm ...
24 #
25 # Process file.asm with the given M4 plus any -D arguments, then
26 # assemble with the given CC plus all arguments.
27 #
28 # The M4 command must be in a single --m4= argument, and will be split
29 # on whitespace.  When CC is invoked file.asm is replaced with a
30 # temporary .s file which is the M4 output.
31 #
32 # To allow parallel builds, the temp file name is based on the .asm
33 # file name, which will be the output object filename for all uses we
34 # put this script to.
35
36 M4=
37 CC=
38 DEFS=
39 ASM=
40 SEEN_O=no
41
42 for i in "$@"; do
43   case $i in
44     --m4=*)
45       M4=`echo "$i" | sed 's/^--m4=//'`
46       ;;
47     -D*)
48       DEFS="$DEFS $i"
49       CC="$CC $i"
50       ;;
51     *.asm)
52       if test -n "$ASM"; then
53         echo "Only one .asm file permitted"
54         exit 1
55       fi
56       BASENAME=`echo "$i" | sed -e 's/\.asm$//' -e 's/^.*[\\/:]//'`
57       TMP=tmp-$BASENAME.s
58       ASM=$i
59       CC="$CC $TMP"
60       ;;
61     -o)
62       SEEN_O=yes
63       CC="$CC $i"
64       ;;
65     *)
66       CC="$CC $i"
67       ;;
68   esac
69 done
70
71 if test -z "$M4"; then
72   echo "No --m4 specified"
73   exit 1
74 fi
75
76 if test -z "$ASM"; then
77   echo "No .asm specified"
78   exit 1
79 fi
80
81 # Libtool adds it's own -o when sending output to .libs/foo.o, but not
82 # when just wanting foo.o in the current directory.  We need an
83 # explicit -o in both cases since we're assembling tmp-foo.s.
84 #
85 if test $SEEN_O = no; then
86   CC="$CC -o $BASENAME.o"
87 fi
88
89 echo "$M4 $DEFS $ASM >$TMP"
90 $M4 $DEFS $ASM >$TMP || exit
91
92 echo "$CC"
93 $CC || exit
94
95 # Comment this out to preserve .s intermediates
96 rm -f $TMP