-
Notifications
You must be signed in to change notification settings - Fork 3
/
dexec-c-family.sh
executable file
·70 lines (59 loc) · 1.76 KB
/
dexec-c-family.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -e
dexec_script_name=$(basename ${0}); pushd $(dirname ${0}) >/dev/null
dexec_script_path=$(pwd -P); popd >/dev/null
source "${dexec_script_path}/dexec-common.sh"
dexec_default_build_name="$(dexec_uuid)"
dexec_default_output_flag="-o"
dexec_compiler=$(eval echo -e "${1}"); shift
dexec_build_name="${dexec_default_build_name}"
function dexec_validate() {
return 0
}
function dexec_setup() {
pushd ${dexec_build_path} >/dev/null
tmp_dir=/tmp/$(dexec_uuid)
mkdir -p ${tmp_dir}
shopt -s dotglob
cp -r ${dexec_build_path}/* ${tmp_dir}
shopt -u dotglob
pushd ${tmp_dir} >/dev/null
for source in "${dexec_sources[@]}"; do
sed -Ee '/^#!.*dexec/d' "${source}" > "${source}_tmp" && mv "${source}_tmp" "${source}"
done
}
function dexec_build() {
if dexec_array_contains "${dexec_default_output_flag}" "${dexec_build_args[@]}"; then
dexec_build_name=$(dexec_array_item_after "${dexec_default_output_flag}" ${dexec_build_args[@]})
else
dexec_build_args+=(${dexec_default_output_flag})
dexec_build_args+=(${dexec_build_name})
fi
${dexec_compiler} "${dexec_build_args[@]}" "${dexec_sources[@]}"
}
function dexec_run() {
if [ -x ${dexec_build_name} ]; then
./${dexec_build_name} "${dexec_args[@]}"
else
return 1
fi
}
function dexec_cleanup() {
if [ -f "${dexec_build_name}" ]; then
rm "${dexec_build_name}"
fi
popd >/dev/null
if [ -w "${dexec_build_path}" ]; then
for source in "${dexec_sources[@]}"; do
cp "${source}" "${tmp_dir}"
done
diff -Naur "${dexec_build_path}" ${tmp_dir} | patch >/dev/null
fi
popd >/dev/null
}
dexec_parse_params "${@}"
dexec_validate
dexec_setup
dexec_build
dexec_run
dexec_cleanup