Quote paths and use platform separator so script works on Windows
[cev.git] / cev
blobccb70413218014fad8e65c741b5e0d9cde708f3b
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/.cev
28 if [ ! -f $HOME/.cev/stdinc.h ]
29 then
30 cat >$HOME/.cev/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 <stdio.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 EOF
41 gcc $HOME/.cev/stdinc.h || echo "W:Could not create precompiled heaader file"
43 TMP=${TMP:-/tmp}
44 tmpf=$TMP/cev$$.c
45 tmpx=$TMP/cev$$
46 trap "rm -f $tmpf $tmpfx" 0
47 cat >$tmpf <<EOF
48 #include "$HOME/.cev/stdinc.h"
49 EOF
50 for i in $INC
52 echo >>$tmpf "#include <$i>"
53 done
54 cat >>$tmpf <<EOF
55 EOF
57 while [ $# -gt 1 ]
59 echo >>$tmpf "$1"
60 shift 1
61 done
63 cat >>$tmpf <<EOF
64 main(int argc,char **argv)
66 $1;
67 return 0;
69 EOF
70 gcc -o $tmpx $tmpf $FLAGS && $tmpx ||grep -n . $tmpf
71 rm -f $tmpx