{"id":23940167,"url":"https://github.com/jason80/alter-bash-build","last_synced_at":"2026-05-06T19:08:30.796Z","repository":{"id":270160533,"uuid":"909495420","full_name":"jason80/alter-bash-build","owner":"jason80","description":"This bash script serves as a quick alternative to tools like Make and CMake.","archived":false,"fork":false,"pushed_at":"2025-01-06T00:51:26.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T01:31:34.682Z","etag":null,"topics":["bash-script","build-tool","c","c-language","cpp-language"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/jason80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-12-28T21:51:34.000Z","updated_at":"2025-01-06T00:51:29.000Z","dependencies_parsed_at":"2024-12-28T23:32:54.981Z","dependency_job_id":null,"html_url":"https://github.com/jason80/alter-bash-build","commit_stats":null,"previous_names":["jason80/alter-bash-build"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jason80%2Falter-bash-build","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jason80%2Falter-bash-build/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jason80%2Falter-bash-build/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jason80%2Falter-bash-build/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jason80","download_url":"https://codeload.github.com/jason80/alter-bash-build/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240415332,"owners_count":19797610,"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","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":["bash-script","build-tool","c","c-language","cpp-language"],"created_at":"2025-01-06T03:12:04.216Z","updated_at":"2026-05-06T19:08:30.789Z","avatar_url":"https://github.com/jason80.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alternative Build Script for C and C++\nThis bash script serves as a quick alternative to tools like Make and CMake.\n\n![NEW](https://img.shields.io/badge/NEW-brightgreen) GNU gettext translation support ![NEW](https://img.shields.io/badge/NEW-brightgreen)\n\n![NEW](https://img.shields.io/badge/NEW-brightgreen) Install option ![NEW](https://img.shields.io/badge/NEW-brightgreen)\n\n## Usage\n\nFor the following example project structure, simply copy the `build.sh` file.\n\n- 📂 Project root\n\t- 📂 src\n\t\t- 📄 main.c\n\t\t- 📄 test.c\n\t- 📂 include\n\t\t- 📄 test.h\n\t\t- 📄 tools.h\n\t- 📄 **build.sh**\n\nThen, simply modify the first lines of the script:\n\n```bash\nSRC_DIR=\"src\"                  # Source code dir.\nSRC_EXT=\"*.c\"                  # *.c  *.cpp extensions.\nTYPE=\"executable\"              # \"executable\" target, \"static\" library or \"shared\" library.\nBUILD_DIR=\"build\"              # Target build directory.\nTARGET=\"test\"                  # Name of the executable or library.\nCXX=\"gcc\"                      # \"gcc\" or \"g++\" compiler selection.\nCFLAGS=\"-Wall -I include\"      # Compiler options.\nLFLAGS=\"\"                      # Linker options.\nMODULE_DEPS=\"\"                 # Module lib dependences.\n\n# Install (for executable and shared)\nINSTALL_PREFIX=\"/usr/local\"\nINSTALL_BIN=\"$INSTALL_PREFIX/bin\"\nINSTALL_LIB=\"$INSTALL_PREFIX/lib\"\nINSTALL_INC=\"$INSTALL_PREFIX/include/$TARGET\"\nINSTALL_RES=\"$INSTALL_PREFIX/share/$TARGET\"\n\nINSTALL_EXTRA=\"\"\t\t\t\t# Extra resources directories (space-separated list)\n\n# Translation\nDOMAIN=\"$TARGET\"\nLOCALE_DIR=\"locales\"\nLANGUAGES=\"es fr it\"           # space-separated list\nPOT_FILE=\"$DOMAIN.pot\"\nTRANSL_SRC_EXTRA=\"\"            # Extra source files to translate (space-separated list)\n```\n\n## Running\n\nMark `build.sh` as executable using:\n\n```bash\nchmod +x build.sh\n```\nor\n```bash\nbash build.sh\n```\n\nYou can create an alias\n```bash\nalias build='bash ./build.sh'\n```\n\nand run the script in the following ways:\n\n* `./build.sh` or `./build.sh build`: build the project.\n* `./build.sh clean`: clean the built files.\n* `./build.sh run`: run the target (only executables).\n* `./build.sh debug`: run the executable using the GDB debugger (only executables). *Note: The object files and the executable must include debugging information generated with the compiler's options.*\n* `./build.sh install`: install the target on the system (run with superuser privileges).\n* `./build.sh translations` or\n`./build.sh transl`: create or update gettext translation files.\n\n## Static and Shared Libraries\n\nSetting the option `TYPE=\"static\"`, the script will generate a static library inside the `build/` directory.\n\nThen: if `TARGET=\"Example\"`, it will generate `libExample.a`\n\nOn the other hand, the option `TYPE=\"shared\"` generates a shared library (.so).\n\n## Dependencies\n\nOnly the translation files that have been modified compared to the compiled objects will be compiled. If any object is compiled, the target is relinked.\n\nThe script enables the compiler option to generate dependency files within the build directory. It then checks if they have been modified to regenerate the object.\n\n## Modules\n\nProjects can be created with modules as follows:\n\n- 📂 Project root\n\t- 📂 ExtendLib\n\t\t- 📂 src\n\t\t\t- 📄 utils.cpp\n\t\t- 📂 include\n\t\t\t- 📄 utils.h\n\t\t- 📄 **build_1.sh**\n\n\t- 📂 main\n\t\t- 📂 src\n\t\t\t- 📄 main.cpp\n\t\t- 📄 **build_2.sh**\n\t- 📄 **build.sh**\n\n### build_1.sh (lib):\n```bash\nSRC_DIR=\"src\"\nSRC_EXT=\"*.cpp\"\nTYPE=\"static\"\t\t\t# Static library\nBUILD_DIR=\"build\"\nTARGET=\"ExtendLib\"\t\t# Generates: \"build/libExtendLib.a\"\nCXX=\"g++\"\nCFLAGS=\"-Wall -I include\"\nLFLAGS=\"\"\nMODULE_DEPS=\"\"\n```\n\n### build_2.sh (main module):\n```bash\nSRC_DIR=\"src\"\nSRC_EXT=\"*.cpp\"\nTYPE=\"executable\"\t\t# Executable\nBUILD_DIR=\"build\"\nTARGET=\"test\"\t\t\t# Executable name\nCXX=\"g++\"\nCFLAGS=\"-Wall -I include -I ../ExtendLib/include\"\t# Compiler options\nLFLAGS=\"-L ../ExtendLib/build -l ExtendLib\"\t\t\t# Linker options\nMODULE_DEPS=\"../ExtendLib/build/libExtendLib.a\"\t\t# Add module dependence to rebuild project\n```\n\n### build.sh (simple root build script):\n```bash\n#!/bin/bash\n./ExtendLib/build_1.sh $1\n./main/build_2.sh $1\n```\n\nConsider `ExtendLib` and `main` as modules. `main` depends on `ExtendLib`. The following line makes the dependency more robust:\n\n```bash\nMODULE_DEPS=\"../ExtendLib/build/libExtendLib.a\"\n```\n\nIf anything in `ExtendLib` changes, the `main` target is rebuilt.\n\nWhen using the `run` option, it checks if the target is available. It also recompiles if there are changes.\n\n## Install\nUsing the 'install' option, the build targets are copied to the system’s local directories. This is only available for 'executable' and 'shared' types.\n\nAdditional resource directories can be specified, which will be copied into the local 'share' directory.\n\nIt must be run with administrator privileges.\n\n```bash\nINSTALL_PREFIX=\"/usr/local\"\t\t\t\t\t\t# base dir\nINSTALL_BIN=\"$INSTALL_PREFIX/bin\"\t\t\t\t# bin dir for executable target\nINSTALL_LIB=\"$INSTALL_PREFIX/lib\"\t\t\t\t# lib dir for shared objects\nINSTALL_INC=\"$INSTALL_PREFIX/include/$TARGET\"\t# include dir for headers\nINSTALL_RES=\"$INSTALL_PREFIX/share/$TARGET\"\t\t# share dir for extra resources\n\nINSTALL_EXTRA=\"\"\t\t# Extra resources directories (space-separated list)\n```\n\n## Translations\n\nThe `translation` argument generates the file and directory structure for the project’s translation. You only need to list the languages separated by spaces. All the project’s source files will be included. Gettext must be properly configured, including both the domain and the strings to be read.\n\n### Generated example if `LANGUAGE=\"es fr it\"`:\n\n- 📂 Project root\n\t- 📂 locales\n\t\t- 📂 es\n\t\t\t- 📂 LC_MESSAGES\n\t\t\t\t- 📄 test.mo\n\t\t- 📂 fr\n\t\t\t- 📂 LC_MESSAGES\n\t\t\t\t- 📄 test.mo\n\t\t- 📂 it\n\t\t\t- 📂 LC_MESSAGES\n\t\t\t\t- 📄 test.mo\n\t- 📂 po\n\t\t- 📄 es.po\n\t\t- 📄 fr.po\n\t\t- 📄 it.po\n\t- 📄 test.pot\n\t- 📄 **build.sh**\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjason80%2Falter-bash-build","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjason80%2Falter-bash-build","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjason80%2Falter-bash-build/lists"}