Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 4cd9912

Browse files
Merge pull request #134 from youpong/refactor-build-tool
Refactor build tool
2 parents 01a2bec + f31043e commit 4cd9912

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: configure
19-
run: ./configure
19+
run: ./configure --enable-code-coverage
2020
- name: build
21-
run: make COVERAGE_TEST=1
21+
run: make -j
2222
- name: check
2323
run: make check
2424
- name: gcov

configure

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -o nounset
55
PROJECT=procfetch
66
VERSION="$(cat VERSION)"
77
CXX=g++
8+
CXXFLAGS=${CXXFLAGS:-}
9+
LIBS=${LIBS:-}
810
unset PREFIX
911
BIN_DIR=/bin
1012
LIB_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>
3035
EOF
3136
exit $1
3237
}
@@ -37,19 +42,23 @@ EOF
3742

3843
help_option=0
3944
version_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 -- "$@")
4249
if [[ $? != 0 ]]; then
4350
show_usage 1
4451
fi
4552

4653
eval set -- "$parsed_arguments"
4754
while 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
7584
fi
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+
7796
BIN_DIR="${PREFIX:-}${BIN_DIR}"
7897
LIB_DIR="${PREFIX:-/usr}${LIB_DIR}"
7998

@@ -82,6 +101,8 @@ do
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"
87108
done

src/Makefile.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ SRCS = fetch.cpp main.cpp util.cpp
33
OBJS = $(SRCS:.cpp=.o)
44

55
CXX = @CXX@
6-
CXXFLAGS = -std=c++2a -Wall -Wextra --pedantic-errors
7-
8-
ifeq ($(COVERAGE_TEST), 1)
9-
CXXFLAGS += -fprofile-arcs -ftest-coverage -O0
10-
LIBS += -lgcov
11-
endif
6+
CXXFLAGS = -std=c++2a -Wall -Wextra --pedantic-errors @CXXFLAGS@
7+
LIBS = @LIBS@
128

139
INSTALL = /usr/bin/install -c -D
1410
FORMATTER = clang-format -i

0 commit comments

Comments
 (0)