Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 1 | ndn-cxx tools |
| 2 | ============= |
| 3 | |
| 4 | Unless disabled with `--without-tools` configuration option, files in `tools/` directory |
| 5 | are automatically build and installed to `${PREFIX}/bin` folder. |
| 6 | |
| 7 | There are two ways to add new tools, depending on their complexity: |
| 8 | |
| 9 | 1. Tools with a single translation unit |
| 10 | |
| 11 | For simple tools that have a single translation unit, the `.cpp` file can be directly put |
| 12 | in `tools/` folder and it will be automatically compiled on the next run of `./waf`. Name |
| 13 | of the compiled binary will be determined by the base name of the `.cpp` file. For example, |
| 14 | `tools/foo.cpp` will be compiled into binary `foo` in `<build>/bin/` folder: |
| 15 | |
| 16 | echo "int main() { return 0; }" > tools/foo.cpp |
| 17 | ./waf |
| 18 | # ... Compiling tools/foo.cpp |
| 19 | # ... Linking build/bin/foo |
| 20 | |
| 21 | sudo ./waf install |
| 22 | # ... install /usr/local/bin/foo (from build/bin/foo) |
| 23 | |
| 24 | # To run the tool |
| 25 | /usr/local/bin/foo |
| 26 | |
| 27 | 2. Tools with multiple translation units |
| 28 | |
| 29 | For more complex tools that contain multiple translation units, one can use |
| 30 | the following directory structure: |
| 31 | |
| 32 | - Create a directory under `tools/` folder (e.g., `tools/bar`). |
| 33 | The name of this directory will determine the name of the compiled binary |
| 34 | (`<build>/bin/bar`) |
| 35 | |
| 36 | - Place any number of translation units (e.g., `tools/bar/a.cpp`, `tools/bar/b.cpp`, |
| 37 | ...) in this directory. All `.cpp` files in this directory will be compiled and linked |
| 38 | together to produce the binary of the tool. One of the .cpp files should contain |
| 39 | the `main()` function. |
| 40 | |
| 41 | For example: |
| 42 | |
| 43 | mkdir tools/bar |
| 44 | echo "int bar(); int main() { return bar(); }" > tools/bar/a.cpp |
| 45 | echo "int bar() { return 10; } " > tools/bar/b.cpp |
| 46 | ./waf |
| 47 | # ... Compiling tools/bar/a.cpp |
| 48 | # ... Compiling tools/bar/b.cpp |
| 49 | # ... Linking build/bin/bar |
| 50 | |
| 51 | sudo ./waf install |
| 52 | # ... install /usr/local/bin/bar (from build/bin/bar) |
| 53 | |
| 54 | # To run the tool |
| 55 | /usr/local/bin/bar |