--- a/doc/doxygen.conf Tue Jul 28 19:55:54 2015 +0200
+++ b/doc/doxygen.conf Tue Jul 28 16:33:35 2015 -0700
@@ -2077,7 +2077,10 @@
NS3_LOG_ENABLE \
NS_LOG_COMPONENT_DEFINE()=1 \
NS_LOG_COMPONENT_DEFINE_MASK()=1 \
- NS_OBJECT_ENSURE_REGISTERED()=1
+ NS_OBJECT_ENSURE_REGISTERED()=1 \
+ NS3_BUILD_PROFILE_DEBUG \
+ NS3_BUILD_PROFILE_RELEASE \
+ NS3_BUILD_PROFILE_OPTIMIZED
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
--- a/doc/tutorial/source/getting-started.rst Tue Jul 28 19:55:54 2015 +0200
+++ b/doc/tutorial/source/getting-started.rst Tue Jul 28 16:33:35 2015 -0700
@@ -554,6 +554,38 @@
There is also an intermediate build profile, ``release``. ``-d`` is a
synonym for ``--build-profile``.
+The build profile controls the use of logging, assertions, and compiler optimization:
+
++--------------------+---------------------------------+-----------------------------------------------------------------+
+| Feature | Build Profile |
++ +---------------------------------+-------------------------------+---------------------------------+
+| | ``debug`` | ``release`` | ``optimized`` |
++====================+=================================+===============================+=================================+
+| Enabled Features | | ``NS3_BUILD_PROFILE_DEBUG`` | ``NS3_BUILD_PROFILE_RELEASE`` | ``NS3_BUILD_PROFILE_OPTIMIZED`` |
+| | | ``NS_LOG...`` | | |
+| | | ``NS_ASSERT...`` | | |
++--------------------+---------------------------------+-------------------------------+---------------------------------+
+| Code Wrapper Macro | ``NS_BUILD_DEBUG(code)`` | ``NS_BUILD_RELEASE(code)`` | ``NS_BUILD_OPTIMIZED(code)`` |
++--------------------+---------------------------------+-------------------------------+---------------------------------+
+| Compiler Flags | ``-O0 -ggdb -g3`` | ``-O3 -g0`` | ``-O3 -g`` |
+| | | ``-fomit-frame-pointer`` | ``-fstrict-overflow`` |
+| | | | ``-march=native`` |
++--------------------+---------------------------------+-------------------------------+---------------------------------+
+
+As you can see, logging and assertions are only available in debug builds.
+Recommended practice is to develop your scenario in debug mode, then
+conduct repetitive runs (for statistics or changing parameters) in
+optimized build profile.
+
+If you have code that should only run in specific build profiles,
+use the indicated Code Wrapper macro:
+
+.. sourcecode:: cpp
+
+ NS_BUILD_DEBUG (std::cout << "Part of an output line..." << std::flush; timer.Start ());
+ DoLongInvolvedComputation ();
+ NS_BUILD_DEBUG (timer.Stop (); std::cout << "Done: " << timer << std::endl;)
+
By default Waf puts the build artifacts in the ``build`` directory.
You can specify a different output directory with the ``--out``
option, e.g.
@@ -590,8 +622,8 @@
$ ./waf configure $NS3CONFIG $NS3OPT
$ ./waf build
-Compilers
-=========
+Compilers and Flags
+===================
In the examples above, Waf uses the GCC C++ compiler, ``g++``, for
building |ns3|. However, it's possible to change the C++ compiler used by Waf
@@ -614,6 +646,9 @@
<http://code.google.com/p/distcc/>`_
under Documentation section.
+To add compiler flags, use the ``CXXFLAGS_EXTRA`` environment variable when
+you configure |ns3|.
+
Install
=======
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/model/build-profile.h Tue Jul 28 16:33:35 2015 -0700
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2015 LLNL
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
+ */
+
+#ifndef NS3_BUILD_PROFILE_H
+#define NS3_BUILD_PROFILE_H
+
+/**
+ * \file
+ * \ingroup debugging
+ * Definition of build profile macros NS_BUILD_DEBUG, NS_BUILD_RELEASE,
+ * and NS_BUILD_OPTIMIZED.
+ */
+
+/**
+ * \ingroup debugging
+ * Build profile no-op macro.
+ * \param [in] code The code to skip.
+ */
+#define NS_BUILD_PROFILE_NOOP(code) \
+ do \
+ if (false) \
+ { \
+ code ; \
+ } \
+ while (false)
+
+/**
+ * \ingroup debugging
+ * Build profile macro to execute a code snippet.
+ * \param [in] code The code to execute.
+ */
+#define NS_BUILD_PROFILE_OP(code) \
+ do \
+ { \
+ code ; \
+ } \
+ while (false)
+
+
+#ifdef NS3_BUILD_PROFILE_DEBUG
+/**
+ * \ingroup debugging
+ * Execute a code snippet in debug builds.
+ * \param [in] code The code to execute.
+ */
+#define NS_BUILD_DEBUG(code) NS_BUILD_PROFILE_OP (code)
+#else
+#define NS_BUILD_DEBUG(code) NS_BUILD_PROFILE_NOOP (code)
+#endif
+
+#ifdef NS3_BUILD_PROFILE_RELEASE
+/**
+ * \ingroup debugging
+ * Execute a code snippet in release builds.
+ * \param [in] code The code to execute.
+ */
+#define NS_BUILD_RELEASE(code) NS_BUILD_PROFILE_OP (code)
+#else
+#define NS_BUILD_RELEASE(code) NS_BUILD_PROFILE_NOOP (code)
+#endif
+
+#ifdef NS3_BUILD_PROFILE_OPTIMIZED
+/**
+ * \ingroup debugging
+ * Execute a code snippet in optimized builds.
+ * \param [in] code The code to execute.
+ */
+#define NS_BUILD_OPTIMIZED(code) NS_BUILD_PROFILE_OP (code)
+#else
+#define NS_BUILD_OPTIMIZED(code) NS_BUILD_PROFILE_NOOP (code)
+#endif
+
+
+
+
+#endif /* NS3_BUILD_PROFILE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/test/build-profile-test-suite.cc Tue Jul 28 16:33:35 2015 -0700
@@ -0,0 +1,82 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2015 LLNL
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
+ */
+
+#include "ns3/build-profile.h"
+#include "ns3/test.h"
+
+using namespace ns3;
+
+class BuildProfileTestCase : public TestCase
+{
+public:
+ BuildProfileTestCase ();
+ virtual ~BuildProfileTestCase () {}
+
+private:
+ virtual void DoRun (void);
+};
+
+BuildProfileTestCase::BuildProfileTestCase (void)
+ : TestCase ("Check build profile macros")
+{
+}
+
+void
+BuildProfileTestCase::DoRun (void)
+{
+ int i = 0;
+ int j = 0;
+
+#ifdef NS3_BUILD_PROFILE_DEBUG
+ std::cout << GetName () << ": running in build profile debug" << std::endl;
+ NS_BUILD_DEBUG (++i; ++j);
+#elif NS3_BUILD_PROFILE_RELEASE
+ std::cout << GetName () << ": running in build profile release" << std::endl;
+ NS_BUILD_RELEASE (++i; ++j);
+#elif NS3_BUILD_PROFILE_OPTIMIZED
+ std::cout << GetName () << ": running in build profile optimized" << std::endl;
+ NS_BUILD_OPTIMIZED (++i; ++j);
+#else
+ NS_TEST_ASSERT_MSG_EQ (0, 1, ": no build profile case executed");
+#endif
+
+ if (i == 1)
+ std::cout << "build profile executed first statement." << std::endl;
+ NS_TEST_ASSERT_MSG_EQ (i, 1,
+ "build profile failed to execute first statement");
+ if (j == 1)
+ std::cout << "build profile executed second statement." << std::endl;
+ NS_TEST_ASSERT_MSG_EQ (j, 1,
+ "build profile failed to execute second statement");
+}
+
+class BuildProfileTestSuite : public TestSuite
+{
+public:
+ BuildProfileTestSuite ();
+};
+
+BuildProfileTestSuite::BuildProfileTestSuite ()
+ : TestSuite ("build-profile", UNIT)
+{
+ AddTestCase (new BuildProfileTestCase, TestCase::QUICK);
+}
+
+static BuildProfileTestSuite g_BuildProfileTestSuite;
--- a/src/core/wscript Tue Jul 28 19:55:54 2015 +0200
+++ b/src/core/wscript Tue Jul 28 16:33:35 2015 -0700
@@ -192,6 +192,7 @@
core_test = bld.create_ns3_module_test_library('core')
core_test.source = [
'test/attribute-test-suite.cc',
+ 'test/build-profile-test-suite.cc',
'test/callback-test-suite.cc',
'test/command-line-test-suite.cc',
'test/config-test-suite.cc',
@@ -297,6 +298,7 @@
'model/hash.h',
'model/valgrind.h',
'model/non-copyable.h',
+ 'model/build-profile.h',
]
if sys.platform == 'win32':
--- a/wscript Tue Jul 28 19:55:54 2015 +0200
+++ b/wscript Tue Jul 28 16:33:35 2015 -0700
@@ -312,9 +312,16 @@
env.append_value('LINKFLAGS', '-coverage')
if Options.options.build_profile == 'debug':
+ env.append_value('DEFINES', 'NS3_BUILD_PROFILE_DEBUG')
env.append_value('DEFINES', 'NS3_ASSERT_ENABLE')
env.append_value('DEFINES', 'NS3_LOG_ENABLE')
+ if Options.options.build_profile == 'release':
+ env.append_value('DEFINES', 'NS3_BUILD_PROFILE_RELEASE')
+
+ if Options.options.build_profile == 'optimized':
+ env.append_value('DEFINES', 'NS3_BUILD_PROFILE_OPTIMIZED')
+
env['PLATFORM'] = sys.platform
env['BUILD_PROFILE'] = Options.options.build_profile
if Options.options.build_profile == "release":