diff --git a/tests/Makefile.am b/tests/Makefile.am index 6bcbaaeb7d..96019defcb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,11 +1,21 @@ +# +# Copyright 2020-2022 the Pacemaker project contributors +# +# The version control history for this file may have further details. +# +# This source code is licensed under the GNU General Public License version 2 +# or later (GPLv2+) WITHOUT ANY WARRANTY. +# + # tap-test is copied from /usr/share/automake-*/tap-driver.sh. EXTRA_DIST = tap-driver.sh \ tap-test \ test-headers.sh check: check-headers .PHONY: check-headers check-headers: - cd $(abs_srcdir); \ - CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" CXX="$(CXX)" CPPFLAGS="$(CPPFLAGS)" LIBS="$(LIBS)" sh test-headers.sh + CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" \ + CXX="$(CXX)" CPPFLAGS="$(CPPFLAGS)" LIBS="$(LIBS)" \ + SRCDIR="$(top_srcdir)" sh "$(srcdir)/test-headers.sh" diff --git a/tests/test-headers.sh b/tests/test-headers.sh index 0cdda170de..b1204342bc 100644 --- a/tests/test-headers.sh +++ b/tests/test-headers.sh @@ -1,44 +1,47 @@ #!/bin/sh # # Check public headers for c++ compatibility and consistent protection #ifdefs # # -INCLUDE_FILES="`find ../include/ -name \*.h -a \! -name \*internal.h`" +: ${SRCDIR:-..} + +INCLUDE_FILES="$(find "${SRCDIR}/include/" -name \*.h \ + -a \! -name \*internal.h \ + -a \! -name config.h \ + -a \! -name gettext.h)" + +TESTFILE="$(mktemp "${TMPDIR:-/tmp}/test-headers-XXXXXXXXXX.c")" for i in $INCLUDE_FILES do - NAME="`echo $i | cut -c12-`" - - # config.h is generated by autoconf - # gettext.h is supplied by gettext - if [ "$NAME" = "config.h" ] || [ "$NAME" = "gettext.h" ] - then - continue - fi - PROTECT="PCMK__`echo $NAME | tr '[:lower:]' '[:upper:]' | tr '/\.' '_' |tr '-' '_' `" - PROTECT=`echo $PROTECT|sed 's/_H/__H/'` # PCMK uses double underscore for .h (eg NAME__H) + NAME="$(echo $i | sed -e 's#^.*/include/##')" + PROTECT="PCMK__$(echo "$NAME" | tr '[:lower:]/\-\.' '[:upper:]___' | sed 's/_H$/__H/')" - echo "#include <$NAME>" > _test_file.c - echo "#ifndef $PROTECT" >> _test_file.c - echo "#error no header protector in file $i" >> _test_file.c - echo "#endif" >> _test_file.c - echo "int main(void) {return 0;}" >> _test_file.c + cat >"$TESTFILE" < +#ifndef $PROTECT +#error no header protector in file $i +#endif +int main(void) {return 0;} +EOF # Not including ${CFLAGS} because it seems to break header detection. But we're not really building here - ${CC} -I ../include -DHAVE_CONFIG_H ${CPPFLAGS} ${LIBS} _test_file.c -o /dev/null + ${CC} -I "${SRCDIR}/include" -DHAVE_CONFIG_H ${CPPFLAGS} ${LIBS} "$TESTFILE" -o /dev/null if [ $? -ne 0 ] then + rm -f "$TESTFILE" exit 1 fi if [ "$CXX" ] && [ command -v "$CXX" >/dev/null 2>&1 ] then - ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LIBS} -I ../include _test_file.c -o /dev/null + ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LIBS} -I "${SRCDIR}/include" "$TESTFILE" -o /dev/null if [ $? -ne 0 ] then + rm -f "$TESTFILE" exit 1 fi echo -n fi - rm -f _test_file.c + rm -f "$TESTFILE" done