pcsx2/build.sh

260 lines
10 KiB
Bash
Raw Normal View History

build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
#!/bin/sh -u
# PCSX2 - PS2 Emulator for PCs
2014-08-04 01:58:37 +00:00
# Copyright (C) 2002-2014 PCSX2 Dev Team
#
# PCSX2 is free software: you can redistribute it and/or modify it under the terms
# of the GNU Lesser General Public License as published by the Free Software Found-
# ation, either version 3 of the License, or (at your option) any later version.
#
# PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with PCSX2.
# If not, see <http://www.gnu.org/licenses/>.
2014-08-04 01:58:37 +00:00
#set -e # This terminates the script in case of any error
flags="-DCMAKE_BUILD_PO=FALSE"
2014-08-04 01:58:37 +00:00
cleanBuild=0
useClang=0
useIcc=0
# 0 => no, 1 => yes, 2 => force yes
useCross=2
CoverityBuild=0
2015-11-05 08:49:06 +00:00
cppcheck=0
clangTidy=0
2014-08-04 01:58:37 +00:00
root=$PWD/$(dirname "$0")
log="$root/install_log.txt"
build="$root/build"
coverity_dir="cov-int"
coverity_result=pcsx2-coverity.xz
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
if [ "$(uname -s)" = 'Darwin' ]; then
ncpu="$(sysctl -n hw.ncpu)"
# Get the major Darwin/OSX version.
if [ "$(sysctl -n kern.osrelease | cut -d . -f 1)" -lt 13 ]; then
2015-11-17 17:25:12 +00:00
echo "This old OSX version is not supported! Build will fail."
toolfile=cmake/darwin-compiler-i386-clang.cmake
else
echo "Using Mavericks build with C++11 support."
toolfile=cmake/darwin13-compiler-i386-clang.cmake
fi
elif [ "$(uname -s)" = 'FreeBSD' ]; then
ncpu="$(sysctl -n hw.ncpu)"
2015-11-17 17:25:12 +00:00
else
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
ncpu=$(grep -w -c processor /proc/cpuinfo)
2015-11-17 17:25:12 +00:00
toolfile=cmake/linux-compiler-i386-multilib.cmake
fi
if command -v ninja >/dev/null ; then
flags="$flags -GNinja"
make=ninja
else
make="make -j$ncpu"
fi
2014-08-04 01:58:37 +00:00
for ARG in "$@"; do
case "$ARG" in
--clean ) cleanBuild=1 ;;
--clang-tidy ) flags="$flags -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"; clangTidy=1 ; useClang=1;;
2015-11-05 08:49:06 +00:00
--clang ) useClang=1 ;;
--intel ) useIcc=1 ;;
2015-11-05 08:49:06 +00:00
--cppcheck ) cppcheck=1 ;;
--dev|--devel ) flags="$flags -DCMAKE_BUILD_TYPE=Devel" ; build="$root/build_dev";;
--dbg|--debug ) flags="$flags -DCMAKE_BUILD_TYPE=Debug" ; build="$root/build_dbg";;
--rel|--release ) flags="$flags -DCMAKE_BUILD_TYPE=Release" ; build="$root/build_rel";;
--prof ) flags="$flags -DCMAKE_BUILD_TYPE=Prof" ; build="$root/build_prof";;
--strip ) flags="$flags -DCMAKE_BUILD_STRIP=TRUE" ;;
--glsl ) flags="$flags -DGLSL_API=TRUE" ;;
--egl ) flags="$flags -DEGL_API=TRUE" ;;
--sdl12 ) flags="$flags -DSDL2_API=FALSE" ;;
--extra ) flags="$flags -DEXTRA_PLUGINS=TRUE" ;;
--asan ) flags="$flags -DUSE_ASAN=TRUE" ;;
--gtk3 ) flags="$flags -DGTK3_API=TRUE" ;;
--no-simd ) flags="$flags -DDISABLE_ADVANCE_SIMD=TRUE" ;;
--cross-multilib ) flags="$flags -DCMAKE_TOOLCHAIN_FILE=$toolfile"; useCross=1; ;;
--no-cross-multilib ) useCross=0; ;;
--coverity ) CoverityBuild=1; cleanBuild=1; ;;
-D* ) flags="$flags $ARG" ;;
*)
2014-08-04 01:58:37 +00:00
# Unknown option
echo "** User options **"
echo "--dev / --devel : Build PCSX2 as a Development build."
echo "--debug : Build PCSX2 as a Debug build."
echo "--prof : Build PCSX2 as a Profiler build (release + debug symbol)."
echo "--release : Build PCSX2 as a Release build."
echo
echo "--clean : Do a clean build."
echo "--extra : Build all plugins"
echo "--no-simd : Only allow sse2"
echo
echo "** Developer option **"
echo "--glsl : Replace CG backend of ZZogl by GLSL"
echo "--egl : Replace GLX by EGL (ZZogl/GSdx plugins)"
echo "--cross-multilib: Build a 32bit PCSX2 on a 64bit machine using multilib."
echo
echo "** Distribution Compatibilities **"
echo "--sdl12 : Build with SDL1.2 (requires if wx is linked against SDL1.2)"
echo
echo "** Expert Developer option **"
echo "--gtk3 : replace GTK2 by GTK3"
echo "--no-cross-multilib: Build a native PCSX2"
echo "--clang : Build with Clang/llvm"
echo "--intel : Build with ICC (Intel compiler)"
2015-11-05 08:49:06 +00:00
echo
echo "** Quality & Assurance (Please install the external tool) **"
echo "--asan : Enable Address sanitizer"
echo "--clang-tidy : Do a clang-tidy analysis. Results can be found in build directory"
2015-11-05 17:24:16 +00:00
echo "--cppcheck : Do a cppcheck analysis. Results can be found in build directory"
2015-11-05 08:49:06 +00:00
echo "--coverity : Do a build for coverity"
2014-08-04 01:58:37 +00:00
exit 1
esac
done
if [ "$cleanBuild" -eq 1 ]; then
2014-08-04 01:58:37 +00:00
echo "Doing a clean build."
# allow to keep build as a symlink (for example to a ramdisk)
2015-12-18 00:45:23 +00:00
rm -fr "$build"/*
2014-08-04 01:58:37 +00:00
fi
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
if [ "$useCross" -eq 2 ] && [ "$(getconf LONG_BIT 2> /dev/null)" != 32 ]; then
echo "Forcing cross compilation."
flags="$flags -DCMAKE_TOOLCHAIN_FILE=$toolfile"
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
elif [ "$useCross" -ne 1 ]; then
useCross=0
fi
# Helper to easily switch wx-config on my system
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
if [ "$useCross" -eq 0 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/lib/i386-linux-gnu/wx/config/gtk2-unicode-3.0" ]; then
sudo update-alternatives --set wx-config /usr/lib/x86_64-linux-gnu/wx/config/gtk2-unicode-3.0
fi
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
if [ "$useCross" -eq 2 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/lib/x86_64-linux-gnu/wx/config/gtk2-unicode-3.0" ]; then
sudo update-alternatives --set wx-config /usr/lib/i386-linux-gnu/wx/config/gtk2-unicode-3.0
fi
echo "Building pcsx2 with $flags" | tee "$log"
# Resolve the symlink otherwise cmake is lost
# Besides, it allows 'mkdir' to create the real destination directory
if [ -L "$build" ]; then
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
build=$(readlink "$build")
fi
2015-12-18 00:45:23 +00:00
mkdir -p "$build"
# Cmake will generate file inside $CWD. It would be nicer if an option to cmake can be provided.
2015-12-18 00:45:23 +00:00
cd "$build"
if [ "$useClang" -eq 1 ]; then
if [ "$useCross" -eq 0 ]; then
CC=clang CXX=clang++ cmake $flags "$root" 2>&1 | tee -a "$log"
else
CC="clang -m32" CXX="clang++ -m32" cmake $flags "$root" 2>&1 | tee -a "$log"
fi
else
if [ "$useIcc" -eq 1 ]; then
if [ "$useCross" -eq 0 ]; then
CC="icc" CXX="icpc" cmake $flags "$root" 2>&1 | tee -a "$log"
else
CC="icc -m32" CXX="icpc -m32" cmake $flags "$root" 2>&1 | tee -a "$log"
fi
else
# Default compiler AKA GCC
cmake $flags "$root" 2>&1 | tee -a "$log"
fi
fi
2015-11-17 17:25:12 +00:00
############################################################
# CPP check build
############################################################
if [ "$cppcheck" -eq 1 ] && command -v cppcheck >/dev/null ; then
2015-11-05 08:49:06 +00:00
summary=cpp_check_summary.log
rm -f $summary
touch $summary
define=""
for undef in _WINDOWS _M_AMD64 _MSC_VER WIN32 __INTEL_COMPILER __x86_64__ \
__SSE4_1__ __SSSE3__ __SSE__ __AVX2__ __USE_ISOC11 ASAN_WORKAROUND ENABLE_OPENCL ENABLE_OGL_DEBUG
do
define="$define -U$undef"
done
2015-11-05 08:49:06 +00:00
check="--enable=warning,style,missingInclude"
for d in pcsx2 common plugins/GSdx plugins/spu2\-x plugins/onepad
do
build.sh: simplify and semi-modernize 1. All POSIX shells support $(...) syntax [1], including /bin/sh. shellcheck warns about it. 2. [[ won't work in /bin/sh [2], so use [ everywhere. I wonder why it worked now, perhaps the test was running on a system where /bin/sh -> /bin/bash. 3. In POSIX sh, string indexing is undefined. [SC2039]. Unfortunately, this means we require a subprocess: https://wiki.ubuntu.com/DashAsBinSh. Very ugly. 4. In POSIX sh, arrays are undefined. We seem to use $flags as an array after constructing it by string concatenation. I tried to verify that this has the same effect as just passing the quoted string in bash: bash-3.2$ flags="-DCMAKE_GOOK" bash-3.2$ flags="$flags -DCMAKE_MOARMA" bash-3.2$ flags="$flags -DCMAKE_URURURUR" bash-3.2$ ./argv $flags 0: ./argv 1: -DCMAKE_GOOK 2: -DCMAKE_MOARMA 3: -DCMAKE_URURURUR bash-3.2$ ./argv "${flags[@]}" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ ./argv "$flags" 0: ./argv 1: -DCMAKE_GOOK -DCMAKE_MOARMA -DCMAKE_URURURUR bash-3.2$ 5. Enable exit on unknown variable (-u). All variables should be known, otherwise we have an error in the script. shellcheck doesn't warn so I think it's fine. Apart from shellcheck(1), I also ran checkbashisms(1). The latter only reported that "command -v" might not be available in other shells. Apparently only ash(1) doesn't understand it. NOTE: Why are we even trying to support pre-Mavericks (Darwin < 13) OSX? We don't even support the most modern OSX (El Capitan) fully yet. OSX upgrades are free and generally don't leave old machines behind. Most machines made after 2009 can upgrade to El Capitan, AFAIK. I also believe that systems that have all the utilities and libraries necessary to build PCSX2 will have /bin/bash >= 3.x. NOTE 2: Does cmake/ninja generate the same type of output in compile_commands.json? [1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 [2]: http://serverfault.com/a/52050
2016-08-20 11:08:29 +00:00
flat_d=$(echo $d | sed -e 's@/@_@')
2015-11-05 08:49:06 +00:00
log=cpp_check__${flat_d}.log
rm -f "$log"
2015-11-05 08:49:06 +00:00
cppcheck $check -j $ncpu --platform=unix32 $define "$root/$d" 2>&1 | tee "$log"
2015-11-05 08:49:06 +00:00
# Create a small summary (warning it might miss some issues)
fgrep -e "(warning)" -e "(error)" -e "(style)" -e "(performance)" -e "(portability)" "$log" >> $summary
2015-11-05 08:49:06 +00:00
done
exit 0
fi
############################################################
# Clang tidy build
############################################################
if [ "$clangTidy" -eq 1 ] && command -v clang-tidy >/dev/null ; then
compile_json=compile_commands.json
cpp_list=cpp_file.txt
summary=clang_tidy_summary.txt
grep '"file"' $compile_json | sed -e 's/"//g' -e 's/^\s*file\s*:\s*//' | grep -v "aVUzerorec.S" > $cpp_list
# EXAMPLE
#
# Modernize loop syntax, fix if old style found.
# $ clang-tidy -p build_dev/compile_commands.json plugins/GSdx/GSTextureCache.cpp -checks='modernize-loop-convert' -fix
# Check all, tons of output:
# $ clang-tidy -p $compile_json $cpp -checks='*' -header-filter='.*'
# List of modernize checks:
# modernize-loop-convert
# modernize-make-unique
# modernize-pass-by-value
# modernize-redundant-void-arg
# modernize-replace-auto-ptr
# modernize-shrink-to-fit
# modernize-use-auto
# modernize-use-default
# modernize-use-nullptr
# modernize-use-override
# Don't check headers, don't check google/llvm coding conventions
if command -v parallel >/dev/null ; then
# Run clang-tidy in parallel with as many jobs as there are CPUs.
parallel -v --keep-order "clang-tidy -p $compile_json -checks='*,-llvm-*,-google-*' {}"
else
# xargs(1) can also run jobs in parallel with -P, but will mix the
# output from the distinct processes together willy-nilly.
xargs clang-tidy -p $compile_json -checks='*,-llvm-*,-google-*'
fi < $cpp_list > $summary
exit 0
fi
############################################################
# Coverity build
############################################################
if [ "$CoverityBuild" -eq 1 ] && command -v cov-build >/dev/null ; then
cov-build --dir "$coverity_dir" $make 2>&1 | tee -a "$log"
# Warning: $coverity_dir must be the root directory
2015-12-18 00:47:48 +00:00
(cd "$build"; tar caf $coverity_result "$coverity_dir")
exit 0
fi
############################################################
# Real build
############################################################
$make 2>&1 | tee -a "$log"
$make install 2>&1 | tee -a "$log"
2014-08-04 01:58:37 +00:00
exit 0