• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/csh -f
2
3set pstatus = 0
4onintr cleanup
5alias usage 'echo "USAGE: $0:t [-h] [-n] [-obj obj-root] [gmake-flags] [VAR=...] [toolname (default: opt)]"; set pstatus = 1; goto cleanup'
6
7set EXEC = opt
8set GMAKE_OPTS = ""
9set 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##
14set OBJROOTDIRLIST = ( )
15
16set doit = 1
17unset options_done
18while ( !( $?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
48end
49
50if ($#argv > 1) then
51    echo 'ERROR: More than one tool is not supported by "makellvm"'
52    usage
53endif
54if ($#argv > 0) then
55    set EXEC = $argv[1]
56endif
57if ($DEBUG) then
58    echo "DEBUG: EXEC = $EXEC"
59endif
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##
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
73if ($DEBUG) then
74    echo "DEBUG: MFILE = $MFILE"
75endif
76if (! -f $MFILE) then
77    echo "Missing or invalid makefile: $MFILE"
78    exit 1
79endif
80
81set LLVMDIR = `awk '/LEVEL[ 	]*=/ {print $NF}' $MFILE`
82if ($DEBUG) then
83    echo "DEBUG: LLVMDIR = $LLVMDIR"
84endif
85
86if ($#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
90endif
91
92## Try to determine the obj-root directory automatically if not specified
93##
94set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST )	## add src dir
95if ($?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)."
110endif
111if (${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
121if ($DEBUG) then
122    echo "DEBUG: BUILDROOT = $BUILDROOT"
123endif
124if (! -d $BUILDROOT) then
125    echo "FATAL: Invalid build directory: ${BUILDROOT}"
126    exit 1
127endif
128cd $BUILDROOT
129
130set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)"
131
132if ($doit == 1) then
133    csh -f -c "$CMD"
134    set pstatus = $?
135else
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)
146