diff --git a/doc/doxygen.conf b/doc/doxygen.conf
index 668712036..addac3f75 100644
--- a/doc/doxygen.conf
+++ b/doc/doxygen.conf
@@ -2077,7 +2077,10 @@ PREDEFINED = NS3_ASSERT_ENABLE \
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
diff --git a/doc/tutorial/source/getting-started.rst b/doc/tutorial/source/getting-started.rst
index b39df5e2c..a33e9f9b3 100644
--- a/doc/tutorial/source/getting-started.rst
+++ b/doc/tutorial/source/getting-started.rst
@@ -554,6 +554,38 @@ We already saw how you can configure Waf for ``debug`` or ``optimized`` builds::
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 @@ to define some environment variables to help you avoid mistakes::
$ ./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 @@ More info on ``distcc`` and distributed compilation can be found on it's
`_
under Documentation section.
+To add compiler flags, use the ``CXXFLAGS_EXTRA`` environment variable when
+you configure |ns3|.
+
Install
=======
diff --git a/src/core/model/build-profile.h b/src/core/model/build-profile.h
new file mode 100644
index 000000000..8874fb243
--- /dev/null
+++ b/src/core/model/build-profile.h
@@ -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.
+ */
+
+#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 */
diff --git a/src/core/test/build-profile-test-suite.cc b/src/core/test/build-profile-test-suite.cc
new file mode 100644
index 000000000..8d6bb4a77
--- /dev/null
+++ b/src/core/test/build-profile-test-suite.cc
@@ -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.
+ */
+
+#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;
diff --git a/src/core/wscript b/src/core/wscript
index 6f13716e6..2090f5e11 100644
--- a/src/core/wscript
+++ b/src/core/wscript
@@ -192,6 +192,7 @@ def build(bld):
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 @@ def build(bld):
'model/hash.h',
'model/valgrind.h',
'model/non-copyable.h',
+ 'model/build-profile.h',
]
if sys.platform == 'win32':
diff --git a/wscript b/wscript
index 416fffa4e..85703524a 100644
--- a/wscript
+++ b/wscript
@@ -312,9 +312,16 @@ def configure(conf):
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":