A simple clean minimal shell based build tool for C/C++ based projects.
There are so many build tools already available currently - autoconf, cmake, xmake, meson, scons, bazel, buck2
Why create a new one??
- the existing tools are highly advanced
- are created for handling all possible combinations of possible build scnearios
- are created to handle complex build deployments
- some of them provide sandboxing
- some are targeted towards speed
- etc etc
The only reason for creating shellb was to have a minimal, clean, simple and concise build files, having worked with all the various build tools out there for ffead-cpp, managing the build files and keeping up with so many build files for a single project led to a thought which said the process should be easy and simple for anyone and the resulting build files should be small and self explanatory.
This thought led to the idea of creating a tool which uses bash as the source language, shell is available everywhere and so the deployment would require no extra installation of any dependencies except a single script and the resulting build files would acahive the target of simplicity, conciseness and clarity.
Please understand that the tool does not claim to be fast, better or ready to handle every complex permutation of build deployments possible out there.
But it does live upto its motto of being simple and concise, lets have a look at the table below for a simple/only comparison of build files for the project ffead-cpp
Tool | Lines of Code | Build Time |
---|---|---|
Autoconf | ~3000 | ~12 mins |
Cmake | ~1000 | ~3.5 mins |
Meson | ~700 | ~3 mins |
Scons | ~650 | ~6.5 mins |
Xmake | ~1000 | ~3.5 mins |
Buck2 | ~300 | ~2 mins |
Bazel | ~450 | ~3 mins |
Shellb | ~167 | ~3 mins |
wget -q https://github.com/sumeetchhetri/shellb/releases/download/2.0.0/shellb -P . && chmod +x shellb && mv shellb /usr/local/bin
First a build script should be created which is nothing but a simple bash script, the only requirement is that the script should contain the following functions, example
- do_setup - Setup initial environment, platform (c/c_cpp), build system (emb/bazel/buck2), any configuration headers to be generated etc
- do_config - Setup build configuration parameters, the function should return a newline separated list of properties (pipe separated values of param name, description and initial value (0,1))
- do_start - Provide the dependencies lookup, #define generation, compile and build any libraries/binaries
- do_install - Finally install the project after successfull build
LOG_MODE - variable to either log output to file or to console
BUILD_PROJ_NAME - build project name
BUILD_SYS - the build tool used (emb|bazel|buck2)
BUILD_PLATFORM - the build platform supported (c|c_cpp)
DEFS_FILE - the relative path to the generated header definition file
A newline separated list of properties (pipe separated values of param name, description and initial value (0,1) 'echoed'
Lets look at an example
function do_config() {
configs+=$'SOME_PARAM|Some description|0\n'
configs+=$'OTHER_PARAM|Other description|1\n'
echo "$configs"
}
set_out - sets the build output directory, if it does not exist it will be created
set_install - name of the project output folder name which will consist the binaries/libarries generated from the build
finc_c_compiler - finds the c compiler and the static library archiver programs (clang gcc c & ar) if found on the system
finc_cpp_compiler - finds the c++, c compilers and the static library archiver (clang++ g++ c++ & clang gcc c & ar) if found on the system
c_flags - set the c++ compiler flags to be passed to the c++ compiler
cpp_flags - set the c++ compiler flags to be passed to the c++ compiler
l_flags - set the liinker/library flags
is_config - check if the said config property is enabled or not
add_def - add a preprocessor define to the $DEFS_FILE file
add_lib - provide library to be used during linking
add_inc_path - add an include directory path to the compiler options
add_lib_path - add a library path to the linker
c_hdr - check whether the c header file exists
cpp_hdr - check whether the c++ header file exists
c_lib - check whether a c library file exists and can be used for linking
cpp_lib - check whether a c++ library file exists and can be used for linking
c_hdr_lib - check whether a c include file exists and can be compiled & whether a c library file exists and can be used for linking
cpp_hdr_lib - check whether a c++ include file exists and can be compiled & whether a c++ library file exists and can be used for linking
c_code - check whether the c code compiles
c_func - check whether the c function exists
cpp_code - check whether the c++ code compiles
set_src - specify source files path to be compiled and compile for 'emb' mode, generates build files for bazel|buck2
set_inc_src - specify source/include files path to be compiled and compile for 'emb' mode, generates build files for bazel|buck2
set_src_files - sepcify the source files to be compiled and compile for 'emb' mode, generates build files for bazel|buck2
set_exclude_src - exclude any source file paths from the list of to be compiled sources
trigger_build - trigger the builds for all the targets specified for non 'emb' modes, 'bazel|buck'
templatize - templatize/evaluate the shellb template file consisting of any variables to be replaced with tha @VAR@ syntax example
install_here - install the said files/directories to the install directory, copy the files relative to the 'set_out' diectory, or either from an absolute path, or with the 'RELATIVE_DIR@.h,.so,*.html...' syntax
Provide any install_here commands or any installation related steps in this function
And you have the entire power of shell scripting at your disposal throughout the build file, do try it out!!