#!/bin/bash

install_version=${1:-"2.0"}
package_name="cppcheck-${install_version}"

# Install lib
apt install -y libpcre3-dev

# Download
cd /tmp
rm -f ${package_name}.tar.gz
wget https://tools.mindspore.cn/tools/check/cppcheck/${package_name}/${package_name}.tar.gz
rm -rf ${package_name}
tar -xf ${package_name}.tar.gz

# Install
cd /tmp/${package_name}
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function" -j8
make install FILESDIR=/usr/share/cppcheck -j8
cd ..

# Delete package
rm -rf /tmp/${package_name}
rm -f /tmp/${package_name}.tar.gz
