Quote paths and use platform separator so script works on Windows
[cev.git] / ccev
blob29f1dd1c18112885bd463a3de6ec5596b42f1d1d
1 #!/bin/bash -e
4 # Copyright (C) 2004 Robin Rosenberg.
6 # This program is available under the terms of the GNU Public License.
9 while [ "${1:0:1}" = "-" ]
11 case "$1" in
12 --I)
13 INC="$INC $2"
14 shift 2;
16 --I*)
17 INC="$INC ${1:3}"
18 shift 1;
20 -*)
21 FLAGS="$FLAGS $1";
22 shift 1
24 esac
25 done
27 mkdir -p $HOME/.ccev
28 if [ ! -f $HOME/.ccev/stdinc.h ]
29 then
30 cat >$HOME/.ccev/stdinc.h <<EOF
31 // Do not forget to re-precompile this
32 // file if you modify it or delete the
33 // .pch file
34 #include <cstdio>
35 #include <cstdlib>
36 #include <iostream>
37 #include <iterator>
38 #include <algorithm>
39 #include <iterator>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <unistd.h>
44 #include <iomanip>
45 EOF
46 g++ $HOME/.ccev/stdinc.h || echo "W:Could not create precompiled heaader file"
48 TMP=${TMP:-/tmp}
49 tmpf=$TMP/ccev$$.cpp
50 tmpx=$TMP/ccev$$
51 trap "rm -f $tmpf $tmpfx" 0
52 cat >$tmpf <<EOF
53 #include "$HOME/.ccev/stdinc.h"
54 EOF
55 for i in $INC
57 echo >>$tmpf "#include <$i>"
58 done
59 cat >>$tmpf <<EOF
60 using namespace std;
61 EOF
63 while [ $# -gt 1 ]
65 echo >>$tmpf "$1"
66 shift 1
67 done
69 cat >>$tmpf <<EOF
70 main(int argc,char **argv)
72 $1;
73 cout << endl;
75 EOF
76 g++ -o $tmpx $tmpf $FLAGS && $tmpx ||grep -n . $tmpf
77 rm -f $tmpx