aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.bashrc_cxx
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-26 02:10:27 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-26 02:10:27 +0300
commit4042abe156b4f9cad30d66238b52fcd938043ded (patch)
treeb351938efa93930aed703119e28c9c269516121f /.bashrc_cxx
parentadd append_pgn, join_pgns (diff)
downloadlinux-home-4042abe156b4f9cad30d66238b52fcd938043ded.tar.gz
linux-home-4042abe156b4f9cad30d66238b52fcd938043ded.zip
split .bashrc into multiple files
Diffstat (limited to '.bashrc_cxx')
-rw-r--r--.bashrc_cxx81
1 files changed, 81 insertions, 0 deletions
diff --git a/.bashrc_cxx b/.bashrc_cxx
new file mode 100644
index 0000000..dc1eaf5
--- /dev/null
+++ b/.bashrc_cxx
@@ -0,0 +1,81 @@
+[ ! -z "${BASHRC_CXX+x}" ] && return || readonly BASHRC_CXX=1
+
+C_FLAGS=('-Wall' '-Wextra')
+
+runc() (
+ set -o errexit
+
+ local -a c_flags=("${C_FLAGS[@]}")
+ local -a src_files=()
+ local -a prog_flags=()
+
+ while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --c-flags)
+ if [ "$#" -le 1 ]; then
+ echo "$FUNCNAME: usage error: missing value for option: $1" >&2
+ return 1
+ fi
+ shift ; c_flags+=("$1") ; shift ;;
+
+ --)
+ shift ; break ;;
+
+ *)
+ src_files+=("$( realpath "$1" )") ; shift ;;
+ esac
+ done
+
+ prog_flags=("$@")
+
+ local build_dir="$( mktemp --directory )"
+ trap "$( printf 'popd > /dev/null && rm -rf %q' "$build_dir" )" 0
+ pushd "$build_dir" > /dev/null
+ local output_name="$( mktemp --tmpdir=. "${FUNCNAME}XXX.exe" )"
+
+ gcc -o "$output_name" \
+ "${c_flags[@]+"${c_flags[@]}"}" \
+ "${src_files[@]+"${src_files[@]}"}"
+
+ "$output_name" "${prog_flags[@]+"${prog_flags[@]}"}"
+)
+
+CXX_FLAGS=('-Wall' '-Wextra' '-std=c++14')
+
+runcxx() (
+ set -o errexit
+
+ local cxx_flags=("${CXX_FLAGS[@]}")
+ local -a src_files=()
+ local -a prog_flags=()
+
+ while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --cxx-flags)
+ if [ "$#" -le 1 ]; then
+ echo "$FUNCNAME: usage error: missing value for option: $1" >&2
+ return 1
+ fi
+ shift ; cxx_flags+=("$1") ; shift ;;
+
+ --)
+ shift ; break ;;
+
+ *)
+ src_files+=("$( realpath "$1" )") ; shift ;;
+ esac
+ done
+
+ prog_flags=("$@")
+
+ local build_dir="$( mktemp --directory )"
+ trap "$( printf 'popd > /dev/null && rm -rf %q' "$build_dir" )" 0
+ pushd "$build_dir" > /dev/null
+ local output_name="$( mktemp --tmpdir=. "${FUNCNAME}XXX.exe" )"
+
+ g++ -o "$output_name" \
+ "${cxx_flags[@]+"${cxx_flags[@]}"}" \
+ "${src_files[@]+"${src_files[@]}"}"
+
+ "$output_name" "${prog_flags[@]+"${prog_flags[@]}"}"
+)