Skip to content

Commit cb5131a

Browse files
committed
Turn off optimisation for test build.
1 parent 2df7386 commit cb5131a

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

configure.ac

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,31 @@ AC_PROG_LIBTOOL
99
AC_PROG_INSTALL
1010
AC_PROG_MAKE_SET
1111

12+
if [[ "$GCC" = "yes" ]]; then
13+
is_gcc=true
14+
else
15+
is_gcc=false
16+
fi
17+
18+
TEST_CFLAGS=""
19+
20+
# Turn on all warnings for gcc. Turn off optimisation for the test build.
21+
22+
if $is_gcc; then
23+
CFLAGS="$CFLAGS -Wall"
24+
TEST_CFLAGS="$TEST_CFLAGS -Wall -O0"
25+
fi
26+
1227
# Support for coverage analysis via gcov:
1328

1429
coverage=no
1530
AC_ARG_ENABLE(coverage,
1631
[ --enable-coverage Enable coverage testing. ],
1732
[ coverage=yes ])
1833

19-
COV_FLAGS=""
20-
2134
if [[ "$coverage" = "yes" ]]; then
22-
if [[ "$GCC" = "yes" ]]; then
23-
COV_FLAGS="-fprofile-arcs -ftest-coverage"
35+
if $is_gcc; then
36+
TEST_CFLAGS="$TEST_CFLAGS -fprofile-arcs -ftest-coverage"
2437
else
2538
AC_MSG_ERROR([Can only enable coverage when using gcc.])
2639
fi
@@ -43,9 +56,16 @@ fi
4356

4457
AM_CONDITIONAL(USE_VALGRIND, $use_valgrind)
4558

59+
# Save the default CFLAGS and clear them, so that the test build
60+
# of the library doesn't get the optimisation flags.
61+
62+
MAIN_CFLAGS="$CFLAGS"
63+
CFLAGS=""
64+
4665
AM_CONFIG_HEADER(config.h:config.h.in)
4766

48-
AC_SUBST(COV_FLAGS)
67+
AC_SUBST(MAIN_CFLAGS)
68+
AC_SUBST(TEST_CFLAGS)
4969
AC_SUBST(ac_aux_dir)
5070

5171
AC_OUTPUT([

src/Makefile.am

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
AM_CFLAGS = -Wall
3-
42
check_LIBRARIES=libcalgtest.a
53
lib_LTLIBRARIES=libcalg.la
64

@@ -18,9 +16,10 @@ avl-tree.c compare-string.c hash-string.c queue.c trie.c \
1816
compare-int.c hash-int.c hash-table.c set.c binary-heap.c \
1917
bloom-filter.c binomial-heap.c
2018

21-
libcalgtest_a_CFLAGS=$(COV_FLAGS) -O0 -DALLOC_TESTING -I../test
19+
libcalgtest_a_CFLAGS=$(TEST_CFLAGS) -DALLOC_TESTING -I../test
2220
libcalgtest_a_SOURCES=$(SRC) $(MAIN_HEADERFILES)
2321

22+
libcalg_la_CFLAGS=$(MAIN_CFLAGS)
2423
libcalg_la_SOURCES=$(SRC) $(MAIN_HEADERFILES) $(CALG_HEADERFILES)
2524

2625
headerfilesdir=$(includedir)/libcalg-1.0

test/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ libtestframework_a_SOURCES=\
2727
alloc-testing.c alloc-testing.h \
2828
framework.c framework.h
2929

30-
AM_CFLAGS = $(COV_FLAGS) -I../src -Wall
30+
AM_CFLAGS = $(TEST_CFLAGS) -I../src
3131
LDADD = $(top_builddir)/src/libcalgtest.a libtestframework.a
3232

3333
EXTRA_DIST=valgrind-wrapper

0 commit comments

Comments
 (0)