diff --git a/Makefile.am b/Makefile.am index a19c382..f188cda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,81 +1,103 @@ # Makefile.am - main makefile for libksba # Copyright (C) 2001, 2002 g10 Code GmbH # # This file is part of KSBA. # # KSBA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # KSBA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . ## Process this file with automake to produce Makefile.in ACLOCAL_AMFLAGS = -I m4 -I gl/m4 DISTCHECK_CONFIGURE_FLAGS = --enable-doc # (A suitable gitlog-to-changelog script can be found in GnuPG master.) GITLOG_TO_CHANGELOG=gitlog-to-changelog EXTRA_DIST = autogen.sh autogen.rc \ COPYING.GPLv2 COPYING.GPLv3 COPYING.LGPLv3 \ ChangeLog-2011 doc/ChangeLog-2011 src/ChangeLog-2011 \ tests/ChangeLog-2011 \ build-aux/git-log-footer build-aux/git-log-fix if CROSS_COMPILING tests = else tests = tests endif if BUILD_DOC doc = doc else doc = endif SUBDIRS = m4 gl src $(tests) $(doc) dist-hook: gen-ChangeLog distcheck-hook: set -e; ( \ pref="#+macro: $$(echo $(PACKAGE_NAME)|tr '-' '_')_" ;\ reldate="$$(date -u +%Y-%m-%d)" ;\ echo "$${pref}ver $(PACKAGE_VERSION)" ;\ echo "$${pref}date $${reldate}" ;\ list='$(DIST_ARCHIVES)'; for i in $$list; do \ case "$$i" in *.tar.bz2) \ echo "$${pref}size $$(wc -c <$$i|awk '{print int($$1/1024)}')k" ;\ echo "$${pref}sha1 $$(sha1sum <$$i|cut -d' ' -f1)" ;\ echo "$${pref}sha2 $$(sha256sum <$$i|cut -d' ' -f1)" ;;\ esac;\ done ) | tee $(distdir).swdb gen_start_date = 2011-12-01T00:00:00 .PHONY: gen-ChangeLog gen-ChangeLog: if test -d $(top_srcdir)/.git; then \ (cd $(top_srcdir) && \ $(GITLOG_TO_CHANGELOG) --append-dot --tear-off \ --amend=build-aux/git-log-fix \ --since=$(gen_start_date) ) > $(distdir)/cl-t; \ cat $(top_srcdir)/build-aux/git-log-footer >> $(distdir)/cl-t;\ rm -f $(distdir)/ChangeLog; \ mv $(distdir)/cl-t $(distdir)/ChangeLog; \ fi stowinstall: $(MAKE) $(AM_MAKEFLAGS) install prefix=/usr/local/stow/libksba + +# Coverage targets +if HAVE_GCOV + +.PHONY: clean-coverage +clean-coverage: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + -find -name '*.gcno' -print | xargs -r rm + -rm -rf coverage.info coveragereport + +.PHONY: coverage-html clean-coverage +coverage-html: check + @echo Collecting coverage data with lcov + $(top_srcdir)/autogen.sh --coverage $(LCOV) $(GCOV) $(abs_builddir) \ + tests src + $(top_srcdir)/autogen.sh --report $(LCOV) $(GENHTML) $(abs_builddir) \ + '*/tests/*' '*/asn1-parse.c' '*/asn1-parse.y' + +clean-local: clean-coverage + +endif # HAVE_GCOV diff --git a/autogen.sh b/autogen.sh index 7effd56..3771c58 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,468 +1,532 @@ #! /bin/sh # autogen.sh # Copyright (C) 2003, 2014 g10 Code GmbH # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # This is a generic script to create the configure script and handle cross # build environments. It requires the presence of a autogen.rc file to # configure it for the respective package. It is maintained as part of # GnuPG and source copied by other packages. # # Version: 2014-06-06 configure_ac="configure.ac" cvtver () { awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}' } check_version () { if [ $(( `("$1" --version || echo "0") | cvtver` >= $2 )) = 1 ]; then return 0 fi echo "**Error**: "\`$1\'" not installed or too old." >&2 echo ' Version '$3' or newer is required.' >&2 [ -n "$4" ] && echo ' Note that this is part of '\`$4\''.' >&2 DIE="yes" return 1 } fatal () { echo "autogen.sh:" "$*" >&2 DIE=yes } info () { if [ -z "${SILENT}" ]; then echo "autogen.sh:" "$*" >&2 fi } die_p () { if [ "$DIE" = "yes" ]; then echo "autogen.sh: Stop." >&2 exit 1 fi } replace_sysroot () { configure_opts=$(echo $configure_opts | sed "s#@SYSROOT@#${w32root}#g") extraoptions=$(echo $extraoptions | sed "s#@SYSROOT@#${w32root}#g") } # Allow to override the default tool names AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX} AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX} AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX} ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX} GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX} MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX} DIE=no FORCE= SILENT= PRINT_HOST=no PRINT_BUILD=no tmp=$(dirname "$0") tsdir=$(cd "${tmp}"; pwd) version_parts=3 if [ -n "${AUTOGEN_SH_SILENT}" ]; then SILENT=" --silent" fi if test x"$1" = x"--help"; then echo "usage: ./autogen.sh [--silent] [--force] [--build-TYPE] [ARGS]" exit 0 fi if test x"$1" = x"--silent"; then SILENT=" --silent" shift fi if test x"$1" = x"--force"; then FORCE=" --force" shift fi if test x"$1" = x"--print-host"; then PRINT_HOST=yes shift fi if test x"$1" = x"--print-build"; then PRINT_BUILD=yes shift fi # Reject unsafe characters in $HOME, $tsdir and cwd. We consider spaces # as unsafe because it is too easy to get scripts wrong in this regard. am_lf=' ' case `pwd` in *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*) fatal "unsafe working directory name" ;; esac case $tsdir in *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*) fatal "unsafe source directory: \`$tsdir'" ;; esac case $HOME in *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*) fatal "unsafe home directory: \`$HOME'" ;; esac die_p # List of variables sourced from autogen.rc. The strings '@SYSROOT@' in # these variables are replaced by the actual system root. configure_opts= extraoptions= # List of optional variables sourced from autogen.rc and ~/.gnupg-autogen.rc w32_toolprefixes= w32_extraoptions= w32ce_toolprefixes= w32ce_extraoptions= w64_toolprefixes= w64_extraoptions= amd64_toolprefixes= # End list of optional variables sourced from ~/.gnupg-autogen.rc # What follows are variables which are sourced but default to # environment variables or lacking them hardcoded values. #w32root= #w32ce_root= #w64root= #amd64root= # Convenience option to use certain configure options for some hosts. myhost="" myhostsub="" case "$1" in --find-version) myhost="find-version" SILENT=" --silent" shift ;; --build-w32) myhost="w32" shift ;; --build-w32ce) myhost="w32" myhostsub="ce" shift ;; --build-w64) myhost="w32" myhostsub="64" shift ;; --build-amd64) myhost="amd64" shift ;; --build*) fatal "**Error**: invalid build option $1" shift ;; + --coverage) + myhost="coverage" + shift + ;; + --report) + myhost="report" + shift + ;; *) ;; esac die_p # Source our configuration if [ -f "${tsdir}/autogen.rc" ]; then . "${tsdir}/autogen.rc" fi # Source optional site specific configuration if [ -f "$HOME/.gnupg-autogen.rc" ]; then info "sourcing extra definitions from $HOME/.gnupg-autogen.rc" . "$HOME/.gnupg-autogen.rc" fi # **** FIND VERSION **** # This is a helper for the configure.ac M4 magic # Called # ./autogen.sh --find-version PACKAGE MAJOR MINOR [MICRO] # returns a complete version string with automatic beta numbering. if [ "$myhost" = "find-version" ]; then package="$1" major="$2" minor="$3" micro="$4" case "$version_parts" in 2) matchstr1="$package-$major.[0-9]*" matchstr2="$package-$major-base" vers="$major.$minor" ;; *) matchstr1="$package-$major.$minor.[0-9]*" matchstr2="$package-$major.$minor-base" vers="$major.$minor.$micro" ;; esac beta=no if [ -d .git ]; then ingit=yes tmp=$(git describe --match "${matchstr1}" --long 2>/dev/null) if [ -n "$tmp" ]; then tmp=$(echo "$tmp"|awk -F- '$3!=0 && $3 !~ /^beta/ {print"-beta"$3}') else tmp=$(git describe --match "${matchstr2}" --long 2>/dev/null \ | awk -F- '$4!=0{print"-beta"$4}') fi [ -n "$tmp" ] && beta=yes rev=$(git rev-parse --short HEAD | tr -d '\n\r') rvd=$((0x$(echo ${rev} | head -c 4))) else ingit=no beta=yes tmp="-unknown" rev="0000000" rvd="0" fi echo "$package-$vers$tmp:$beta:$ingit:$vers$tmp:$vers:$tmp:$rev:$rvd:" exit 0 fi # **** end FIND VERSION **** +# **** COVERAGE **** +# This is a helper for the code coverage collection +# Called +# ./autogen.sh --coverage lcov gcov [dirs...] +if [ "$myhost" = "coverage" ]; then + LCOV="$1" + GCOV="$2" + BASE=`realpath "$3"` + COVINFO="" + + shift 3 + + while [ x"$1" != "x" ]; do + P="$1" + $LCOV --gcov-tool $GCOV \ + --base-directory "$BASE"/"$P" \ + --directory "$P" \ + --output-file coverage.info.`basename "$P"` \ + --capture --no-checksum --compat-libtool \ + --rc lcov_branch_coverage=1 + COVINFO="$COVINFO -a coverage.info."`basename "$P"` + shift + done + + $LCOV $COVINFO --base-directory "$BASE" --output-file coverage.info \ + --no-checksum \ + --rc lcov_branch_coverage=1 + + exit 0 +fi +# **** end COVERAGE **** + +# **** COVERAGE_REPORT **** +# This is a helper for the code coverage report +# Called +# ./autogen.sh --report lcov genhtml [exclude...] +if [ "$myhost" = "report" ]; then + LCOV="$1" + GENHTML="$2" + + shift 2 + + while [ x"$1" != "x" ]; do + P="$1" + $LCOV --remove coverage.info "$P" -o coverage.info \ + --rc lcov_branch_coverage=1 + shift + done + + LANG=C $GENHTML --output-directory coveragereport --title "Code Coverage" \ + --legend --show-details coverage.info \ + --rc lcov_branch_coverage=1 + + exit 0 +fi +# **** end COVERAGE_REPORT **** if [ ! -f "$tsdir/build-aux/config.guess" ]; then fatal "$tsdir/build-aux/config.guess not found" exit 1 fi build=`$tsdir/build-aux/config.guess` if [ $PRINT_BUILD = yes ]; then echo "$build" exit 0 fi # ****************** # W32 build script # ****************** if [ "$myhost" = "w32" ]; then case $myhostsub in ce) w32root="$w32ce_root" [ -z "$w32root" ] && w32root="$HOME/w32ce_root" toolprefixes="$w32ce_toolprefixes arm-mingw32ce" extraoptions="$extraoptions $w32ce_extraoptions" ;; 64) w32root="$w64root" [ -z "$w32root" ] && w32root="$HOME/w64root" toolprefixes="$w64_toolprefixes x86_64-w64-mingw32" extraoptions="$extraoptions $w64_extraoptions" ;; *) [ -z "$w32root" ] && w32root="$HOME/w32root" toolprefixes="$w32_toolprefixes i686-w64-mingw32 i586-mingw32msvc" toolprefixes="$toolprefixes i386-mingw32msvc mingw32" extraoptions="$extraoptions $w32_extraoptions" ;; esac info "Using $w32root as standard install directory" replace_sysroot # Locate the cross compiler crossbindir= for host in $toolprefixes; do if ${host}-gcc --version >/dev/null 2>&1 ; then crossbindir=/usr/${host}/bin conf_CC="CC=${host}-gcc" break; fi done if [ -z "$crossbindir" ]; then fatal "cross compiler kit not installed" if [ -z "$myhostsub" ]; then info "Under Debian GNU/Linux, you may install it using" info " apt-get install mingw32 mingw32-runtime mingw32-binutils" fi die_p fi if [ $PRINT_HOST = yes ]; then echo "$host" exit 0 fi if [ -f "$tsdir/config.log" ]; then if ! head $tsdir/config.log | grep "$host" >/dev/null; then fatal "Please run a 'make distclean' first" die_p fi fi $tsdir/configure --enable-maintainer-mode ${SILENT} \ --prefix=${w32root} \ --host=${host} --build=${build} SYSROOT=${w32root} \ ${configure_opts} ${extraoptions} "$@" rc=$? exit $rc fi # ***** end W32 build script ******* # ***** AMD64 cross build script ******* # Used to cross-compile for AMD64 (for testing) if [ "$myhost" = "amd64" ]; then [ -z "$amd64root" ] && amd64root="$HOME/amd64root" info "Using $amd64root as standard install directory" replace_sysroot toolprefixes="$amd64_toolprefixes x86_64-linux-gnu amd64-linux-gnu" # Locate the cross compiler crossbindir= for host in $toolprefixes ; do if ${host}-gcc --version >/dev/null 2>&1 ; then crossbindir=/usr/${host}/bin conf_CC="CC=${host}-gcc" break; fi done if [ -z "$crossbindir" ]; then echo "Cross compiler kit not installed" >&2 echo "Stop." >&2 exit 1 fi if [ $PRINT_HOST = yes ]; then echo "$host" exit 0 fi if [ -f "$tsdir/config.log" ]; then if ! head $tsdir/config.log | grep "$host" >/dev/null; then echo "Please run a 'make distclean' first" >&2 exit 1 fi fi $tsdir/configure --enable-maintainer-mode ${SILENT} \ --prefix=${amd64root} \ --host=${host} --build=${build} \ ${configure_opts} ${extraoptions} "$@" rc=$? exit $rc fi # ***** end AMD64 cross build script ******* # Grep the required versions from configure.ac autoconf_vers=`sed -n '/^AC_PREREQ(/ { s/^.*(\(.*\))/\1/p q }' ${configure_ac}` autoconf_vers_num=`echo "$autoconf_vers" | cvtver` automake_vers=`sed -n '/^min_automake_version=/ { s/^.*="\(.*\)"/\1/p q }' ${configure_ac}` automake_vers_num=`echo "$automake_vers" | cvtver` if [ -d "${tsdir}/po" ]; then gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { s/^.*\[\(.*\)])/\1/p q }' ${configure_ac}` gettext_vers_num=`echo "$gettext_vers" | cvtver` else gettext_vers="n/a" fi if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ] then echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2 exit 1 fi if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf fi if check_version $AUTOMAKE $automake_vers_num $automake_vers; then check_version $ACLOCAL $automake_vers_num $autoconf_vers automake fi if [ "$gettext_vers" != "n/a" ]; then if check_version $GETTEXT $gettext_vers_num $gettext_vers; then check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext fi fi if [ "$DIE" = "yes" ]; then cat <. # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) min_automake_version="1.14" # To build a release you need to create a tag with the version number # (git tag -s libksba-n.m.k) and run "./autogen.sh --force". Please # bump the version number immediately after the release and do another # commit and push so that the git magic is able to work. See below # for the LT versions. m4_define([mym4_package],[libksba]) m4_define([mym4_major], [1]) m4_define([mym4_minor], [3]) m4_define([mym4_micro], [6]) # Below is m4 magic to extract and compute the git revision number, # the decimalized short revision number, a beta version string and a # flag indicating a development version (mym4_isbeta). Note that the # m4 processing is done by autoconf and not during the configure run. m4_define([mym4_verslist], m4_split(m4_esyscmd([./autogen.sh --find-version] \ mym4_package mym4_major mym4_minor mym4_micro),[:])) m4_define([mym4_isbeta], m4_argn(2, mym4_verslist)) m4_define([mym4_version], m4_argn(4, mym4_verslist)) m4_define([mym4_revision], m4_argn(7, mym4_verslist)) m4_define([mym4_revision_dec], m4_argn(8, mym4_verslist)) m4_esyscmd([echo ]mym4_version[>VERSION]) AC_INIT([mym4_package],[mym4_version], [http://bugs.gnupg.org]) # LT Version numbers: Remember to change them just *before* a release. # (Interfaces removed: CURRENT++, AGE=0, REVISION=0) # (Interfaces added: CURRENT++, AGE++, REVISION=0) # (No interfaces changed: REVISION++) # Please remember to document interface changes in the NEWS file. LIBKSBA_LT_CURRENT=19 LIBKSBA_LT_AGE=11 LIBKSBA_LT_REVISION=6 #------------------- # If the API is changed in an incompatible way: increment the next counter. KSBA_CONFIG_API_VERSION=1 NEED_GPG_ERROR_VERSION=1.8 PACKAGE=$PACKAGE_NAME VERSION=$PACKAGE_VERSION AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_SRCDIR([src/ksba.h]) AM_INIT_AUTOMAKE([serial-tests dist-bzip2 no-dist-gzip]) AM_CONFIG_HEADER(config.h) AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_HOST AB_INIT AC_GNU_SOURCE LT_PREREQ([2.2.6]) LT_INIT([win32-dll disable-static]) LT_LANG([Windows Resource]) AM_MAINTAINER_MODE AC_SUBST(LIBKSBA_LT_CURRENT) AC_SUBST(LIBKSBA_LT_AGE) AC_SUBST(LIBKSBA_LT_REVISION) AC_SUBST(PACKAGE) AC_SUBST(VERSION) AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package]) AH_TOP([ #ifndef _KSBA_CONFIG_H_INCLUDED #define _KSBA_CONFIG_H_INCLUDED /* Enable gpg-error's strerror macro for W32CE. */ #define GPG_ERR_ENABLE_ERRNO_MACROS 1 ]) AH_BOTTOM([ #endif /*_KSBA_CONFIG_H_INCLUDED*/ ]) # Checks for programs. missing_dir=`cd $ac_aux_dir && pwd` AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) AM_SILENT_RULES AC_PROG_AWK AC_PROG_CC AC_PROG_CPP AM_PROG_CC_C_O if test "x$ac_cv_prog_cc_c89" = "xno" ; then AC_MSG_ERROR([[No C-89 compiler found]]) fi AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET gl_EARLY #AC_ARG_PROGRAM AC_PROG_YACC AX_PROG_BISON([have_bison=yes],[have_bison=no]) +if test "$USE_MAINTAINER_MODE" = "yes"; then + # gcov coverage reporting + AC_CHECK_PROGS(GCOV, [gcov], gcov) + AC_TDD_GCOV + AC_SUBST(COVERAGE_CFLAGS) + AC_SUBST(COVERAGE_LDFLAGS) +fi + AC_C_INLINE # We need to compile and run a program on the build machine. # The AC_PROG_CC_FOR_BUILD macro in the AC archive is broken for # autoconf 2.57. AC_MSG_CHECKING(for cc for build) if test "$cross_compiling" = "yes"; then CC_FOR_BUILD="${CC_FOR_BUILD-cc}" else CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" fi AC_MSG_RESULT($CC_FOR_BUILD) AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) # This is handy for debugging so the compiler doesn't rearrange # things and eliminate variables. AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable compiler optimization]), [if test $enableval = no ; then CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'` fi]) if test "$GCC" = yes; then CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" if test "$USE_MAINTAINER_MODE" = "yes"; then CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security" # We use -W only if -Wno-missing-field-initializers is supported. # -W is important because it detects errors like "if (foo);" AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wno-missing-field-initializers" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no) AC_MSG_RESULT($_gcc_wopt) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_wopt" = xyes ; then CFLAGS="$CFLAGS -W -Wno-sign-compare -Wno-missing-field-initializers" fi AC_MSG_CHECKING([if gcc supports -Wdeclaration-after-statement]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wdeclaration-after-statement" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no) AC_MSG_RESULT($_gcc_wopt) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_wopt" = xyes ; then CFLAGS="$CFLAGS -Wdeclaration-after-statement" fi fi AC_MSG_CHECKING([if gcc supports -Wpointer-arith]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wpointer-arith" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no) AC_MSG_RESULT($_gcc_wopt) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_wopt" = xyes ; then CFLAGS="$CFLAGS -Wpointer-arith" fi AC_MSG_CHECKING([if gcc supports -Wno-pointer-sign]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wno-pointer-sign" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_psign=yes,_gcc_psign=no) AC_MSG_RESULT($_gcc_psign) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_psign" = xyes ; then CFLAGS="$CFLAGS -Wno-pointer-sign" fi fi # Setup some stuff depending on host. have_w32_system=no have_w32ce_system=no case "${host}" in *-*-mingw32ce*) have_w32_system=yes have_w32ce_system=yes ;; *-*-mingw32*) have_w32_system=yes ;; *-apple-darwin*) AC_DEFINE(_DARWIN_C_SOURCE, 900000L, Expose all libc features (__DARWIN_C_FULL).) ;; *) ;; esac if test "$have_w32_system" = yes; then AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system]) if test "$have_w32ce_system" = yes; then AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE]) fi fi AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes) AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes) # For some systems we know that we have ld_version scripts. # Use it then as default. have_ld_version_script=no case "${host}" in *-*-linux*) have_ld_version_script=yes ;; *-*-gnu*) have_ld_version_script=yes ;; esac AC_ARG_ENABLE([ld-version-script], AC_HELP_STRING([--enable-ld-version-script], [enable/disable use of linker version script. (default is system dependent)]), [have_ld_version_script=$enableval], [ : ] ) AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes") # # Check for ELF visibility support. # AC_CACHE_CHECK(whether the visibility attribute is supported, ksba_cv_visibility_attribute, [ksba_cv_visibility_attribute=no AC_LANG_CONFTEST([AC_LANG_SOURCE( [[int foo __attribute__ ((visibility ("hidden"))) = 1; int bar __attribute__ ((visibility ("protected"))) = 1; ]])]) if ${CC-cc} -Werror -S conftest.c -o conftest.s \ 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then ksba_cv_visibility_attribute=yes fi fi fi ]) if test "$ksba_cv_visibility_attribute" = "yes"; then AC_CACHE_CHECK(for broken visibility attribute, ksba_cv_broken_visibility_attribute, [ksba_cv_broken_visibility_attribute=yes AC_LANG_CONFTEST([AC_LANG_SOURCE( [[int foo (int x); int bar (int x) __asm__ ("foo") __attribute__ ((visibility ("hidden"))); int bar (int x) { return x; } ]])]) if ${CC-cc} -Werror -S conftest.c -o conftest.s \ 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then if grep '\.hidden@<:@ _@:>@foo' conftest.s >/dev/null 2>&1; then ksba_cv_broken_visibility_attribute=no fi fi ]) fi if test "$ksba_cv_visibility_attribute" = "yes"; then AC_CACHE_CHECK(for broken alias attribute, ksba_cv_broken_alias_attribute, [ksba_cv_broken_alias_attribute=yes AC_LANG_CONFTEST([AC_LANG_SOURCE( [[extern int foo (int x) __asm ("xyzzy"); int bar (int x) { return x; } extern __typeof (bar) foo __attribute ((weak, alias ("bar"))); extern int dfoo; extern __typeof (dfoo) dfoo __asm ("abccb"); int dfoo = 1; ]])]) if ${CC-cc} -Werror -S conftest.c -o conftest.s \ 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \ grep 'abccb' conftest.s >/dev/null 2>&1; then ksba_cv_broken_alias_attribute=no fi fi ]) fi if test "$ksba_cv_visibility_attribute" = "yes"; then AC_CACHE_CHECK(if gcc supports -fvisibility=hidden, ksba_cv_gcc_has_f_visibility, [ksba_cv_gcc_has_f_visibility=no _gcc_cflags_save=$CFLAGS CFLAGS="-fvisibility=hidden" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], ksba_cv_gcc_has_f_visibility=yes) CFLAGS=$_gcc_cflags_save; ]) fi if test "$ksba_cv_visibility_attribute" = "yes" \ && test "$ksba_cv_broken_visibility_attribute" != "yes" \ && test "$ksba_cv_broken_alias_attribute" != "yes" \ && test "$ksba_cv_gcc_has_f_visibility" = "yes" then AC_DEFINE(KSBA_USE_VISIBILITY, 1, [Define to use the GNU C visibility attribute.]) CFLAGS="$CFLAGS -fvisibility=hidden" fi # # Checks for libraries. # AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION") if test "x$GPG_ERROR_LIBS" = "x"; then AC_MSG_ERROR([libgpg-error is needed. See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .]) fi AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_KSBA, [The default error source for libksba.]) # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([string.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_BIGENDIAN AC_CHECK_SIZEOF(unsigned int) AC_CHECK_SIZEOF(unsigned long) GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF) # Checks for library functions. AC_CHECK_FUNCS([memmove strchr strtol strtoul stpcpy gmtime_r getenv]) # GNUlib checks gl_SOURCE_BASE(gl) gl_M4_BASE(gl/m4) gl_MODULES(alloca valgrind-tests) gl_INIT # To be used in ksba-config KSBA_CONFIG_LIBS="-lksba" KSBA_CONFIG_CFLAGS="" KSBA_CONFIG_HOST="$host" AC_SUBST(KSBA_CONFIG_LIBS) AC_SUBST(KSBA_CONFIG_CFLAGS) AC_SUBST(KSBA_CONFIG_API_VERSION) AC_SUBST(KSBA_CONFIG_HOST) # The Makefiles need to know about cross compiling AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling != xno) # Generate extended version information for W32. if test "$have_w32_system" = yes; then changequote(,)dnl BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'` changequote([,])dnl BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec" fi AC_SUBST(BUILD_REVISION) AC_SUBST(BUILD_FILEVERSION) BUILD_REVISION="mym4_revision" AC_SUBST(BUILD_REVISION) AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", [GIT commit id revision used to build this package]) AC_ARG_ENABLE([build-timestamp], AC_HELP_STRING([--enable-build-timestamp], [set an explicit build timestamp for reproducibility. (default is the current time in ISO-8601 format)]), [if test "$enableval" = "yes"; then BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date` else BUILD_TIMESTAMP="$enableval" fi], [BUILD_TIMESTAMP=""]) AC_SUBST(BUILD_TIMESTAMP) AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP", [The time this package was configured for a build]) build_doc=yes AC_ARG_ENABLE([doc], AC_HELP_STRING([--disable-doc], [do not build the documentation]), build_doc=$enableval, build_doc=yes) AM_CONDITIONAL([BUILD_DOC], [test "x$build_doc" != xno]) AC_CONFIG_FILES([ Makefile m4/Makefile gl/Makefile src/Makefile src/ksba-config src/versioninfo.rc tests/Makefile doc/Makefile ]) AC_OUTPUT if test x"$have_bison" = xno; then AC_MSG_NOTICE([[ *** *** Note: The installed yacc version is not GNU Bison. You need *** to install Bison if you want to change any grammar (.y) file. ***]]) fi echo " Libksba v${VERSION} has been configured as follows: Revision: mym4_revision (mym4_revision_dec) Platform: $host " diff --git a/m4/Makefile.am b/m4/Makefile.am index 6078d25..fdbffdd 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -1,5 +1,5 @@ EXTRA_DIST = autobuild.m4 gnupg-typedef.m4 gpg-error.m4 libgcrypt.m4 \ - libtool.m4 ax_prog_bison.m4 + libtool.m4 ax_prog_bison.m4 gcov.m4 diff --git a/m4/gcov.m4 b/m4/gcov.m4 new file mode 100644 index 0000000..ad1d3ec --- /dev/null +++ b/m4/gcov.m4 @@ -0,0 +1,93 @@ +# Copyright 2012 Canonical Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +# Checks for existence of coverage tools: +# * gcov +# * lcov +# * genhtml +# * gcovr +# +# Sets ac_cv_check_gcov to yes if tooling is present +# and reports the executables to the variables LCOV, GCOVR and GENHTML. +AC_DEFUN([AC_TDD_GCOV], +[ + AC_ARG_ENABLE(gcov, + AS_HELP_STRING([--enable-gcov], + [enable coverage testing with gcov]), + [use_gcov=yes], [use_gcov=no]) + + AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes") + + if test "x$use_gcov" = "xyes"; then + # we need gcc: + if test "$GCC" != "yes"; then + AC_MSG_ERROR([GCC is required for --enable-gcov]) + fi + + # Check if ccache is being used + AC_CHECK_PROG(SHTOOL, shtool, shtool) + if test "$SHTOOL"; then + AS_CASE([`$SHTOOL path $CC`], + [*ccache*], [gcc_ccache=yes], + [gcc_ccache=no]) + fi + + if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then + AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) + fi + + lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13" + AC_CHECK_PROG(LCOV, lcov, lcov) + AC_CHECK_PROG(GENHTML, genhtml, genhtml) + + if test "$LCOV"; then + AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ + glib_cv_lcov_version=invalid + lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'` + for lcov_check_version in $lcov_version_list; do + if test "$lcov_version" = "$lcov_check_version"; then + glib_cv_lcov_version="$lcov_check_version (ok)" + fi + done + ]) + else + lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list" + AC_MSG_ERROR([$lcov_msg]) + fi + + case $glib_cv_lcov_version in + ""|invalid[)] + lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)." + AC_MSG_ERROR([$lcov_msg]) + LCOV="exit 0;" + ;; + esac + + if test -z "$GENHTML"; then + AC_MSG_ERROR([Could not find genhtml from the lcov package]) + fi + + # Remove all optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` + CPPFLAGS=`echo "$CPPFLAGS" | $SED -e 's/-O[0-9]*//g'` + changequote([,]) + + # Add the special gcc flags + COVERAGE_CFLAGS="--coverage -DDEBUG" + COVERAGE_CXXFLAGS="--coverage -DDEBUG" + COVERAGE_LDFLAGS="--coverage -lgcov" + +fi +]) # AC_TDD_GCOV diff --git a/src/Makefile.am b/src/Makefile.am index 7e3f06b..e8a5692 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,135 +1,136 @@ # Makefile.am - for the KSBA ASN.1 and X.509 library # Copyright (C) 2001, 2002, 2004, 2005, 2007 g10 Code GmbH # # This file is part of KSBA. # # KSBA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # KSBA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . ## Process this file with automake to produce Makefile.in asn1_modules = tmttv2.asn cms.asn buildtool_src = asn1-gentables.c gen-help.c gen-help.h EXTRA_DIST = ksba-config.in $(asn1_modules) ksba.m4 libksba.vers libksba.def \ asn1-parse.c asn1-tables.c $(buildtool_src) BUILT_SOURCES = asn1-parse.c asn1-tables.c bin_SCRIPTS = ksba-config include_HEADERS = ksba.h lib_LTLIBRARIES = libksba.la noinst_PROGRAMS = ber-dump m4datadir = $(datadir)/aclocal m4data_DATA = ksba.m4 CLEANFILES = asn1-gentables DISTCLEANFILES = asn1-tables.c AM_CPPFLAGS = -I$(top_builddir)/gl -I$(top_srcdir)/gl -AM_CFLAGS = $(GPG_ERROR_CFLAGS) +AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) if HAVE_LD_VERSION_SCRIPT libksba_version_script_cmd = -Wl,--version-script=$(srcdir)/libksba.vers else libksba_version_script_cmd = endif if HAVE_W32_SYSTEM RCCOMPILE = $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(libksba_la_CPPFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) LTRCCOMPILE = $(LIBTOOL) --mode=compile --tag=RC $(RCCOMPILE) SUFFIXES = .rc .lo .rc.lo: $(LTRCCOMPILE) -i "$<" -o "$@" ksba_res = versioninfo.lo no_undefined = -no-undefined export_symbols = -export-symbols $(srcdir)/libksba.def extra_ltoptions = -XCClinker -static-libgcc install-def-file: $(INSTALL) $(srcdir)/libksba.def $(DESTDIR)$(libdir)/libksba.def uninstall-def-file: -rm $(DESTDIR)$(libdir)/libksba.def ksba_deps = $(ksba_res) libksba.def else !HAVE_W32_SYSTEM ksba_res = no_undefined = export_symbols = extra_ltoptions = ksba_deps = install-def-file: uninstall-def-file: endif !HAVE_W32_SYSTEM libksba_la_LDFLAGS = $(no_undefined) $(export_symbols) $(extra_ltoptions) \ $(libksba_version_script_cmd) -version-info \ - @LIBKSBA_LT_CURRENT@:@LIBKSBA_LT_REVISION@:@LIBKSBA_LT_AGE@ + @LIBKSBA_LT_CURRENT@:@LIBKSBA_LT_REVISION@:@LIBKSBA_LT_AGE@ \ + $(COVERAGE_LDFLAGS) libksba_la_INCLUDES = -I$(top_srcdir)/lib libksba_la_DEPENDENCIES = $(srcdir)/libksba.vers $(ksba_deps) libksba_la_LIBADD = $(ksba_res) @LTLIBOBJS@ @GPG_ERROR_LIBS@ libksba_la_SOURCES = \ ksba.h \ visibility.c visibility.h \ reader.c reader.h \ writer.c writer.h \ asn1-parse.y \ asn1-func.c asn1-func2.c asn1-func.h \ ber-help.c ber-help.h \ ber-decoder.c ber-decoder.h \ der-encoder.c der-encoder.h \ cert.c cert.h \ cms.c cms.h cms-parser.c \ crl.c crl.h \ certreq.c certreq.h \ ocsp.c ocsp.h \ keyinfo.c keyinfo.h \ oid.c name.c dn.c time.c convert.h \ version.c util.c util.h shared.h \ sexp-parse.h \ asn1-tables.c ber_dump_SOURCES = ber-dump.c \ ber-decoder.c ber-help.c reader.c writer.c asn1-parse.c \ asn1-func.c oid.c util.c ber_dump_LDADD = $(GPG_ERROR_LIBS) ../gl/libgnu.la ber_dump_CFLAGS = $(AM_CFLAGS) asn1-parse.c : asn1-func.h gen-help.h asn1-gentables: asn1-gentables.c asn1-parse.c asn1-func.c gen-help.c gen-help.h $(CC_FOR_BUILD) -I$(srcdir) -DBUILD_GENTOOLS -o $@ \ $(srcdir)/asn1-gentables.c \ `test -f 'asn1-parse.c' || echo '$(srcdir)/'`asn1-parse.c \ $(srcdir)/asn1-func.c \ $(srcdir)/gen-help.c asn1-tables.c : $(asn1_modules) asn1-gentables @set -e; list=""; \ for file in $(asn1_modules); do list="$$list $(srcdir)/$$file";done;\ ./asn1-gentables $$list > asn1-tables.c install-data-local: install-def-file uninstall-local: uninstall-def-file diff --git a/tests/Makefile.am b/tests/Makefile.am index 949a812..9652674 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,64 +1,64 @@ # Makefile.am - for the KSBA regression tests # Copyright (C) 2001, 2003 g10 Code GmbH # # This file is part of KSBA. # # KSBA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # KSBA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . ## Process this file with automake to produce Makefile.in TESTS_ENVIRONMENT = test_certs = cert_dfn_pca01.der cert_dfn_pca15.der \ cert_g10code_test1.der crl_testpki_testpca.der \ samples/authority.crt samples/betsy.crt samples/bull.crt \ samples/ov-ocsp-server.crt samples/ov-userrev.crt \ samples/ov-root-ca-cert.crt samples/ov-serverrev.crt \ samples/ov-user.crt samples/ov-server.crt \ samples/ov2-root-ca-cert.crt samples/ov2-ocsp-server.crt \ samples/ov2-user.crt samples/ov2-userrev.crt test_crls = samples/ov-test-crl.crl test_keys = samples/ov-server.p12 samples/ov-userrev.p12 \ samples/ov-serverrev.p12 samples/ov-user.p12 EXTRA_DIST = $(test_certs) samples/README mkoidtbl.awk BUILT_SOURCES = oidtranstbl.h CLEANFILES = oidtranstbl.h TESTS = cert-basic t-crl-parser t-dnparser t-oid t-reader -AM_CFLAGS = $(GPG_ERROR_CFLAGS) -AM_LDFLAGS = -no-install +AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) +AM_LDFLAGS = -no-install $(COVERAGE_LDFLAGS) noinst_HEADERS = t-common.h noinst_PROGRAMS = $(TESTS) t-cms-parser t-crl-parser t-dnparser t-ocsp LDADD = ../src/libksba.la $(GPG_ERROR_LIBS) t_ocsp_SOURCES = t-ocsp.c sha1.c # Build the OID table: Note that the binary includes data from an # another program and we may not be allowed to distribute this. This # ain't no problem as the programs using this generated data are not # installed and thus not distributed. oidtranstbl.h: Makefile mkoidtbl.awk set -e; f="/dev/null"; \ for i in /etc/dumpasn1 /usr/local/bin /usr/local/share /usr/bin \ /usr/share ; do \ if test -f $$i/dumpasn1.cfg; then f=$$i/dumpasn1.cfg; break; fi; \ done; tr -d '\r' <$$f | $(AWK) -f $(srcdir)/mkoidtbl.awk >$@ LOG_COMPILER = $(VALGRIND)