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 | |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 11 | ## Search path for automatically finding the obj-root to use. |
| 12 | ## Note: The src root directory ${LLVMDIR} will be prepended to this path later. |
| 13 | ## |
Chris Lattner | e5ff008 | 2007-02-14 07:39:35 +0000 | [diff] [blame] | 14 | set OBJROOTDIRLIST = ( ) |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 15 | |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 16 | set doit = 1 |
| 17 | unset options_done |
| 18 | while ( !( $?options_done ) && ($#argv > 0)) |
| 19 | switch ($argv[1]) |
| 20 | case -h : |
| 21 | usage |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 22 | case -f : |
| 23 | if ($#argv < 2) usage |
| 24 | shift argv; set MFILE = $argv[1]; shift argv; breaksw |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 25 | case -n : |
| 26 | set doit = 0; shift argv; breaksw |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 27 | case -obj : |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 28 | set OBJROOT = $argv[2]; shift argv; shift argv |
| 29 | if (! -d "$OBJROOT") then |
| 30 | echo "FATAL: Illegal obj-root directory ${OBJROOT}" |
| 31 | exit 1 |
| 32 | endif |
| 33 | breaksw |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 34 | case -d : |
| 35 | set doit = 0; set DEBUG = 1; shift argv; breaksw |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 36 | case -* : |
| 37 | set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw |
| 38 | default : |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 39 | set optarg = `echo -n $argv[1] | sed 's/^[^=]*$//'` |
| 40 | if ($#optarg) then |
| 41 | set GMAKE_OPTS = ( $GMAKE_OPTS $optarg ) |
| 42 | shift argv |
| 43 | else |
| 44 | set options_done |
| 45 | endif |
| 46 | breaksw |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 47 | endsw |
| 48 | end |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 49 | |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 50 | if ($#argv > 1) then |
| 51 | echo 'ERROR: More than one tool is not supported by "makellvm"' |
| 52 | usage |
| 53 | endif |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 54 | if ($#argv > 0) then |
Vikram S. Adve | 2d45660 | 2002-09-15 18:22:47 +0000 | [diff] [blame] | 55 | set EXEC = $argv[1] |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 56 | endif |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 57 | if ($DEBUG) then |
| 58 | echo "DEBUG: EXEC = $EXEC" |
| 59 | endif |
Vikram S. Adve | 631484c | 2002-09-15 16:33:32 +0000 | [diff] [blame] | 60 | |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 61 | ## Compute LLVMDIR: the root of the current LLVM tree. |
| 62 | ## It is recorded in the variable LEVEL in Makefile, to compute it |
| 63 | ## |
| 64 | if (! $?MFILE) then |
| 65 | if (-f GNUmakefile) then |
| 66 | set MFILE = GNUmakefile |
| 67 | else if (-f makefile) then |
| 68 | set MFILE = makefile |
| 69 | else |
| 70 | set MFILE = Makefile |
| 71 | endif |
| 72 | endif |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 73 | if ($DEBUG) then |
| 74 | echo "DEBUG: MFILE = $MFILE" |
| 75 | endif |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 76 | if (! -f $MFILE) then |
| 77 | echo "Missing or invalid makefile: $MFILE" |
| 78 | exit 1 |
| 79 | endif |
| 80 | |
| 81 | set LLVMDIR = `awk '/LEVEL[ ]*=/ {print $NF}' $MFILE` |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 82 | if ($DEBUG) then |
| 83 | echo "DEBUG: LLVMDIR = $LLVMDIR" |
| 84 | endif |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 85 | |
Vikram S. Adve | ec6867e | 2003-09-08 15:32:47 +0000 | [diff] [blame] | 86 | if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 87 | 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] | 88 | echo "Are you within a valid LLVM directory for running gmake?" |
Vikram S. Adve | df3ac86 | 2003-07-22 12:35:28 +0000 | [diff] [blame] | 89 | exit 1 |
| 90 | endif |
| 91 | |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 92 | ## Try to determine the obj-root directory automatically if not specified |
| 93 | ## |
| 94 | set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST ) ## add src dir |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 95 | if ($?OBJROOT == 0) then |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 96 | ## Try to determine object root directory by looking for Makefile.config |
| 97 | foreach objdir ( $OBJROOTDIRLIST ) |
| 98 | if (-f "${objdir}/Makefile.config") then |
| 99 | set OBJROOT = ${objdir} |
| 100 | break |
| 101 | endif |
| 102 | end |
| 103 | if ($?OBJROOT == 0) then |
| 104 | echo "FATAL: Could not choose an obj-root directory from these choices:" |
| 105 | echo " ${OBJROOTDIRLIST}." |
| 106 | echo " You can specify it explicitly using '-obj obj-root'." |
| 107 | exit 1 |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 108 | endif |
| 109 | echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)." |
| 110 | endif |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 111 | if (${OBJROOT} == ${LLVMDIR}) then |
| 112 | # run make in the source directory itself |
| 113 | set BUILDROOT = . |
| 114 | else |
| 115 | # run make in the in the obj-root tree, in the directory for $cwd |
| 116 | set SRCROOT = `sh -c "cd $LLVMDIR; pwd | sed 's/\//\\\//g'"` |
| 117 | set CURSRCDIR = `echo $cwd | sed -e "s/${SRCROOT}//"` |
| 118 | set BUILDROOT = ${OBJROOT}/${CURSRCDIR} |
| 119 | unset SRCROOT CURSRCDIR |
| 120 | endif |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 121 | if ($DEBUG) then |
| 122 | echo "DEBUG: BUILDROOT = $BUILDROOT" |
| 123 | endif |
Vikram S. Adve | c69230d5 | 2003-09-15 11:18:36 +0000 | [diff] [blame] | 124 | if (! -d $BUILDROOT) then |
| 125 | echo "FATAL: Invalid build directory: ${BUILDROOT}" |
| 126 | exit 1 |
| 127 | endif |
Vikram S. Adve | fb5e060 | 2003-09-14 23:44:31 +0000 | [diff] [blame] | 128 | cd $BUILDROOT |
| 129 | |
Chris Lattner | e96e376 | 2005-08-02 00:10:52 +0000 | [diff] [blame] | 130 | set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)" |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 131 | |
| 132 | if ($doit == 1) then |
| 133 | csh -f -c "$CMD" |
Daniel Dunbar | 8bd79a8 | 2008-08-13 20:43:56 +0000 | [diff] [blame] | 134 | set pstatus = $? |
Vikram S. Adve | 39c36e8 | 2002-09-19 14:54:53 +0000 | [diff] [blame] | 135 | else |
| 136 | echo '(NOT EXECUTING) COMMAND:' |
| 137 | echo " $CMD" |
| 138 | endif |
| 139 | |
| 140 | |
| 141 | #========================================================= |
| 142 | # CODE TO BE EXECUTED IF INTERRUPT IS RECEIVED |
| 143 | #========================================================= |
| 144 | cleanup: |
| 145 | exit($pstatus) |