Merge branch 'master' into verilog-ams
[sverilog.git] / iverilog-vpi.sh
blobb49abe6cc208254072d8bb7c3759102a5c5eff02
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 LDFLAGS="@SHARED@ -L@LIBDIR@"
30 LDLIBS="-lveriuser -lvpi"
32 CCSRC=
33 CXSRC=
34 OBJ=
35 LIB=
36 OUT=
37 INCOPT=
38 DEFS=
40 # --
41 # parse the command line switches. This collects the source files
42 # and precompiled object files, and maybe user libraries. As we are
43 # going, guess an output file name.
44 for parm
46 case $parm
49 *.c) CCSRC="$CCSRC $parm"
50 if [ x$OUT = x ]; then
51 OUT=`basename $parm .c`
55 *.cc) CXSRC="$CXSRC $parm"
56 LD=$CXX
57 if [ x$OUT = x ]; then
58 OUT=`basename $parm .cc`
62 *.cpp) CXSRC="$CXSRC $parm"
63 LD=$CXX
64 if [ x$OUT = x ]; then
65 OUT=`basename $parm .cpp`
69 *.o) OBJ="$OBJ $parm"
70 if [ x$OUT = x ]; then
71 OUT=`basename $parm .o`
75 --name=*)
76 OUT=`echo $parm | cut -b8-`
79 -l*) LIB="$LIB $parm"
82 -I*) INCOPT="$INCOPT $parm"
85 -D*) DEFS="$DEFS $parm"
88 --cflags)
89 echo "$CFLAGS"
90 exit;
93 --ldflags)
94 echo "$LDFLAGS"
95 exit;
98 --ldlibs)
99 echo "$LDLIBS"
100 exit;
103 --install-dir)
104 echo "@LIBDIR@/ivl"
105 exit
107 esac
109 done
111 if [ x$OUT = x ]; then
112 echo "Usage: $0 [src and obj files]..." 1>&2
113 exit 0
116 # Put the .vpi on the result file.
117 OUT=$OUT".vpi"
119 compile_errors=0
121 # Compile all the source files into object files
122 for src in $CCSRC
124 base=`basename $src .c`
125 obj=$base".o"
127 echo "Compiling $src..."
128 $CC -c -o $obj $DEFS $CFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
129 OBJ="$OBJ $obj"
130 done
132 for src in $CXSRC
134 base=`basename $src .cc`
135 obj=$base".o"
137 echo "Compiling $src..."
138 $CXX -c -o $obj $DEFS $CFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
139 OBJ="$OBJ $obj"
140 done
142 if test $compile_errors -gt 0
143 then
144 echo "$0: $compile_errors file(s) failed to compile."
145 exit $compile_errors
148 echo "Making $OUT from $OBJ..."
149 exec $LD -o $OUT $LDFLAGS $OBJ $LIB $LDLIBS