Fix for assertion error when expanding macro.
[iverilog.git] / iverilog-vpi.sh
blobd2512cc40f012592e8fab76c5b21e3f5c0e69a69
1 #!/bin/sh
3 # This source code is free software; you can redistribute it
4 # and/or modify it in source code form under the terms of the GNU
5 # Library General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with this program; if not, write to the Free
16 # Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330
18 # Boston, MA 02111-1307, USA
20 #ident "$Id: iverilog-vpi.sh,v 1.17 2007/02/06 05:07:31 steve Exp $"
22 # These are the variables used for compiling files
23 CC=@IVCC@
24 CXX=@IVCXX@
25 CFLAGS="@PIC@ @IVCFLAGS@ -I@INCLUDEDIR@"
27 # These are used for linking...
28 LD=$CC
29 LDFLAGS32="@SHARED@ -L@LIBDIR@"
30 LDFLAGS64="@SHARED@ -L@LIBDIR64@"
31 LDFLAGS="$LDFLAGS64"
32 LDLIBS="-lveriuser -lvpi"
34 INSTDIR64="@VPIDIR1@"
35 INSTDIR32="@VPIDIR2@"
36 if test x$INSTDIR32 = x
37 then
38 INSTDIR32=$INSTDIR64
41 INSTDIR="$INSTDIR64"
43 CCSRC=
44 CXSRC=
45 OBJ=
46 LIB=
47 OUT=
48 INCOPT=
49 DEFS=
51 # --
52 # parse the command line switches. This collects the source files
53 # and precompiled object files, and maybe user libraries. As we are
54 # going, guess an output file name.
55 for parm
57 case $parm
60 *.c) CCSRC="$CCSRC $parm"
61 if [ x$OUT = x ]; then
62 OUT=`basename $parm .c`
66 *.cc) CXSRC="$CXSRC $parm"
67 LD=$CXX
68 if [ x$OUT = x ]; then
69 OUT=`basename $parm .cc`
73 *.cpp) CXSRC="$CXSRC $parm"
74 LD=$CXX
75 if [ x$OUT = x ]; then
76 OUT=`basename $parm .cpp`
80 *.o) OBJ="$OBJ $parm"
81 if [ x$OUT = x ]; then
82 OUT=`basename $parm .o`
86 --name=*)
87 OUT=`echo $parm | cut -b8-`
90 -l*) LIB="$LIB $parm"
93 -I*) INCOPT="$INCOPT $parm"
96 -D*) DEFS="$DEFS $parm"
99 -m32) LDFLAGS="-m32 $LDFLAGS32"
100 CFLAGS="-m32 $CFLAGS"
101 INSTDIR="$INSTDIR32"
104 --cflags)
105 echo "$CFLAGS"
106 exit;
109 --ldflags)
110 echo "$LDFLAGS"
111 exit;
114 --ldlibs)
115 echo "$LDLIBS"
116 exit;
119 --install-dir)
120 echo "@LIBDIR@/ivl/$INSTDIR"
121 exit
123 esac
125 done
127 if [ x$OUT = x ]; then
128 echo "Usage: $0 [src and obj files]..." 1>&2
129 exit 0
132 # Put the .vpi on the result file.
133 OUT=$OUT".vpi"
135 compile_errors=0
137 # Compile all the source files into object files
138 for src in $CCSRC
140 base=`basename $src .c`
141 obj=$base".o"
143 echo "Compiling $src..."
144 $CC -c -o $obj $DEFS $CFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
145 OBJ="$OBJ $obj"
146 done
148 for src in $CXSRC
150 base=`basename $src .cc`
151 obj=$base".o"
153 echo "Compiling $src..."
154 $CXX -c -o $obj $DEFS $CFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
155 OBJ="$OBJ $obj"
156 done
158 if test $compile_errors -gt 0
159 then
160 echo "Some ($compile_errors) files failed to compile."
161 exit $compile_errors
164 echo "Making $OUT from $OBJ..."
165 exec $LD -o $OUT $LDFLAGS $OBJ $LIB $LDLIBS