Update makellvm to work with the brave new world of separate obj-root trees.
[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] [-obj obj-root] [gmake-flags] [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 -obj :
23             set OBJROOT = $argv[1]; shift argv; shift argv; breaksw
24         case -d :
25             set doit = 0; set DEBUG = 1; shift argv; breaksw
26         case -* :
27             set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw
28         default :
29             set optarg = `echo -n $argv[1] | sed 's/^[^=]*$//'`
30             if ($#optarg) then
31                 set GMAKE_OPTS = ( $GMAKE_OPTS $optarg )
32                 shift argv
33             else
34                 set options_done
35             endif
36             breaksw
37     endsw
38 end
39
40 if ($#argv > 1) then
41     echo 'ERROR: More than one tool is not supported by "makellvm"'
42     usage
43 endif
44 if ($#argv > 0) then
45     set EXEC = $argv[1]
46 endif
47 if ($DEBUG) then
48     echo "DEBUG: EXEC = $EXEC"
49 endif
50
51 ## Compute LLVMDIR: the root of the current LLVM tree.
52 ## It is recorded in the variable LEVEL in Makefile, to compute it
53 ## 
54 if (! $?MFILE) then
55     if (-f GNUmakefile) then
56         set MFILE = GNUmakefile
57     else if (-f makefile) then
58         set MFILE = makefile
59     else
60         set MFILE = Makefile
61     endif
62 endif
63 if ($DEBUG) then
64     echo "DEBUG: MFILE = $MFILE"
65 endif
66 if (! -f $MFILE) then
67     echo "Missing or invalid makefile: $MFILE"
68     exit 1
69 endif
70
71 set LLVMDIR = `awk '/LEVEL[     ]*=/ {print $NF}' $MFILE`
72 if ($DEBUG) then
73     echo "DEBUG: LLVMDIR = $LLVMDIR"
74 endif
75
76 if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then
77     echo "Unable to find LLVM src-root directory or directory is invalid."
78     echo "Are you within a valid LLVM directory for running gmake?"
79     exit 1
80 endif
81
82 if ($?OBJROOT == 0) then
83     ## Check if source root is obj-root by looking for Makefile.config there
84     if (-f ${LLVMDIR}/Makefile.config) then
85         set OBJROOT = ${LLVMDIR}
86         set BUILDROOT = .
87     else ## Otherwise assume a default location for OBJROOT
88         set OBJROOT = "/localhome/$USER/llvm"
89         set SRCROOT = `sh -c "cd $LLVMDIR; pwd | sed 's/\//\\\//g'"` 
90         set CURSRCDIR = `echo $cwd | sed -e "s/${SRCROOT}//"`
91         set BUILDROOT = ${OBJROOT}/${CURSRCDIR}
92         unset SRCROOT CURSRCDIR
93     endif
94     echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)."
95 endif
96 if ($DEBUG) then
97     echo "DEBUG: BUILDROOT = $BUILDROOT"
98 endif
99 cd $BUILDROOT 
100
101 set CMD = "gmake $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && gmake $GMAKE_OPTS)"
102
103 if ($doit == 1) then
104     csh -f -c "$CMD"
105 else
106     echo '(NOT EXECUTING) COMMAND:'
107     echo "  $CMD"
108 endif
109
110
111 #=========================================================
112 # CODE TO BE EXECUTED IF INTERRUPT IS RECEIVED
113 #=========================================================
114 cleanup:
115     exit($pstatus)