doc/tutorial/source/getting-started.rst
changeset 7661 9ef562047d3e
parent 7654 62ecccd96cad
child 8837 b769bed02bc2
equal deleted inserted replaced
7660:a688e3775e21 7661:9ef562047d3e
   246 Building ns-3
   246 Building ns-3
   247 *************
   247 *************
   248 
   248 
   249 Building with build.py
   249 Building with build.py
   250 ++++++++++++++++++++++
   250 ++++++++++++++++++++++
   251 The first time you build the |ns3| project you should build using the
   251 The first time you build the |ns3| project you can build using a 
   252 ``allinone`` environment.  This will get the project configured for you
   252 convenience program found in the
   253 in the most commonly useful way.
   253 ``allinone`` directory.  This program is called ``build.py``.  This 
       
   254 program will get the project configured for you
       
   255 in the most commonly useful way.  However, please note that more advanced
       
   256 configuration and work with |ns3| will typically involve using the
       
   257 native |ns3| build system, Waf, to be introduced later in this tutorial.  
   254 
   258 
   255 Change into the directory you created in the download section above.  If you
   259 Change into the directory you created in the download section above.  If you
   256 downloaded using Mercurial you should have a directory called 
   260 downloaded using Mercurial you should have a directory called 
   257 ``ns-3-allinone`` under your ``~/repos`` directory.  If you downloaded
   261 ``ns-3-allinone`` under your ``~/repos`` directory.  If you downloaded
   258 using a tarball you should have a directory called something like 
   262 using a tarball you should have a directory called something like 
   259 ``ns-allinone-3.13`` under your ``~/tarballs`` directory.  Take a deep
   263 ``ns-allinone-3.13`` under your ``~/tarballs`` directory.  
   260 breath and type the following:
   264 Type the following:
   261 
   265 
   262 ::
   266 ::
   263 
   267 
   264   ./build.py --enable-examples --enable-tests
   268   ./build.py --enable-examples --enable-tests
   265 
   269 
   266 Because we are working with examples and tests in this tutorial, and
   270 Because we are working with examples and tests in this tutorial, and
   267 because they are not built by default in |ns3|, the arguments for
   271 because they are not built by default in |ns3|, the arguments for
   268 build.py tells it to build them for us.  In the future you can build
   272 build.py tells it to build them for us.  The program also defaults to
   269 |ns3| without examples and tests if you wish.
   273 building all available modules.  Later, you can build
       
   274 |ns3| without examples and tests, or eliminate the modules that
       
   275 are not necessary for your work, if you wish.
   270 
   276 
   271 You will see lots of typical compiler output messages displayed as the build
   277 You will see lots of typical compiler output messages displayed as the build
   272 script builds the various pieces you downloaded.  Eventually you should see the
   278 script builds the various pieces you downloaded.  Eventually you should see the
   273 following magic words:
   279 following magic words:
   274 
   280 
   303 
   309 
   304   cd ns-3-dev
   310   cd ns-3-dev
   305 
   311 
   306 Building with Waf
   312 Building with Waf
   307 +++++++++++++++++
   313 +++++++++++++++++
   308 We use Waf to configure and build the |ns3| project.  It's not 
   314 Most users directly use Waf to configure and build the |ns3| project.  
       
   315 It's not 
   309 strictly required at this point, but it will be valuable to take a slight
   316 strictly required at this point, but it will be valuable to take a slight
   310 detour and look at how to make changes to the configuration of the project.
   317 detour and look at how to make changes to the configuration of the project.
   311 Probably the most useful configuration change you can make will be to 
   318 Probably the most useful configuration change you can make will be to 
   312 build the optimized version of the code.  By default you have configured
   319 build the optimized version of the code.  By default you have configured
   313 your project to build the debug version.  Let's tell the project to 
   320 your project to build the debug version.  Let's tell the project to 
   314 make an optimized build.  To explain to Waf that it should do optimized
   321 make an optimized build.  To explain to Waf that it should do optimized
   315 builds that include the examples and tests, you will need to execute the 
   322 builds that include the examples and tests, you will need to execute the 
   316 following command,
   323 following commands,
   317 
   324 
   318 ::
   325 ::
   319 
   326 
       
   327   ./waf clean
   320   ./waf -d optimized --enable-examples --enable-tests configure
   328   ./waf -d optimized --enable-examples --enable-tests configure
   321 
   329 
   322 This runs Waf out of the local directory (which is provided as a convenience
   330 This runs Waf out of the local directory (which is provided as a convenience
   323 for you).  As the build system checks for various dependencies you should see
   331 for you).  The first command to clean out the previous build is not 
       
   332 typically strictly necessary but is good practice; it will remove the
       
   333 previously built libraries and object files found in directory ``build/``. 
       
   334 When the project is reconfigured and the build system checks for various 
       
   335 dependencies, you should see
   324 output that looks similar to the following,
   336 output that looks similar to the following,
   325 
   337 
   326 ::
   338 ::
   327 
   339 
   328   Checking for program g++                 : ok /usr/bin/g++
   340   Checking for program g++                 : ok /usr/bin/g++
   394 
   406 
   395 Now go ahead and switch back to the debug build that includes the examples and tests.
   407 Now go ahead and switch back to the debug build that includes the examples and tests.
   396 
   408 
   397 ::
   409 ::
   398 
   410 
       
   411   ./waf clean
   399   ./waf -d debug --enable-examples --enable-tests configure
   412   ./waf -d debug --enable-examples --enable-tests configure
   400 
   413 
   401 The build system is now configured and you can build the debug versions of 
   414 The build system is now configured and you can build the debug versions of 
   402 the |ns3| programs by simply typing
   415 the |ns3| programs by simply typing
   403 
   416 
   404 ::
   417 ::
   405 
   418 
   406   ./waf
   419   ./waf
   407 
   420 
       
   421 Okay, sorry, I made you build the |ns3| part of the system twice,
       
   422 but now you know how to change the configuration and build optimized code.
       
   423 
       
   424 Here are a few more introductory tips about Waf.
   408 Some waf commands are meaningful during the build phase and some commands are valid
   425 Some waf commands are meaningful during the build phase and some commands are valid
   409 in the configuration phase.  For example, if you wanted to use the emulation 
   426 in the configuration phase.  For example, if you wanted to use the emulation 
   410 features of |ns3|, you might want to enable setting the suid bit using
   427 features of |ns3|, you might want to enable setting the suid bit using
   411 sudo as described above.  This turns out to be a configuration-time command, and so 
   428 sudo as described above.  This turns out to be a configuration-time command, and so 
   412 you could reconfigure using the following command that also includes the examples and tests
   429 you could reconfigure using the following command that also includes the examples and tests
   423 
   440 
   424   ./waf --help
   441   ./waf --help
   425 
   442 
   426 We'll use some of the testing-related commands in the next section.
   443 We'll use some of the testing-related commands in the next section.
   427 
   444 
   428 Okay, sorry, I made you build the |ns3| part of the system twice,
   445 Finally, as an aside, it is possible to specify that waf builds the 
   429 but now you know how to change the configuration and build optimized code.
   446 project in 
       
   447 a directory different than the default ``build/`` directory by passing
       
   448 the ``-o`` option to configure; e.g.
       
   449 
       
   450 ::
       
   451 
       
   452   ./waf -d debug -o build/debug --enable-examples --enable-tests configure
       
   453 
       
   454 This allows users to work with multiple builds rather than always
       
   455 overwriting the last build.
   430 
   456 
   431 Testing ns-3
   457 Testing ns-3
   432 ************
   458 ************
   433 
   459 
   434 You can run the unit tests of the |ns3| distribution by running the 
   460 You can run the unit tests of the |ns3| distribution by running the