]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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 | ## 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 | ## | |
14 | set OBJROOTDIRLIST = ( ) | |
15 | ||
16 | set doit = 1 | |
17 | unset options_done | |
18 | while ( !( $?options_done ) && ($#argv > 0)) | |
19 | switch ($argv[1]) | |
20 | case -h : | |
21 | usage | |
22 | case -f : | |
23 | if ($#argv < 2) usage | |
24 | shift argv; set MFILE = $argv[1]; shift argv; breaksw | |
25 | case -n : | |
26 | set doit = 0; shift argv; breaksw | |
27 | case -obj : | |
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 | |
34 | case -d : | |
35 | set doit = 0; set DEBUG = 1; shift argv; breaksw | |
36 | case -* : | |
37 | set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw | |
38 | default : | |
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 | |
47 | endsw | |
48 | end | |
49 | ||
50 | if ($#argv > 1) then | |
51 | echo 'ERROR: More than one tool is not supported by "makellvm"' | |
52 | usage | |
53 | endif | |
54 | if ($#argv > 0) then | |
55 | set EXEC = $argv[1] | |
56 | endif | |
57 | if ($DEBUG) then | |
58 | echo "DEBUG: EXEC = $EXEC" | |
59 | endif | |
60 | ||
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 | |
73 | if ($DEBUG) then | |
74 | echo "DEBUG: MFILE = $MFILE" | |
75 | endif | |
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` | |
82 | if ($DEBUG) then | |
83 | echo "DEBUG: LLVMDIR = $LLVMDIR" | |
84 | endif | |
85 | ||
86 | if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then | |
87 | echo "Unable to find LLVM src-root directory or directory is invalid." | |
88 | echo "Are you within a valid LLVM directory for running gmake?" | |
89 | exit 1 | |
90 | endif | |
91 | ||
92 | ## Try to determine the obj-root directory automatically if not specified | |
93 | ## | |
94 | set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST ) ## add src dir | |
95 | if ($?OBJROOT == 0) then | |
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 | |
108 | endif | |
109 | echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)." | |
110 | endif | |
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 | |
121 | if ($DEBUG) then | |
122 | echo "DEBUG: BUILDROOT = $BUILDROOT" | |
123 | endif | |
124 | if (! -d $BUILDROOT) then | |
125 | echo "FATAL: Invalid build directory: ${BUILDROOT}" | |
126 | exit 1 | |
127 | endif | |
128 | cd $BUILDROOT | |
129 | ||
130 | set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)" | |
131 | ||
132 | if ($doit == 1) then | |
133 | csh -f -c "$CMD" | |
134 | set pstatus = $? | |
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) |