Skip to content

Commit 966f88e

Browse files
committed
build-llvm: Improve code for checking for preexisting native tools when cross compiling
Check for the prescence of the llvm-tblgen binary in addition to just checking whether the llvm/build or llvm/build-asserts directories exist. In cases where having multiple build directories around, where some are older than others, it's now possible to clarify which one to use for tools by just removing the llvm-tblgen binary from the other ones. Also check for the prescenece of each individual tool before setting it; this fixes builds where the native build might not have all components enable as as enabled in the cross build.
1 parent 83d84ab commit 966f88e

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

build-llvm.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,33 +145,47 @@ else
145145
fi
146146

147147
if [ -n "$HOST" ]; then
148-
find_native_tools() {
149-
if [ -d llvm-project/llvm/build/bin ]; then
150-
echo $(pwd)/llvm-project/llvm/build/bin
151-
elif [ -d llvm-project/llvm/build-asserts/bin ]; then
152-
echo $(pwd)/llvm-project/llvm/build-asserts/bin
153-
elif [ -n "$(which llvm-tblgen)" ]; then
154-
echo $(dirname $(which llvm-tblgen))
155-
fi
156-
}
157-
158148
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows"
159149
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CROSSCOMPILING=TRUE"
160150
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc"
161151
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++"
162152
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres"
163153
CMAKEFLAGS="$CMAKEFLAGS -DCROSS_TOOLCHAIN_FLAGS_NATIVE="
164154

165-
native=$(find_native_tools)
166-
if [ -n "$native" ]; then
155+
native=""
156+
for dir in llvm-project/llvm/build/bin llvm-project/llvm/build-asserts/bin; do
157+
if [ -x "$dir/llvm-tblgen.exe" ]; then
158+
native="$(pwd)/$dir"
159+
suffix=".exe"
160+
break
161+
elif [ -x "$dir/llvm-tblgen" ]; then
162+
native="$(pwd)/$dir"
163+
suffix=""
164+
break
165+
fi
166+
done
167+
if [ -z "$native" ] && [ -n "$(which llvm-tblgen)" ]; then
168+
native="$(dirname $(which llvm-tblgen))"
167169
suffix=""
168-
if [ -f $native/llvm-tblgen.exe ]; then
170+
if [ -x "$native/llvm-tblgen.exe" ]; then
169171
suffix=".exe"
170172
fi
171-
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_TABLEGEN=$native/llvm-tblgen$suffix"
172-
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_TABLEGEN=$native/clang-tblgen$suffix"
173-
CMAKEFLAGS="$CMAKEFLAGS -DLLDB_TABLEGEN=$native/lldb-tblgen$suffix"
174-
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_CONFIG_PATH=$native/llvm-config$suffix"
173+
fi
174+
175+
176+
if [ -n "$native" ]; then
177+
if [ -x "$native/llvm-tblgen$suffix" ]; then
178+
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_TABLEGEN=$native/llvm-tblgen$suffix"
179+
fi
180+
if [ -x "$native/clang-tblgen$suffix" ]; then
181+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_TABLEGEN=$native/clang-tblgen$suffix"
182+
fi
183+
if [ -x "$native/lldb-tblgen$suffix" ]; then
184+
CMAKEFLAGS="$CMAKEFLAGS -DLLDB_TABLEGEN=$native/lldb-tblgen$suffix"
185+
fi
186+
if [ -x "$native/llvm-config$suffix" ]; then
187+
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_CONFIG_PATH=$native/llvm-config$suffix"
188+
fi
175189
fi
176190
CROSS_ROOT=$(cd $(dirname $(which $HOST-gcc))/../$HOST && pwd)
177191
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$CROSS_ROOT"

0 commit comments

Comments
 (0)