2022-05-17 01:51:25 -04:00
#!/bin/bash
2024-01-22 05:08:38 -03:00
## Copyright (c) 2024 Alex313031.
2022-05-17 01:51:25 -04:00
2024-01-22 05:08:38 -03:00
## Clones current LLVM being used by the Chromium Project, and builds a local LLVM toolchain with Polly to use the Polly optimizations in the main Thorium BUILD.gn
2022-08-07 18:34:31 -04:00
YEL = '\033[1;33m' # Yellow
CYA = '\033[1;96m' # Cyan
RED = '\033[1;31m' # Red
GRE = '\033[1;32m' # Green
c0 = '\033[0m' # Reset Text
bold = '\033[1m' # Bold Text
underline = '\033[4m' # Underline Text
# Error handling
yell( ) { echo " $0 : $* " >& 2; }
die( ) { yell " $* " ; exit 111; }
try( ) { " $@ " || die " ${ RED } Failed $* " ; }
2023-06-23 01:38:08 -04:00
# chromium/src dir env variable
if [ -z " ${ CR_DIR } " ] ; then
CR_SRC_DIR = " $HOME /chromium/src "
export CR_SRC_DIR
else
CR_SRC_DIR = " ${ CR_DIR } "
export CR_SRC_DIR
fi
2022-08-07 18:34:31 -04:00
# --help
displayHelp ( ) {
2023-06-23 01:29:21 -04:00
cd ${ CR_SRC_DIR } &&
2022-08-07 18:34:31 -04:00
python3 tools/clang/scripts/build.py --help &&
printf "\n" &&
printf " ${ bold } ${ GRE } Script to clone the latest LLVM being used by the Chromium Project, and builds a local ${ c0 } \n " &&
printf " ${ bold } ${ GRE } LLVM toolchain with Polly to use the Polly optimizations in the main Thorium BUILD.gn ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --pgo flag to build LLVM with PGO. ${ c0 } \n " &&
2022-08-08 00:13:10 -04:00
printf " ${ bold } ${ YEL } Use the --jobs or -j flag to set the number of jobs (should be less or equal to the number of CPU cores). ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --verbose or -v flag to make Ninja show verbose commands. ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --version flag to show version, and --help to show help. ${ c0 } \n " &&
2022-08-07 18:34:31 -04:00
printf "\n"
}
case $1 in
--help) displayHelp; exit 0; ;
esac
2022-08-08 00:13:10 -04:00
# --version
displayVersion ( ) {
2023-06-23 01:29:21 -04:00
cd ${ CR_SRC_DIR } &&
2022-08-08 00:13:49 -04:00
printf "\n" &&
2022-08-08 00:13:10 -04:00
python3 tools/clang/scripts/build.py --version &&
printf "\n"
}
case $1 in
--version) displayVersion; exit 0; ;
esac
2022-08-07 18:34:31 -04:00
# Build with PGO
buildPollyPGO ( ) {
2023-06-23 01:29:21 -04:00
cd ${ CR_SRC_DIR } &&
2022-08-07 18:34:31 -04:00
printf " ${ GRE } Building LLVM and Polly using PGO... ${ c0 } \n " &&
printf "\n"
2022-08-08 00:13:10 -04:00
sleep 1 &&
2022-08-07 18:34:31 -04:00
2024-01-22 06:56:39 -03:00
python3 tools/clang/scripts/build.py --without-android --without-fuchsia --disable-asserts --bootstrap --thinlto --pgo $@ &&
2022-08-07 18:34:31 -04:00
printf "\n"
printf " ${ GRE } Done! You can now run ./build.sh\n " &&
printf "\n" &&
tput sgr0
}
case $1 in
--pgo) buildPollyPGO; exit 0; ;
esac
printf "\n" &&
printf " ${ bold } ${ GRE } Clones latest LLVM being used by the Chromium Project, and builds a local LLVM toolchain with Polly ${ c0 } \n " &&
printf " ${ bold } ${ GRE } to use the Polly optimizations in the main Thorium BUILD.gn ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --pgo flag to build LLVM with PGO. ${ c0 } \n " &&
2022-08-08 00:13:10 -04:00
printf " ${ bold } ${ YEL } Use the --jobs or -j flag to set the number of jobs (should be less or equal to the number of CPU cores) ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --verbose or -v flag to make Ninja show verbose commands. ${ c0 } \n " &&
printf " ${ bold } ${ YEL } Use the --version flag to show version, and --help to show help. ${ c0 } \n " &&
2022-08-07 18:34:31 -04:00
printf "\n"
2023-06-23 01:29:21 -04:00
cd ${ CR_SRC_DIR } &&
2022-05-17 01:51:25 -04:00
2022-08-07 18:34:31 -04:00
printf " ${ GRE } Building LLVM and Polly... ${ c0 } \n " &&
printf "\n"
sleep 1 &&
2024-01-22 06:56:39 -03:00
python3 tools/clang/scripts/build.py --without-android --without-fuchsia --disable-asserts --bootstrap --thinlto $@ &&
2022-08-07 18:34:31 -04:00
printf "\n"
printf " ${ GRE } Done! You can now run ./build.sh\n " &&
printf "\n" &&
2024-01-22 05:08:38 -03:00
tput sgr0