forked from chen3feng/blade-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsrc
executable file
·59 lines (51 loc) · 1021 Bytes
/
lsrc
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
#!/bin/bash
# list srcs as BUILD file format, except test files.
shopt -s nullglob
first=1
function output ()
{
local src_pattern='\w+\.(c|cc|cpp)$'
local test_pattern='[-_](unit)?test\.c*'
# all sources except tests
if [[ $1 =~ $src_pattern && \
! $1 =~ $test_pattern ]]; then
if [ $first -eq 0 ]; then
echo -en ",\n"
else
first=0
fi
echo -n " '$1'"
fi
}
function handle_dir ()
{
local dir
dir=$1
if [ ! -z "$dir" ]; then
if [ "$dir" = '.' ]; then
dir=
elif ! [[ "$dir" =~ /$ ]]; then
dir=$dir/
fi
fi
for src in $dir*.{c,cc,cpp,cxx}; do
output $src
done
}
function handle_entry ()
{
for entry in $@; do
if [ -d $entry ]; then
handle_dir $entry
else
output $entry
fi
done
}
echo -e ' srcs = ['
if [ $# -eq 0 ]; then
handle_entry *.*
else
handle_entry $@
fi
echo -e '\n ]'