Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 1 | #!/bin/csh -f |
| 2 | |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 3 | set pstatus = 0 |
| 4 | onintr cleanup |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 5 | alias usage 'echo "USAGE: $0:t [-h] [-n] [-obj obj-root] [gmake-flags] [VAR=...] [toolname (default: opt)]"; set pstatus = 1; goto cleanup' |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 6 | |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 7 | set EXEC = opt |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 8 | set GMAKE_OPTS = "" |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 9 | set DEBUG = 0 |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 10 | |
| 11 | set doit = 1 |
| 12 | unset options_done |
| 13 | while ( !( $?options_done ) && ($#argv > 0)) |
| 14 | switch ($argv[1]) |
| 15 | case -h : |
| 16 | usage |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 17 | case -f : |
| 18 | if ($#argv < 2) usage |
| 19 | shift argv; set MFILE = $argv[1]; shift argv; breaksw |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 20 | case -n : |
| 21 | set doit = 0; shift argv; breaksw |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 22 | case -obj : |
| 23 | set OBJROOT = $argv[1]; shift argv; shift argv; breaksw |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 24 | case -d : |
| 25 | set doit = 0; set DEBUG = 1; shift argv; breaksw |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 26 | case -* : |
| 27 | set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw |
| 28 | default : |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 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 |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 37 | endsw |
| 38 | end |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 39 | |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 40 | if ($#argv > 1) then |
| 41 | echo 'ERROR: More than one tool is not supported by "makellvm"' |
| 42 | usage |
| 43 | endif |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 44 | if ($#argv > 0) then |
Vikram S. Adve | 2d45660 | 2002-09-15 18:22:47 +0000 | [diff] [blame] | 45 | set EXEC = $argv[1] |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 46 | endif |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 47 | if ($DEBUG) then |
| 48 | echo "DEBUG: EXEC = $EXEC" |
| 49 | endif |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 50 | |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 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 |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 63 | if ($DEBUG) then |
| 64 | echo "DEBUG: MFILE = $MFILE" |
| 65 | endif |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 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` |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 72 | if ($DEBUG) then |
| 73 | echo "DEBUG: LLVMDIR = $LLVMDIR" |
| 74 | endif |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 75 | |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 76 | if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 77 | echo "Unable to find LLVM src-root directory or directory is invalid." |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 78 | echo "Are you within a valid LLVM directory for running gmake?" |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 79 | exit 1 |
| 80 | endif |
| 81 | |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 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 | |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 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) |