blob: ae77712941a27b4274c9bc0018ecd97c544d56dc [file] [log] [blame]
Vikram S. Adve631484c2002-09-15 16:33:32 +00001#!/bin/csh -f
2
Vikram S. Adve39c36e82002-09-19 14:54:53 +00003set pstatus = 0
4onintr cleanup
Vikram S. Advefb5e0602003-09-14 23:44:31 +00005alias usage 'echo "USAGE: $0:t [-h] [-n] [-obj obj-root] [gmake-flags] [VAR=...] [toolname (default: opt)]"; set pstatus = 1; goto cleanup'
Vikram S. Adve39c36e82002-09-19 14:54:53 +00006
Vikram S. Adve631484c2002-09-15 16:33:32 +00007set EXEC = opt
Vikram S. Adve39c36e82002-09-19 14:54:53 +00008set GMAKE_OPTS = ""
Vikram S. Adveec6867e2003-09-08 15:32:47 +00009set DEBUG = 0
Vikram S. Adve39c36e82002-09-19 14:54:53 +000010
Vikram S. Advec69230d52003-09-15 11:18:36 +000011## 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 Lattnere5ff0082007-02-14 07:39:35 +000014set OBJROOTDIRLIST = ( )
Vikram S. Advec69230d52003-09-15 11:18:36 +000015
Vikram S. Adve39c36e82002-09-19 14:54:53 +000016set doit = 1
17unset options_done
18while ( !( $?options_done ) && ($#argv > 0))
19 switch ($argv[1])
20 case -h :
21 usage
Vikram S. Advedf3ac862003-07-22 12:35:28 +000022 case -f :
23 if ($#argv < 2) usage
24 shift argv; set MFILE = $argv[1]; shift argv; breaksw
Vikram S. Adve39c36e82002-09-19 14:54:53 +000025 case -n :
26 set doit = 0; shift argv; breaksw
Vikram S. Advefb5e0602003-09-14 23:44:31 +000027 case -obj :
Vikram S. Advec69230d52003-09-15 11:18:36 +000028 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. Adveec6867e2003-09-08 15:32:47 +000034 case -d :
35 set doit = 0; set DEBUG = 1; shift argv; breaksw
Vikram S. Adve39c36e82002-09-19 14:54:53 +000036 case -* :
37 set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw
38 default :
Vikram S. Advedf3ac862003-07-22 12:35:28 +000039 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. Adve39c36e82002-09-19 14:54:53 +000047 endsw
48end
Vikram S. Adve631484c2002-09-15 16:33:32 +000049
Vikram S. Advedf3ac862003-07-22 12:35:28 +000050if ($#argv > 1) then
51 echo 'ERROR: More than one tool is not supported by "makellvm"'
52 usage
53endif
Vikram S. Adve631484c2002-09-15 16:33:32 +000054if ($#argv > 0) then
Vikram S. Adve2d456602002-09-15 18:22:47 +000055 set EXEC = $argv[1]
Vikram S. Adve631484c2002-09-15 16:33:32 +000056endif
Vikram S. Adveec6867e2003-09-08 15:32:47 +000057if ($DEBUG) then
58 echo "DEBUG: EXEC = $EXEC"
59endif
Vikram S. Adve631484c2002-09-15 16:33:32 +000060
Vikram S. Advedf3ac862003-07-22 12:35:28 +000061## Compute LLVMDIR: the root of the current LLVM tree.
62## It is recorded in the variable LEVEL in Makefile, to compute it
63##
64if (! $?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
72endif
Vikram S. Adveec6867e2003-09-08 15:32:47 +000073if ($DEBUG) then
74 echo "DEBUG: MFILE = $MFILE"
75endif
Vikram S. Advedf3ac862003-07-22 12:35:28 +000076if (! -f $MFILE) then
77 echo "Missing or invalid makefile: $MFILE"
78 exit 1
79endif
80
81set LLVMDIR = `awk '/LEVEL[ ]*=/ {print $NF}' $MFILE`
Vikram S. Adveec6867e2003-09-08 15:32:47 +000082if ($DEBUG) then
83 echo "DEBUG: LLVMDIR = $LLVMDIR"
84endif
Vikram S. Advedf3ac862003-07-22 12:35:28 +000085
Vikram S. Adveec6867e2003-09-08 15:32:47 +000086if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then
Vikram S. Advefb5e0602003-09-14 23:44:31 +000087 echo "Unable to find LLVM src-root directory or directory is invalid."
Vikram S. Adveec6867e2003-09-08 15:32:47 +000088 echo "Are you within a valid LLVM directory for running gmake?"
Vikram S. Advedf3ac862003-07-22 12:35:28 +000089 exit 1
90endif
91
Vikram S. Advec69230d52003-09-15 11:18:36 +000092## Try to determine the obj-root directory automatically if not specified
93##
94set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST ) ## add src dir
Vikram S. Advefb5e0602003-09-14 23:44:31 +000095if ($?OBJROOT == 0) then
Vikram S. Advec69230d52003-09-15 11:18:36 +000096 ## 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. Advefb5e0602003-09-14 23:44:31 +0000108 endif
109 echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)."
110endif
Vikram S. Advec69230d52003-09-15 11:18:36 +0000111if (${OBJROOT} == ${LLVMDIR}) then
112 # run make in the source directory itself
113 set BUILDROOT = .
114else
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
120endif
Vikram S. Advefb5e0602003-09-14 23:44:31 +0000121if ($DEBUG) then
122 echo "DEBUG: BUILDROOT = $BUILDROOT"
123endif
Vikram S. Advec69230d52003-09-15 11:18:36 +0000124if (! -d $BUILDROOT) then
125 echo "FATAL: Invalid build directory: ${BUILDROOT}"
126 exit 1
127endif
Vikram S. Advefb5e0602003-09-14 23:44:31 +0000128cd $BUILDROOT
129
Chris Lattnere96e3762005-08-02 00:10:52 +0000130set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)"
Vikram S. Adve39c36e82002-09-19 14:54:53 +0000131
132if ($doit == 1) then
133 csh -f -c "$CMD"
Daniel Dunbar8bd79a82008-08-13 20:43:56 +0000134 set pstatus = $?
Vikram S. Adve39c36e82002-09-19 14:54:53 +0000135else
136 echo '(NOT EXECUTING) COMMAND:'
137 echo " $CMD"
138endif
139
140
141#=========================================================
142# CODE TO BE EXECUTED IF INTERRUPT IS RECEIVED
143#=========================================================
144cleanup:
145 exit($pstatus)