{"id":23086888,"url":"https://github.com/theakman2/ntb","last_synced_at":"2025-10-14T06:02:47.903Z","repository":{"id":74205607,"uuid":"210133023","full_name":"theakman2/ntb","owner":"theakman2","description":"A simple Ninja file generator for Linux","archived":false,"fork":false,"pushed_at":"2019-09-22T11:10:51.000Z","size":190,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-07T09:36:28.978Z","etag":null,"topics":["build","c","cpp","lua","ninja-build"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theakman2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-22T11:05:13.000Z","updated_at":"2025-05-15T01:20:41.000Z","dependencies_parsed_at":"2023-02-25T19:15:18.348Z","dependency_job_id":null,"html_url":"https://github.com/theakman2/ntb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/theakman2/ntb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theakman2%2Fntb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theakman2%2Fntb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theakman2%2Fntb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theakman2%2Fntb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theakman2","download_url":"https://codeload.github.com/theakman2/ntb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theakman2%2Fntb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017959,"owners_count":26086237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","c","cpp","lua","ninja-build"],"created_at":"2024-12-16T19:32:07.582Z","updated_at":"2025-10-14T06:02:47.878Z","avatar_url":"https://github.com/theakman2.png","language":"Lua","readme":"# NTB\n\nA simple ninja file generator for Linux, with a focus on compiling and linking C/C++ applications.\n\nTested with Ninja 1.9.0. Untested on earlier versions.\n\n## Building\n\nOn a Linux machine:\n\n\t$ cd /path/to/this/directory\n\t$ luajit build.lua\n\nThe build artefacts are placed in the `build` directory. The binary is at `build/bin/ntb`.\n\nThe binary is standalone and does not require lua to be installed on the system.\n\n### Build Requirements\n\n* Luajit 2.1.0-beta3 or higher.\n* Luajit public headers and static library.\n* GCC or Clang.\n\n## Tests\n\nOnce NTB has been built following the instructions above, tests may be run as follows:\n\n\t$ lua /path/to/this/directory/test/main.lua\n\n## Usage\n\nNTB expects your projects to be laid out in a single folder with an `ntbconf.lua` file at the top level, like this:\n\n![Project Structure](docs/project_structure.png)\n\nEach project directory should have a Lua script file that ends in `.ntb.lua`, which contains the build instructions for that project.\n\nThe `ntbconf.lua` file at the top level must return a lua table with `targets` and `projects` values, like this example:\n\n```lua\nreturn {\n\ttargets = {\n\t\t{\n\t\t\tname = \"dbg\";\n\t\t\tkind = \"dbg\";\n\t\t},\n\t\t{\n\t\t\tname = \"rel\";\n\t\t\tkind = \"rel\";\n\t\t\tcflags = {\n\t\t\t\t\"-Ofast\",\n\t\t\t\t\"-march=native\",\n\t\t\t\t\"-mtune=native\",\n\t\t\t};\n\t\t},\n\t};\n\tprojects = {\n\t\t\"bin1\",\n\t\t\"bin2/build.ntb.lua\",\n\t};\n};\n```\n\nThe projects table consists of a list of paths to the build files for each project relative to the directory containing the `ntbconf.lua` file.\n\nIf a path doesn't end with `.lua`, then `/main.ntb.lua` is appended. So `bin1` will be treated as `bin1/main.ntb.lua`.\n\nThe `ntbconf.lua` file is just a normal Lua file so any kind of scripting can be performed, such as e.g. defining projects based on an environment variable:\n\n```lua\nlocal projects;\nif os.getenv(\"FOOBAR\") == \"yes\" then\n\tprojects = {\"a\", \"b\"};\nelse\n\tprojects = {\"c\", \"d\"};\nend\n\nreturn {\n\ttargets = {\n\t\t{\n\t\t\tname = \"dbg\";\n\t\t\tkind = \"dbg\";\n\t\t},\n\t\t{\n\t\t\tname = \"rel\";\n\t\t\tkind = \"rel\";\n\t\t\tcflags = {\n\t\t\t\t\"-Ofast\",\n\t\t\t\t\"-march=native\",\n\t\t\t\t\"-mtune=native\",\n\t\t\t};\n\t\t},\n\t};\n\tprojects = projects;\n};\n```\n\nThe project build files (e.g. the `bin1/main.ntb.lua` file mentioned above) look like this:\n\n```lua\nlocal lib2 = import(\"lib2\");\nlocal sublib2 = import(\"sublib2\");\n\nreturn cbinary(\n\t\"bin1\",\n\t{\n\t\tccompile{\n\t\t\t\"main.c\",\n\t\t},\n\t\tlib2,\n\t\tsublib2,\n\t}\n);\n```\n\nThis build file imports two other projects called `lib2` and `sublib2` and returns a C binary called `bin1`. The `cbinary` function takes a name and a table of object files as the first and second parameter respectively.\n\nAgain, the build files are just normal Lua scripts so any kind of scripting can be performed.\n\nNTB will, for each target specified in the `targets` array, execute each of the files referenced in the ntbconf.lua `projects` field in order. So looking at the `test/complex/ntbconf.lua` file as an example, NTB will execute `bin1/main.ntb.lua` and then `bin2/build.ntb.lua` for the `dbg` target, and then execute `bin1/main.ntb.lua` and then `bin2/build.ntb.lua` for the `rel` target.\n\nTo actually generate a Ninja file (or files) from your project, you'll need to run the following command:\n\n\t$ ntb /path/to/ntbconf.lua\n\nThis will generate an `_out` directory adjacent to the `ntbconf.lua` file, with subdirectories for each target. One Ninja file will be generated for each target. So if the `ntbconf.lua` file specifies a target with the name `foo`, then you'll have a Ninja file at `/_out/foo/build.ninja`. You can then run:\n\n\t$ ninja -f /path/to/_out/foo/build.ninja\n\nNB: The `test` directory contains several sample projects.\n\n## Reference\n\nThis section lists the Lua functions and variables provided by NTB that may be used in the `ntbconf.lua` file or any of the individual build files.\n\n### Global variables\n\n* `ntb.scriptDir`. The absolute path to the directory containing the current lua file.\n* `ntb.scriptPath`. The absolute path of the currently-executing lua file.\n* `ntb.projectsDirectory`. The absolute path to the directory containing the `ntbconf.lua` file.\n* `ntb.buildDirectory`. The absolute path to the directory where the build artefacts (binaries, object files, etc.) of the current target will be placed.\n* `ntb.target`. The currently-active target.\n\n### Functions\n\n* `import(filepath)`. Opens and executes the file at the supplied path. The path is assumed to be relative to the directory from which the `import` is called. If the filepath doesn't end with `.lua`, then `/build.ntb.lua` is automatically appended.\n\n[TODO: finish documenting available functions.]\n\n### Other\n\nThe `penlight` and `luafilesystem` modules are built in and may be used globally (e.g. `dir.getfiles(...)` or `lfs.currentdir()`).\n\n## Why did you create this?\n\nI needed a fast, lightweight, simple, and hackable build generator for an internal project. I had tried GNU Make, CMake, Premake, writing Ninja files by hand, among others, but nothing fit the bill. Hence NTB was born.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheakman2%2Fntb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheakman2%2Fntb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheakman2%2Fntb/lists"}