@@ -5,6 +5,8 @@ set -o nounset
55PROJECT=procfetch
66VERSION=" $( cat VERSION) "
77CXX=g++
8+ CXXFLAGS=${CXXFLAGS:- }
9+ LIBS=${LIBS:- }
810unset PREFIX
911BIN_DIR=/bin
1012LIB_DIR=/share/procfetch
@@ -20,13 +22,16 @@ function show_usage {
2022 Usage: $0 [OPTION]...
2123
2224 Options:
23- -h, --help display this help and exit.
24- -v, --versoin display version information and exit.
25- --prefix=PREFIX install files in PREFIX.
26- --with-cxx=CXX use CXX to compile (default=gcc).
25+ -h, --help display this help and exit.
26+ -v, --versoin display version information and exit.
27+ --prefix=PREFIX install files in PREFIX.
28+ --with-cxx=CXX use CXX to compile (default=gcc).
29+ --enable-code-coverage enable coverage testing
2730
2831 Some influential environment variables:
29- CXX C++ compiler command
32+ CXX C++ compiler command
33+ CXXFLAGS C++ compiler flags
34+ LIBS libraries to pass to the linker, e.g. -l<library>
3035EOF
3136 exit $1
3237}
3742
3843help_option=0
3944version_option=0
45+ code_coverage_option=0
4046
41- parsed_arguments=$( getopt -n $0 -o hv --long help,version,prefix:,with-cxx: -- " $@ " )
47+ parsed_arguments=$( getopt -n $0 -o hv \
48+ --long help,version,prefix:,with-cxx:,enable-code-coverage -- " $@ " )
4249if [[ $? != 0 ]]; then
4350 show_usage 1
4451fi
4552
4653eval set -- " $parsed_arguments "
4754while true ; do
4855 case " $1 " in
49- -h | --help ) help_option=1 ; shift ;;
50- -v | --version ) version_option=1 ; shift ;;
51- --prefix ) PREFIX=" $2 " ; shift 2 ;;
52- --with-cxx ) CXX=" $2 " ; shift 2 ;;
56+ -h | --help ) help_option=1 ; shift ;;
57+ -v | --version ) version_option=1 ; shift ;;
58+ --prefix ) PREFIX=" $2 " ; shift 2 ;;
59+ --with-cxx ) CXX=" $2 " ; shift 2 ;;
60+ --enable-code-coverage )
61+ code_coverage_option=1 ; shift ;;
5362 --) shift ; break ;;
5463 * ) echo " Error: Unknown option: $1 "
5564 show_usage 1;;
@@ -74,6 +83,16 @@ if [[ $version_option == 1 ]]; then
7483 exit 0
7584fi
7685
86+ if [[ $code_coverage_option == 1 ]]; then
87+ if [[ $CXX =~ clang\+\+ ]]; then # for clang++
88+ echo " Not implemented yet"
89+ exit 1
90+ else # for gcc
91+ CXXFLAGS=" -fprofile-arcs -ftest-coverage -O0"
92+ LIBS=" -lgcov"
93+ fi
94+ fi
95+
7796BIN_DIR=" ${PREFIX:- }${BIN_DIR} "
7897LIB_DIR=" ${PREFIX:-/ usr}${LIB_DIR} "
7998
82101 echo " creating $f "
83102 sed -e " s/@VERSION@/${VERSION} /g" \
84103 -e " s/@CXX@/${CXX} /g" \
104+ -e " s/@CXXFLAGS@/${CXXFLAGS} /g" \
105+ -e " s/@LIBS@/${LIBS} /g" \
85106 -e " s:@BIN_DIR@:${BIN_DIR} :g" \
86107 -e " s:@LIB_DIR@:${LIB_DIR} :g" " $f .in" > " $f "
87108done
0 commit comments