From 1ac03f9cd8b57367c848b979b89616a97f1dc210 Mon Sep 17 00:00:00 2001 From: William Brown Date: Jan 10 2017 00:24:21 +0000 Subject: Ticket 75 - Port nunc-stans to freebsd. Bug Description: This is the initial step to port nunc-stans to freebsd. It builds on the work to decouple lfds from the nuncstans source tree. Fix Description: This cleans a number of compiler warnings, fixes the pkg config detection of libevent and cmocka. This also allows optionally building of the tests suites to avoid a dependency on cmocka if not needed. https://pagure.io/nunc-stans/issue/75 Author: wibrown Review by: mreynolds (Thanks!) --- diff --git a/Makefile.am b/Makefile.am index 62ca511..ddb30fd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,9 @@ ACLOCAL_AMFLAGS = -I m4 DOXYGEN = doxygen +if WITH_TESTS TESTS = cmocka_test +endif #------------------------ # Compiler Flags @@ -10,18 +12,19 @@ TESTS = cmocka_test DEBUG_DEFINES = @debug_defs@ NS_DEFINES = NS_INCLUDES = -I$(srcdir)/include @nspr_inc@ @sds_inc@ -AM_CPPFLAGS = $(PLATFORM_DEFINES) $(DEBUG_DEFINES) $(NS_DEFINES) $(NS_INCLUDES) +EVENT_INCLUDES = @event_inc@ +CMOCKA_INCLUDES = @cmocka_inc@ +AM_CPPFLAGS = $(PLATFORM_DEFINES) $(DEBUG_DEFINES) $(NS_DEFINES) $(NS_INCLUDES) $(EVENT_INCLUDES) #------------------------ # Linker Flags #------------------------ NSPR_LINK = @nspr_lib@ -lplc4 -lnspr4 SDS_LINK = @sds_lib@ -LIBEVENT_LINK = -levent +EVENT_LINK = @event_lib@ LIBTEVENT_LINK = -ltevent -ltalloc - -#NSS_LINK = @nss_lib@ -lssl3 -lnss3 -#OPENSSL_LINK = @openssl_lib@ -lcrypto -lssl +CMOCKA_LINK = @cmocka_lib@ +AM_LDFLAGS = $(NSPR_LINK) $(SDS_LINK) $(EVENT_LINK) $(LIBTEVENT_LINK) #------------------------ # Build Products @@ -52,7 +55,7 @@ libnunc_stans_la_SOURCES = ns_thrpool.c \ ns_event_fw_tevent.c libnunc_stans_la_CPPFLAGS = $(AM_CPPFLAGS) -libnunc_stans_la_LIBADD = $(NSPR_LINK) $(LFDS_LINK) $(LIBEVENT_LINK) $(LIBTEVENT_LINK) $(SDS_LINK) +libnunc_stans_la_LIBADD = $(AM_LDFLAGS) #//////////////////////////////////////////////////////////////// @@ -60,6 +63,9 @@ libnunc_stans_la_LIBADD = $(NSPR_LINK) $(LFDS_LINK) $(LIBEVENT_LINK) $(LIBTEVENT # Tests # #//////////////////////////////////////////////////////////////// + +if WITH_TESTS + check_PROGRAMS = cmocka_test cmocka_stress_test check_SCRIPTS = tests/file-test.sh tests/put.py file-test.sh: $(srcdir)/tests/file-test.sh put.py @@ -68,10 +74,14 @@ put.py: $(srcdir)/tests/put.py cp $^ $@ cmocka_test_SOURCES = tests/cmocka/test.c -cmocka_test_LDADD = -lcmocka libnunc-stans.la -lssl3 -lnss3 -lnssutil3 +cmocka_test_CPPFLAGS = $(AM_CPPFLAGS) $(CMOCKA_INCLUDES) +cmocka_test_LDADD = libnunc-stans.la $(AM_LDFLAGS) $(CMOCKA_LINK) cmocka_stress_test_SOURCES = tests/cmocka/stress_test.c -cmocka_stress_test_LDADD = -lcmocka libnunc-stans.la -lssl3 -lnss3 -lnssutil3 +cmocka_stress_test_CPPFLAGS = $(AM_CPPFLAGS) $(CMOCKA_INCLUDES) +cmocka_stress_test_LDADD = libnunc-stans.la $(AM_LDFLAGS) $(CMOCKA_LINK) + +endif install-data-hook: $(srcdir)/nunc-stans.doxy if [ ! -d $(DESTDIR)$(htmldir) ] ; then mkdir -p $(DESTDIR)$(htmldir) ; fi @@ -79,4 +89,4 @@ install-data-hook: $(srcdir)/nunc-stans.doxy sed -e "s,^HTML_OUTPUT.*$$,HTML_OUTPUT = $(DESTDIR)$(htmldir)," \ -e "s,^MAN_OUTPUT.*$$,MAN_OUTPUT = $(DESTDIR)$(mandir)," \ $^ > ns.doxy - curdir=`pwd` ; pushd $(srcdir) ; $(DOXYGEN) $$curdir/ns.doxy ; popd + curdir=`pwd` ; cd $(srcdir); $(DOXYGEN) $$curdir/ns.doxy; diff --git a/configure.ac b/configure.ac index 7db52e0..ff3b4bb 100644 --- a/configure.ac +++ b/configure.ac @@ -58,7 +58,9 @@ AC_MSG_RESULT($enable_rpath) m4_include(m4/nspr.m4) m4_include(m4/fhs.m4) +m4_include(m4/event.m4) m4_include(m4/sds.m4) +m4_include(m4/cmocka.m4) # installation paths - by default, configure will just # use /usr as the prefix for everything, which means @@ -73,12 +75,20 @@ dnl as opposed to the default /usr/var localstatedir='/var' fi +# Do this before our includes, to guarantee we have pkgconfig +AC_PATH_PROG(PKG_CONFIG, pkg-config) +if test -z "$PKG_CONFIG"; then + AC_MSG_ERROR([pkg-config not found!!!]) +fi + # write out paths for binary components AC_SUBST(nspr_inc) AC_SUBST(nspr_lib) AC_SUBST(nspr_libdir) AC_SUBST(sds_inc) AC_SUBST(sds_lib) +AC_SUBST(event_inc) +AC_SUBST(event_lib) if test "$enable_rpath" != "yes" ; then AC_MSG_NOTICE([Fixing libtool to remove automatic rpath to $libdir . . .]) diff --git a/m4/cmocka.m4 b/m4/cmocka.m4 new file mode 100644 index 0000000..3be8d9c --- /dev/null +++ b/m4/cmocka.m4 @@ -0,0 +1,33 @@ +## BEGIN COPYRIGHT BLOCK +## Copyright (c) 2016, William Brown +## All rights reserved. +## +## License: License: GPL (version 3 or any later version). +## See LICENSE for details. +## END COPYRIGHT BLOCK + +AC_MSG_CHECKING(for --enable-tests) +AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests], [Enable cmocka based tests (default: no)]), +[ + AC_MSG_RESULT(yes) + AC_DEFINE([WITH_TESTS], [1], [With cmocka unit tests]) + with_tests="yes" + AC_MSG_CHECKING(for cmocka) + if $PKG_CONFIG --exists cmocka; then + cmocka_inc=`$PKG_CONFIG --cflags cmocka` + cmocka_lib=`$PKG_CONFIG --libs cmocka` + AC_MSG_RESULT([using system cmocka]) + else + AC_MSG_ERROR([pkg-config could not find cmocka!]) + fi +], +[ + AC_MSG_RESULT(no) + with_tests="0" +]) + +AM_CONDITIONAL([WITH_TESTS], [test "$with_tests" = "yes"]) +AC_SUBST(cmocka_inc) +AC_SUBST(cmocka_lib) + + diff --git a/m4/event.m4 b/m4/event.m4 new file mode 100644 index 0000000..58b6818 --- /dev/null +++ b/m4/event.m4 @@ -0,0 +1,47 @@ +# BEGIN COPYRIGHT BLOCK +# Copyright (C) 2015 Red Hat +# see files 'COPYING' and 'COPYING.openssl' for use and warranty +# information +# +# This program 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. +# +# This program 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 . +# +# Additional permission under GPLv3 section 7: +# +# If you modify this Program, or any covered work, by linking or +# combining it with OpenSSL, or a modified version of OpenSSL licensed +# under the OpenSSL license +# (https://www.openssl.org/source/license.html), the licensors of this +# Program grant you additional permission to convey the resulting +# work. Corresponding Source for a non-source form of such a +# combination shall include the source code for the parts that are +# licensed under the OpenSSL license as well as that of the covered +# work. +# END COPYRIGHT BLOCK +AC_CHECKING(for EVENT) + +# Always use pkgconfig, because we know it's installed properly! + +AC_MSG_CHECKING(for event with pkg-config) +AC_PATH_PROG(PKG_CONFIG, pkg-config) +if test -n "$PKG_CONFIG"; then + if $PKG_CONFIG --exists libevent; then + event_inc=`$PKG_CONFIG --cflags libevent` + event_lib=`$PKG_CONFIG --libs libevent` + AC_MSG_RESULT([using system EVENT]) + else + AC_MSG_ERROR([EVENT not found, check with pkg-config libevent!]) + fi +fi + + diff --git a/ns_event_fw_event.c b/ns_event_fw_event.c index 7432f97..5c109ad 100644 --- a/ns_event_fw_event.c +++ b/ns_event_fw_event.c @@ -152,7 +152,7 @@ ns_event_fw_destroy(ns_event_fw_ctx_t *ns_event_fw_ctx_t) */ static void ns_event_fw_io_event_remove( - ns_event_fw_ctx_t *ns_event_fw_ctx, + ns_event_fw_ctx_t *ns_event_fw_ctx __attribute__((unused)), ns_job_t *job ) { @@ -172,7 +172,7 @@ ns_event_fw_io_event_done( static void ns_event_fw_timer_event_remove( - ns_event_fw_ctx_t *ns_event_fw_ctx, + ns_event_fw_ctx_t *ns_event_fw_ctx __attribute__((unused)), ns_job_t *job ) { @@ -192,7 +192,7 @@ ns_event_fw_timer_event_done( static void ns_event_fw_signal_event_remove( - ns_event_fw_ctx_t *ns_event_fw_ctx, + ns_event_fw_ctx_t *ns_event_fw_ctx __attribute__((unused)), ns_job_t *job ) { @@ -266,7 +266,7 @@ ns_event_fw_add_timer( static void ns_event_fw_mod_timer( - ns_event_fw_ctx_t *ns_event_fw_ctx, + ns_event_fw_ctx_t *ns_event_fw_ctx __attribute__((unused)), ns_job_t *job ) { @@ -288,7 +288,7 @@ ns_event_fw_add_signal( static void ns_event_fw_mod_signal( - ns_event_fw_ctx_t *ns_event_fw_ctx, + ns_event_fw_ctx_t *ns_event_fw_ctx __attribute__((unused)), ns_job_t *job ) { diff --git a/nunc-stans.spec b/nunc-stans.spec index 2fce139..3ace47c 100644 --- a/nunc-stans.spec +++ b/nunc-stans.spec @@ -14,6 +14,7 @@ BuildRequires: libcmocka-devel BuildRequires: autoconf BuildRequires: automake BuildRequires: libtool +BuildRequires: doxygen Source0: https://git.fedorahosted.org/cgit/nunc-stans.git/snapshot/%{name}-%{version}.tar.xz #Source0: http://fedorahosted.org/sources/%{name}-%{version}.tar.xz