Skip to content
Permalink
Browse files

build.sh and cmake plugin code cleanup (#2953)

* Refactor build.sh. Restructure finding plugins. Remove legacy code. Add --clean-plugins option. Document --no-trans option.

Don't do setcap if dev9ghzdrk isn't being built. List dependencies if they are missing. Remove code related to zerospu2, and misc plugins we aren't building. Minor message changes.
  • Loading branch information...
arcum42 committed Jul 5, 2019
1 parent 7054450 commit fc35de02f25263b069c7ab4d9657d83f149b2672
Showing with 197 additions and 148 deletions.
  1. +171 −120 build.sh
  2. +20 −15 cmake/SelectPcsx2Plugins.cmake
  3. +6 −4 pcsx2/CMakeLists.txt
  4. +0 −9 plugins/CMakeLists.txt
291 build.sh
@@ -16,13 +16,167 @@

#set -e # This terminates the script in case of any error

# Function declarations
set_ncpu_toolfile()
{
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
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)"
else
ncpu=$(grep -w -c processor /proc/cpuinfo)
toolfile=cmake/linux-compiler-i386-multilib.cmake
fi
}

switch_wxconfig()
{
# Helper to easily switch wx-config on my system
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
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
}

find_freetype()
{
if [ "$useCross" -eq 0 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/include/x86_64-linux-gnu/freetype2/ft2build.h" ]; then
export GTKMM_BASEPATH=/usr/include/x86_64-linux-gnu/freetype2
fi
if [ "$useCross" -eq 2 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/include/i386-linux-gnu/freetype2/ft2build.h" ]; then
export GTKMM_BASEPATH=/usr/include/i386-linux-gnu/freetype2
fi
}

set_make()
{
if command -v ninja >/dev/null ; then
flags="$flags -GNinja"
make=ninja
else
make="make -j$ncpu"
fi
}

set_compiler()
{
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
}

run_cppcheck()
{
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 \
XBYAK_USE_MMAP_ALLOCATOR MAP_ANONYMOUS MAP_ANON XBYAK_DISABLE_AVX512
do
define="$define -U$undef"
done

check="--enable=warning,style,missingInclude"

for d in pcsx2 common plugins/GSdx plugins/spu2\-x plugins/onepad plugins/cdvdGigaherz
do
flat_d=$(echo $d | sed -e 's@/@_@')
log=cpp_check__${flat_d}.log
rm -f "$log"

cppcheck $check -j $ncpu --platform=unix32 $define "$root/$d" 2>&1 | tee "$log"
# Create a small summary (warning it might miss some issues)
fgrep -e "(warning)" -e "(error)" -e "(style)" -e "(performance)" -e "(portability)" "$log" >> $summary
done

exit 0
}

run_clangtidy()
{
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" | sort -u > $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
}

run_coverity()
{
cov-build --dir "$coverity_dir" $make 2>&1 | tee -a "$log"
# Warning: $coverity_dir must be the root directory
(cd "$build"; tar caf $coverity_result "$coverity_dir")
exit 0
}

# Main script
flags="-DCMAKE_BUILD_PO=FALSE"

cleanBuild=0
useClang=0
useIcc=0

# 0 => no, 1 => yes, 2 => force yes
useCross=2

CoverityBuild=0
cppcheck=0
clangTidy=0
@@ -33,34 +187,13 @@ build="$root/build"
coverity_dir="cov-int"
coverity_result=pcsx2-coverity.xz

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
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)"
else
ncpu=$(grep -w -c processor /proc/cpuinfo)
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
set_ncpu_toolfile
set_make

for ARG in "$@"; do
case "$ARG" in
--clean ) cleanBuild=1 ;;
--clean-plugins ) cleanBuild=2 ;;
--clang-tidy ) flags="$flags -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"; clangTidy=1 ; useClang=1;;
--clang ) useClang=1 ;;
--intel ) useIcc=1 ;;
@@ -88,7 +221,7 @@ for ARG in "$@"; do
-D* ) flags="$flags $ARG" ;;

*)
echo $ARG
echo $ARG
# Unknown option
echo "** User options **"
echo "--dev / --devel : Build PCSX2 as a Development build."
@@ -97,6 +230,7 @@ for ARG in "$@"; do
echo "--release : Build PCSX2 as a Release build."
echo
echo "--clean : Do a clean build."
echo "--clean-plugins : Do a clean build of plugins, but not of pcsx2."
echo "--extra : Build all plugins"
echo "--no-simd : Only allow sse2"
echo
@@ -110,7 +244,8 @@ for ARG in "$@"; do
echo
echo "** Expert Developer option **"
echo "--gtk3 : replace GTK2 by GTK3"
echo "--no-cross-multilib: Build a native PCSX2"
echo "--no-cross-multilib: Build a native PCSX2 (nonfunctional recompiler)"
echo "--no-trans : Don't regenerate mo files when building."
echo "--clang : Build with Clang/llvm"
echo "--intel : Build with ICC (Intel compiler)"
echo "--lto : Use Link Time Optimization"
@@ -132,6 +267,9 @@ if [ "$cleanBuild" -eq 1 ]; then
echo "Doing a clean build."
# allow to keep build as a symlink (for example to a ramdisk)
rm -fr "$build"/*
elif [ "$cleanBuild" -eq 2 ]; then
echo "Doing a clean build on the plugins, but not pcsx2."
rm -fr "$build"/plugins/*
fi

if [ "$useCross" -eq 2 ] && [ "$(getconf LONG_BIT 2> /dev/null)" != 32 ]; then
@@ -141,20 +279,10 @@ elif [ "$useCross" -ne 1 ]; then
useCross=0
fi

# Helper to easily switch wx-config on my system
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
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
switch_wxconfig

# Workaround for Debian. Cmake failed to find freetype include path
if [ "$useCross" -eq 0 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/include/x86_64-linux-gnu/freetype2/ft2build.h" ]; then
export GTKMM_BASEPATH=/usr/include/x86_64-linux-gnu/freetype2
fi
if [ "$useCross" -eq 2 ] && [ "$(uname -m)" = "x86_64" ] && [ -e "/usr/include/i386-linux-gnu/freetype2/ft2build.h" ]; then
export GTKMM_BASEPATH=/usr/include/i386-linux-gnu/freetype2
fi
find_freetype

echo "Building pcsx2 with $flags" | tee "$log"

@@ -168,104 +296,27 @@ mkdir -p "$build"
# Cmake will generate file inside $CWD. It would be nicer if an option to cmake can be provided.
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


set_compiler

############################################################
# CPP check build
############################################################
if [ "$cppcheck" -eq 1 ] && command -v cppcheck >/dev/null ; then
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 \
XBYAK_USE_MMAP_ALLOCATOR MAP_ANONYMOUS MAP_ANON XBYAK_DISABLE_AVX512
do
define="$define -U$undef"
done
check="--enable=warning,style,missingInclude"
for d in pcsx2 common plugins/GSdx plugins/spu2\-x plugins/onepad plugins/cdvdGigaherz
do
flat_d=$(echo $d | sed -e 's@/@_@')
log=cpp_check__${flat_d}.log
rm -f "$log"

cppcheck $check -j $ncpu --platform=unix32 $define "$root/$d" 2>&1 | tee "$log"
# Create a small summary (warning it might miss some issues)
fgrep -e "(warning)" -e "(error)" -e "(style)" -e "(performance)" -e "(portability)" "$log" >> $summary
done
exit 0
run_cppcheck
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" | sort -u > $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
run_clangtidy
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
(cd "$build"; tar caf $coverity_result "$coverity_dir")
exit 0
run_coverity
fi

############################################################

0 comments on commit fc35de0

Please sign in to comment.
You can’t perform that action at this time.