diff --git a/CBUILD_VERSION b/CBUILD_VERSION new file mode 100644 index 0000000..7c32728 --- /dev/null +++ b/CBUILD_VERSION @@ -0,0 +1 @@ +2.1.1 \ No newline at end of file diff --git a/README.md b/README.md index e885d65..8a35ea9 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,31 @@ # cbuild -My C/C++ build system written in bash. +My C/C++ build system written in sh. ## Installation -```bash +```sh git clone https://timerix.ddns.net:3322/cbuild.git cd cbuild sudo ./setup.sh ``` +Can be installed to `~/.local/` if you have no root rights. +- ```sh + ./setup.sh --local + ``` +- Then add `~/.local/bin` to `PATH` in your shell config. ## Usage 1. Initialize cbuild project in some directory: - ```bash + ```sh cd some_project cbuild --new-project ``` - -2. Edit `default.config`. +2. Edit `project.config`. 3. Call some tasks: - ```bash + ```sh cbuild build_exec_dbg exec ``` +P.S. See help +```sh +cbuild -h +``` diff --git a/bootstrap.sh b/bootstrap.sh index e0a2b8e..393c52d 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -CBUILD_BOOTSTRAP_VERSION=1.0.0 +CBUILD_BOOTSTRAP_VERSION=1.0.1 set -eo pipefail function version_parse { @@ -29,29 +29,56 @@ function exec_script_line { eval "$line_str" } +function print_version_list { + dir_local="$HOME/.local/share/cbuild" + dir_global="/usr/local/share/cbuild" + files="" + if [ -d "$dir_local" ]; then + files+="$(find $dir_local -name 'CBUILD_VERSION')" + fi + if [ -d "$dir_global" ]; then + files+="$(find $dir_global -name 'CBUILD_VERSION')" + fi + for f in $files; do + cat $f | sed '$a\' + done | sort -V +} + +function print_help { + echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION" + echo "Script that launches a specific cbuild version selected by user or defined in a project config." + echo "Usage: cbuild [OPTIONS]" + echo "Options:" + echo " -h, --help Show this message" + echo " -v, --version Shows version" + echo " -c, --config FILE Set project config file path (default=./project.config)" + echo " --list-versions Shows list of installed cbuild versions" +} + # parse command line arguments project_config_path="./project.config" args=($@) args_count=${#args[@]} i=0 - -function get_next_arg { - i=$((i+1)) - safeprint "${args[i]}" -} - +if [ $args_count -eq 0 ]; then + print_help +fi while [ $i -lt $args_count ] do case "${args[i]}" in '-v' | '--version') echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION" ;; - '-c' | '--config') - project_config_path="$(get_next_arg)" + '-h' | '--help') + print_help ;; - '-n' | '--new-project') - echo "enter project cbuild version (example: 2.1.0)" - read -r CBUILD_VERSION + '-c' | '--config') + i=$((i+1)) + project_config_path="${args[i]}" + ;; + '--list-versions') + print_version_list + exit 0 ;; *) ;; @@ -59,9 +86,21 @@ do i=$((i+1)) done -# read version from project config if not specified if [ -z "$CBUILD_VERSION" ]; then - exec_script_line "$project_config_path" 2 + if [ -f "$project_config_path" ]; then + # read version from project config + exec_script_line "$project_config_path" 2 + else + echo "project config not found" + echo "list of installed cbuild versions:" + versions=$(print_version_list) + + echo "$versions" + latest_version=$(echo "$versions" | tail -n 1) + echo "select version (default=$latest_version):" + read -r CBUILD_VERSION + [ -z "$CBUILD_VERSION" ] && CBUILD_VERSION=$latest_version + fi fi version_parse "$CBUILD_VERSION" diff --git a/cbuild.sh b/cbuild.sh index a72c2de..3a9ddee 100644 --- a/cbuild.sh +++ b/cbuild.sh @@ -47,11 +47,12 @@ include "cbuild/config.sh" function print_help { myprint "cbuild v$INSTALLED_CBUILD_VERSION" myprint "C/C++ project build system written in bash." - myprint "Usage: cbuild [OPTIONS] [TASK]" - myprint " -h, --help Show this message" - myprint " -v, --version Shows version" - myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)" - myprint " -c, --config FILE Set project config file path (default=./project.config)" + myprint "Usage: cbuild [OPTIONS] [TASKS]" + myprint "Options:" + myprint " -h, --help Show this message" + myprint " -v, --version Shows version" + myprint " -c, --config FILE Set project config file path (default=./project.config)" + myprint " -n, --new-project [DIR] Initialize new cbuild project directory (default=./)" } # parse command line arguments @@ -62,6 +63,7 @@ selected_tasks_array=() i=0 if [ $args_count -eq 0 ]; then print_help + exit 1 fi while [ $i -lt $args_count ] @@ -84,6 +86,8 @@ do new_project_dir="${args[i]}" if [ -z "$new_project_dir" ]; then new_project_dir="." + else + mkdir -p "$new_project_dir" fi if ask_yn "create default cbuild project config?"; then project_config_path="$new_project_dir/project.config"