forked from chen3feng/blade-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genlibbuild
executable file
·35 lines (27 loc) · 952 Bytes
/
genlibbuild
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
#!/bin/bash
# generate BUILD file for library dir
# @author CHEN Feng <[email protected]>
shopt -s nullglob
libname=$(basename $(pwd))
echo -e "# generated by $(basename $0)\n"
# generate proto_library
for src in *.proto; do
echo -e "proto_library(\n name = '${src/./_}',\n srcs = '$src'\n)\n"
done
# generate cc_library
test_src_pattern='_test\.c.*$'
test_src_pattern2='Test\.c.*$'
echo -e "cc_library(\n name = '$libname',\n srcs = ["
for src in *.{c,cc,cpp,cxx}; do
if ! [[ ($src =~ $test_src_pattern) || ($src =~ $test_src_pattern2) ]]; then
echo " '$src',"
fi
done
echo -e " ]\n)\n"
# generate cc_test
for src in *_test.{c,cc,cpp,cxx}; do
echo -e "\ncc_test(\n name = '${src/.*/}',\n srcs = ['$src'],\n deps = [':$libname']\n)\n"
done
for src in *Test.{c,cc,cpp,cxx}; do
echo -e "\ncc_test(\n name = '${src/.*/}',\n srcs = ['$src'],\n deps = [':$libname']\n)\n"
done