Confessions of a Wall Street Programmer

practical ideas (and perhaps some uncommon knowledge) on software architecture, design, construction and testing

build_cppcheck.sh

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).

See this post for more information.

Code Listing

(build_cppcheck.sh) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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 installed
INSTALL_PREFIX=/build/share/${PACKAGE}/${VERSION}
# uncomment following to get verbose output from make
#VERBOSE=VERBOSE=1

# find compiler libraries to use in RPATH setting
COMPILER=${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 old
rm -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

Comments