Skip to content

Commit

Permalink
Fix to handle CFLAGS, CPPFLAGS and C_EXTRA_FLAGS. Added generat…
Browse files Browse the repository at this point in the history
…ion of configuration options in `wolfmqtt/options.h`. Cleanup of the configure.ac to use AM_CFLAGS and remove AX_PTHREAD.
  • Loading branch information
dgarske committed May 22, 2018
1 parent c81de86 commit 1d05050
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ firmware.bin
IDE/ARDUINO/wolfMQTT
examples/azure/azureiothub
examples/aws/awsiot
wolfmqtt/options.h
115 changes: 95 additions & 20 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ AC_INIT([wolfmqtt],[1.0.0],[https://github.com/wolfssl/wolfMQTT/issues],[wolfmqt
AC_PREREQ([2.63])
AC_CONFIG_AUX_DIR([build-aux])

# The following sets CFLAGS and CXXFLAGS to empty if unset on command line.
# We do not want the default "-g -O2" that AC_PROG_CC AC_PROG_CXX sets
# automatically.
: ${CFLAGS=""}
: ${CXXFLAGS=""}
: ${AR_FLAGS="cr"}

AC_CANONICAL_HOST
Expand All @@ -34,6 +38,11 @@ WOLFMQTT_LIBRARY_VERSION=2:0:0
# +- increment if interfaces have been added, removed or changed
AC_SUBST([WOLFMQTT_LIBRARY_VERSION])

# capture user C_EXTRA_FLAGS from ./configure line, CFLAGS may hold -g -O2 even
# if user doesn't override, no way to tell
USER_C_EXTRA_FLAGS="$C_EXTRA_FLAGS"
USER_CFLAGS="$CFLAGS"

LT_PREREQ([2.2])
LT_INIT([disable-static], [win32-dll])
LT_LANG([C])
Expand Down Expand Up @@ -68,33 +77,23 @@ AC_CHECK_FUNCS([signal])
AC_CHECK_LIB(network,socket)

# DEBUG
DEBUG_CFLAGS="-g -O0"
DEBUG_CPPFLAGS="-DDEBUG -DDEBUG_WOLFMQTT"
DEBUG_CFLAGS="-g -O0 -DDEBUG -DDEBUG_WOLFMQTT"

# Optimizations
OPTIMIZE_CFLAGS="-O2"

AX_DEBUG
AS_IF([test "x$ax_enable_debug" = "xyes" || test "x$ax_enable_debug" = "xverbose"],
[AM_CFLAGS="$DEBUG_CFLAGS $AM_CFLAGS"
AM_CPPFLAGS="$DEBUG_CPPFLAGS $AM_CPPFLAGS"],
[AM_CFLAGS="$AM_CFLAGS $OPTIMIZE_CFLAGS"
AM_CPPFLAGS="-DNDEBUG $AM_CFLAGS"])

AX_PTHREAD([
# If AX_PTHREAD is adding -Qunused-arguments, need to prepend with
# -Xcompiler libtool will use it. Newer versions of clang don't need
# the -Q flag when using pthreads.
AS_CASE([$PTHREAD_CFLAGS],[-Qunused-arguments*],[PTHREAD_CFLAGS="-Xcompiler $PTHREAD_CFLAGS"])
AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"])
[AM_CFLAGS="$DEBUG_CFLAGS $AM_CFLAGS"],
[AM_CFLAGS="$AM_CFLAGS $OPTIMIZE_CFLAGS -DNDEBUG"])


# Checks for typedefs, structures, and compiler characteristics.
if test "$ac_cv_sizeof_long" = "8"; then
AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG=8"
AM_CFLAGS="$AM_CFLAGS -DSIZEOF_LONG=8"
else
if test "$ac_cv_sizeof_long_long" = "8"; then
AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG_LONG=8"
AM_CFLAGS="$AM_CFLAGS -DSIZEOF_LONG_LONG=8"
fi
fi

Expand All @@ -116,7 +115,7 @@ AC_ARG_ENABLE([tls],

if test "x$ENABLED_TLS" = "xyes"
then
AM_CPPFLAGS="$AM_CPPFLAGS -DENABLE_MQTT_TLS"
AM_CFLAGS="$AM_CFLAGS -DENABLE_MQTT_TLS"

TAO_REQUIRE_LIBWOLFSSL
fi
Expand All @@ -132,7 +131,7 @@ AC_ARG_ENABLE([nonblock],

if test "x$ENABLED_NONBLOCK" = "xyes"
then
AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFMQTT_NONBLOCK"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_NONBLOCK"
fi


Expand All @@ -145,7 +144,7 @@ AC_ARG_ENABLE([timeout],

if test "x$ENABLED_TIMEOUT" = "xno"
then
AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFMQTT_NO_TIMEOUT"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_NO_TIMEOUT"
fi

# Examples
Expand All @@ -167,7 +166,7 @@ AC_ARG_ENABLE([errorstrings],

if test "x$ENABLED_ERROR_STRINGS" = "xno"
then
AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFMQTT_NO_ERROR_STRINGS"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_NO_ERROR_STRINGS"
fi


Expand All @@ -180,7 +179,7 @@ AC_ARG_ENABLE([stdincap],

if test "x$ENABLED_STDINCAP" = "xno"
then
AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFMQTT_NO_STDIN_CAP"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_NO_STDIN_CAP"
fi

AM_CONDITIONAL([BUILD_STDINCAP], [test "x$ENABLED_STDINCAP" = "xyes"])
Expand All @@ -190,6 +189,11 @@ AM_CONDITIONAL([BUILD_STDINCAP], [test "x$ENABLED_STDINCAP" = "xyes"])
# HARDEN FLAGS
AX_HARDEN_CC_COMPILER_FLAGS

# add user C_EXTRA_FLAGS back
CFLAGS="$CFLAGS $USER_CFLAGS $USER_C_EXTRA_FLAGS"
OPTION_FLAGS="$CFLAGS $CPPFLAGS $AM_CFLAGS"


CREATE_HEX_VERSION
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CFLAGS])
Expand All @@ -198,6 +202,7 @@ AC_SUBST([AM_LDFLAGS])
# FINAL
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([wolfmqtt/version.h])
AC_CONFIG_FILES([wolfmqtt/options.h])

AX_CREATE_GENERIC_CONFIG
AX_AM_JOBSERVER([yes])
Expand All @@ -210,6 +215,76 @@ echo "Running make clean..."
make clean >/dev/null 2>&1
echo

# generate user options header
echo "---"
echo "Generating user options header..."

OPTION_FILE="wolfmqtt/options.h"
rm -f $OPTION_FILE

echo "/* wolfmqtt options.h" > $OPTION_FILE
echo " * generated from configure options" >> $OPTION_FILE
echo " *" >> $OPTION_FILE
echo " * Copyright (C) 2006-2018 wolfSSL Inc." >> $OPTION_FILE
echo " *" >> $OPTION_FILE
echo " * * This file is part of wolfMQTT." >> $OPTION_FILE
echo " *" >> $OPTION_FILE
echo " */" >> $OPTION_FILE

echo "" >> $OPTION_FILE
echo "#ifndef WOLFMQTT_OPTIONS_H" >> $OPTION_FILE
echo "#define WOLFMQTT_OPTIONS_H" >> $OPTION_FILE
echo "" >> $OPTION_FILE
echo "" >> $OPTION_FILE
echo "#ifdef __cplusplus" >> $OPTION_FILE
echo "extern \"C\" {" >> $OPTION_FILE
echo "#endif" >> $OPTION_FILE
echo "" >> $OPTION_FILE

for option in $OPTION_FLAGS; do
defonly=`echo $option | sed 's/-D//'`
if test "$defonly" != "$option"
then
noequalsign=`echo $defonly | sed 's/=/ /'`
if test "$noequalsign" = "NDEBUG" || test "$noequalsign" = "DEBUG"
then
echo "not outputting (N)DEBUG to $OPTION_FILE"
continue
fi

# allow user to igonore system options
ignoresys=no
if [[[ $noequalsign == _* ]]] ;
then
ignoresys=yes
echo "#ifndef WOLFSSL_OPTIONS_IGNORE_SYS" >> $OPTION_FILE
fi

noarg=`echo $defonly | sed 's/=.*//'`
echo "#undef $noarg" >> $OPTION_FILE
echo "#define $noequalsign" >> $OPTION_FILE

if test "$ignoresys" = "yes"
then
echo "#endif" >> $OPTION_FILE
fi

echo "" >> $OPTION_FILE
else
echo "option w/o begin -D is $option, not saving to $OPTION_FILE"
fi
done

echo "" >> $OPTION_FILE
echo "#ifdef __cplusplus" >> $OPTION_FILE
echo "}" >> $OPTION_FILE
echo "#endif" >> $OPTION_FILE
echo "" >> $OPTION_FILE
echo "" >> $OPTION_FILE
echo "#endif /* WOLFMQTT_OPTIONS_H */" >> $OPTION_FILE
echo "" >> $OPTION_FILE
echo

# output config summary
echo "---"
echo "Configuration summary for $PACKAGE_NAME version $VERSION"
Expand Down
3 changes: 2 additions & 1 deletion wolfmqtt/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ nobase_include_HEADERS+= \
wolfmqtt/mqtt_client.h \
wolfmqtt/mqtt_packet.h \
wolfmqtt/mqtt_socket.h \
wolfmqtt/visibility.h
wolfmqtt/visibility.h \
wolfmqtt/options.h
39 changes: 39 additions & 0 deletions wolfmqtt/options.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* options.h.in
*
* Copyright (C) 2006-2018 wolfSSL Inc.
*
* This file is part of wolfMQTT.
*
* wolfMQTT 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 2 of the License, or
* (at your option) any later version.
*
* wolfMQTT 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/


/* default blank options for autoconf */

#ifndef WOLFMQTT_OPTIONS_H
#define WOLFMQTT_OPTIONS_H


#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif


#endif /* WOLFMQTT_OPTIONS_H */

0 comments on commit 1d05050

Please sign in to comment.