Fix syntax error when makellvm is run in an invalid directory.
[oota-llvm.git] / utils / makellvm
1 #!/bin/csh -f
2
3 set pstatus = 0
4 onintr cleanup
5 alias usage 'echo "USAGE: $0:t [-h] [-n] [gmake-flag...] [VAR=...] [toolname (default: opt)]"; set pstatus = 1; goto cleanup'
6
7 set EXEC = opt
8 set GMAKE_OPTS = ""
9 set DEBUG = 0
10
11 set doit = 1
12 unset options_done
13 while ( !( $?options_done ) && ($#argv > 0))
14     switch ($argv[1])
15         case -h :
16             usage
17         case -f :
18             if ($#argv < 2) usage
19             shift argv; set MFILE = $argv[1]; shift argv; breaksw
20         case -n :
21             set doit = 0; shift argv; breaksw
22         case -d :
23             set doit = 0; set DEBUG = 1; shift argv; breaksw
24         case -* :
25             set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw
26         default :
27             set optarg = `echo -n $argv[1] | sed 's/^[^=]*$//'`
28             if ($#optarg) then
29                 set GMAKE_OPTS = ( $GMAKE_OPTS $optarg )
30                 shift argv
31             else
32                 set options_done
33             endif
34             breaksw
35     endsw
36 end
37
38 if ($#argv > 1) then
39     echo 'ERROR: More than one tool is not supported by "makellvm"'
40     usage
41 endif
42 if ($#argv > 0) then
43     set EXEC = $argv[1]
44 endif
45 if ($DEBUG) then
46     echo "DEBUG: EXEC = $EXEC"
47 endif
48
49 ## Compute LLVMDIR: the root of the current LLVM tree.
50 ## It is recorded in the variable LEVEL in Makefile, to compute it
51 ## 
52 if (! $?MFILE) then
53     if (-f GNUmakefile) then
54         set MFILE = GNUmakefile
55     else if (-f makefile) then
56         set MFILE = makefile
57     else
58         set MFILE = Makefile
59     endif
60 endif
61 if ($DEBUG) then
62     echo "DEBUG: MFILE = $MFILE"
63 endif
64 if (! -f $MFILE) then
65     echo "Missing or invalid makefile: $MFILE"
66     exit 1
67 endif
68
69 set LLVMDIR = `awk '/LEVEL[     ]*=/ {print $NF}' $MFILE`
70 if ($DEBUG) then
71     echo "DEBUG: LLVMDIR = $LLVMDIR"
72 endif
73
74 if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then
75     echo "Unable to find LLVM obj-root directory or directory is invalid."
76     echo "Are you within a valid LLVM directory for running gmake?"
77     exit 1
78 endif
79
80 set CMD = "gmake $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && gmake $GMAKE_OPTS)"
81
82 if ($doit == 1) then
83     csh -f -c "$CMD"
84 else
85     echo '(NOT EXECUTING) COMMAND:'
86     echo "  $CMD"
87 endif
88
89
90 #=========================================================
91 # CODE TO BE EXECUTED IF INTERRUPT IS RECEIVED
92 #=========================================================
93 cleanup:
94     exit($pstatus)