-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·115 lines (73 loc) · 2.44 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·115 lines (73 loc) · 2.44 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/bash
ScriptPath=$0
Dir=$(cd $(dirname "$ScriptPath"); pwd)
ProjectNameFile="$Dir/.sis/project_name.txt"
ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile")
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
case $1 in
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Builds the ${ProjectName} library and (if present) examples
$ScriptPath [ ... flags/options ... ]
Flags/options:
standard flags:
--help
displays this help and terminates
EOF
exit 0
;;
*)
>&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage"
exit 1
;;
esac
shift
done
# ##########################################################
# main()
mkdir -p "$Dir/scratch/build-artefacts/"
# library
echo "building ${ProjectName} library ..."
go build -v "$Dir"
# examples
if [ -d "$Dir/examples" ]; then
echo "building ${ProjectName} examples ..."
# subdirectory examples (examples/<name>/main.go)
for example_dir in "$Dir"/examples/*/; do
[ -d "$example_dir" ] || continue
if [ -f "${example_dir}main.go" ]; then
example_name=$(basename "$example_dir")
echo "building example ${example_name} ..."
go build -v -o "$Dir/scratch/build-artefacts/${example_name}" "$example_dir"
fi
done
# loose single-file examples (examples/*.go)
for example_file in "$Dir"/examples/*.go; do
[ -f "$example_file" ] || continue
example_name=$(basename "$example_file" .go)
echo "building example ${example_name} ..."
go build -v -o "$Dir/scratch/build-artefacts/${example_name}" "$example_file"
done
fi
# tests (standalone programs under tests/, if present)
if [ -d "$Dir/tests" ]; then
echo "building ${ProjectName} tests ..."
for test_dir in "$Dir"/tests/*/; do
[ -d "$test_dir" ] || continue
if [ -f "${test_dir}main.go" ]; then
test_name=$(basename "$test_dir")
echo "building test ${test_name} ..."
go build -v -o "$Dir/scratch/build-artefacts/${test_name}" "$test_dir"
fi
done
for test_file in "$Dir"/tests/*.go; do
[ -f "$test_file" ] || continue
test_name=$(basename "$test_file" .go)
echo "building test ${test_name} ..."
go build -v -o "$Dir/scratch/build-artefacts/${test_name}" "$test_file"
done
fi
# ############################## end of file ############################# #