aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 21:23:33 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 21:23:33 +0300
commit2a103e32e7042bf1e3ef91470823efbfda49941d (patch)
tree44b395fd76503d7d217c69094a3af370b96a0245
parentmove Netwrix-specific stuff to .bashrc_netwrix (diff)
downloadlinux-home-2a103e32e7042bf1e3ef91470823efbfda49941d.tar.gz
linux-home-2a103e32e7042bf1e3ef91470823efbfda49941d.zip
runc*: add command line options
-rw-r--r--.bashrc98
1 files changed, 77 insertions, 21 deletions
diff --git a/.bashrc b/.bashrc
index 5d3ffe4..47deb7d 100644
--- a/.bashrc
+++ b/.bashrc
@@ -259,45 +259,101 @@ verify_checksums() {
sha1sum --check "$checksums_path"
}
-# `runhaskell` (from the Haskell world) alternatives for C/C++
-# ------------------------------------------------------------
+# `runhaskell` alternatives for C/C++
+# -----------------------------------
+
+C_FLAGS=('-Wall' '-Wextra')
runc() (
set -o errexit
- local -a src_files
- local src_file
-
- for src_file in "$@"; do
- src_files+=("$( realpath "$src_file" )")
+ 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
- local build_dir="$( mktemp -d )"
+ 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" )"
- set +o errexit
+ gcc -o "$output_name" \
+ "${c_flags[@]+"${c_flags[@]}"}" \
+ "${src_files[@]+"${src_files[@]}"}"
- gcc -Wall -Wextra "${src_files[@]}" && ./a.exe
- popd > /dev/null && rm -rf "$build_dir"
+ "$output_name" "${prog_flags[@]+"${prog_flags[@]}"}"
)
-runcpp() (
- set -o errexit
+CXX_FLAGS=('-Wall' '-Wextra' '-std=c++14')
- local -a src_files
- local src_file
+runcxx() (
+ set -o errexit
- for src_file in "$@"; do
- src_files+=("$( realpath "$src_file" )")
+ 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
- local build_dir="$( mktemp -d )"
+ 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" )"
- set +o errexit
+ g++ -o "$output_name" \
+ "${cxx_flags[@]+"${cxx_flags[@]}"}" \
+ "${src_files[@]+"${src_files[@]}"}"
- g++ -std=c++14 -Wall -Wextra "${src_files[@]}" && ./a.exe
- popd > /dev/null && rm -rf "$build_dir"
+ "$output_name" "${prog_flags[@]+"${prog_flags[@]}"}"
)
# Miscellaneous