From 2ec4360b84e36f4c99d11b8b1c2a63e36d57fee4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 24 Aug 2017 21:31:16 +0200 Subject: runc*: support -I w/ relative paths --- %HOME%/.bash_utils/cxx.sh | 48 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/%HOME%/.bash_utils/cxx.sh b/%HOME%/.bash_utils/cxx.sh index 633e154..6e4df60 100644 --- a/%HOME%/.bash_utils/cxx.sh +++ b/%HOME%/.bash_utils/cxx.sh @@ -22,6 +22,10 @@ runcxx_flags=('-Wall' '-Wextra' '-std=c++14') runc_compiler=gcc runcxx_compiler=g++ +_get_absolute_path() { + readlink -z --canonicalize-missing -- "$@" +} + _runc_usage() ( set -o errexit -o nounset -o pipefail @@ -33,7 +37,7 @@ _runc_usage() ( echo "$prefix: $msg" done - echo "usage: $prefix [-h|--help] [-c|--comp-arg ARG]... C_PATH... [-- [PROG_ARG]...]" + echo "usage: $prefix [-h|--help] [-c|--comp-arg ARG]... [-I DIR]... C_PATH... [-- [PROG_ARG]...]" ) runc() ( @@ -41,6 +45,7 @@ runc() ( local -a c_flags=(${runc_flags[@]+"${runc_flags[@]}"}) local -a src_files=() + local -a include_dirs=() local -a prog_args while [ "$#" -gt 0 ]; do @@ -62,6 +67,15 @@ runc() ( shift ;; + -I) + if [ "$#" -eq 0 ]; then + _runc_usage "missing argument for parameter: $key" >&2 + return 1 + fi + include_dirs+=("$1") + shift + ;; + --) break ;; @@ -85,7 +99,14 @@ runc() ( local src_file while IFS= read -d '' -r src_file; do src_files+=("$src_file") - done < <( readlink -z --canonicalize-missing -- ${_src_files[@]+"${_src_files[@]}"} ) + done < <( _get_absolute_path ${_src_files[@]+"${_src_files[@]}"} ) + + if [ "${#include_dirs[@]}" -gt 0 ]; then + local include_dir + while IFS= read -d '' -r include_dir; do + c_flags+=("-I$include_dir") + done < <( _get_absolute_path ${include_dirs[@]+"${include_dirs[@]}"} ) + fi local build_dir build_dir="$( mktemp --directory )" @@ -114,7 +135,7 @@ _runcxx_usage() ( echo "$prefix: $msg" done - echo "usage: $prefix [-h|--help] [-c|--comp-arg ARG]... CPP_PATH... [-- [PROG_ARG]...]" + echo "usage: $prefix [-h|--help] [-c|--comp-arg ARG]... [-I DIR]... CPP_PATH... [-- [PROG_ARG]...]" ) runcxx() ( @@ -122,6 +143,7 @@ runcxx() ( local -a cxx_flags=(${runcxx_flags[@]+"${runcxx_flags[@]}"}) local -a src_files=() + local -a include_dirs=() local -a prog_args while [ "$#" -gt 0 ]; do @@ -135,7 +157,7 @@ runcxx() ( ;; -c|--comp-arg) - if [ "$#" -le 1 ]; then + if [ "$#" -eq 0 ]; then _runcxx_usage "missing argument for parameter: $key" >&2 return 1 fi @@ -143,6 +165,15 @@ runcxx() ( shift ;; + -I) + if [ "$#" -eq 0 ]; then + _runc_usage "missing argument for parameter: $key" >&2 + return 1 + fi + include_dirs+=("$1") + shift + ;; + --) break ;; @@ -166,7 +197,14 @@ runcxx() ( local src_file while IFS= read -d '' -r src_file; do src_files+=("$src_file") - done < <( readlink -z --canonicalize-missing -- ${_src_files[@]+"${_src_files[@]}"} ) + done < <( _get_absolute_path ${_src_files[@]+"${_src_files[@]}"} ) + + if [ "${#include_dirs[@]}" -gt 0 ]; then + local include_dir + while IFS= read -d '' -r include_dir; do + cxx_flags+=("-I$include_dir") + done < <( _get_absolute_path ${include_dirs[@]+"${include_dirs[@]}"} ) + fi local build_dir build_dir="$( mktemp --directory )" -- cgit v1.2.3