This script builds cppcheck for installation in a non-standard location (i.e., not /usr or /usr/local).
Usage
build_cppcheck.sh
Notes
The script downloads cppcheck, unpacks the compressed tarball, and invokes make on the source directory.
The PACKAGE, VERSION and INSTALL_PREFIX variables can be modified if needed.
Since cppcheck requires C++1x support, and since the system compiler on RH6 doesn’t support C++1x, we need to build with a different compiler. Which means that cppcheck needs to be able to find that compiler’s libtsdc++ at runtime. To faciliate that, we set the RPATH of the executable to the library directory of the compiler. (Note that the approach used assumes we’re using gcc).
#!/bin/bash## Copyright 2016 by Bill Torpey. All Rights Reserved.# This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License.# http://creativecommons.org/licenses/by-nc-nd/3.0/us/deed.en#set -exv
PACKAGE=cppcheck
VERSION=1.73
## NOTE: cppcheck requires pcre-devel package (yum install pcre-devel)## location where package should be installedINSTALL_PREFIX=/build/share/${PACKAGE}/${VERSION}# uncomment following to get verbose output from make#VERBOSE=VERBOSE=1# find compiler libraries to use in RPATH settingCOMPILER=${CXX}[[ -z ${COMPILER}]]&&COMPILER=g++
RPATH=$(dirname $(dirname $(which ${COMPILER})))/lib64
[[ -e ${PACKAGE}-${VERSION}.tar.gz ]]|| wget --no-check-certificate -nv https://sourceforge.net/projects/${PACKAGE}/files/${PACKAGE}/${VERSION}/${PACKAGE}-${VERSION}.tar.gz
rm -rf ${PACKAGE}-${VERSION}tar xvfz ${PACKAGE}-${VERSION}.tar.gz
# delete oldrm -rf ${INSTALL_PREFIX}cd${PACKAGE}-${VERSION}make clean
make ${VERBOSE}PREFIX=${INSTALL_PREFIX}CFGDIR=${INSTALL_PREFIX}/cfg HAVE_RULES=yes LDFLAGS="-Wl,--rpath=${RPATH}" install