-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_file_list.sh
74 lines (59 loc) · 1.4 KB
/
make_file_list.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
71
72
73
#!/bin/sh
function usage {
cat <<EOF
make_file_list is a tool for generating source list and header list of cmake.
Usage:
make_file_list [/path/to/source/dir targt_name] [<option>]
Options:
--version, -v print make_file_list version
--help, -h print this
EOF
}
function version {
echo "make_file_list version 0.0.1"
}
function make_file_list() {
local num=$#
local search_dir=$1
local target_name=$2
local output_path=cmake/${target_name}.cmake
if [ $num -ne 2 ]; then
exit 1
fi
find $search_dir -name "*.cpp" | sed -e 's/\s\+/\n/g' | sort > srcs.tmp
find $search_dir -name "*.h" | sed -e 's/\s\+/\n/g' | sort > c_headers.tmp
find $search_dir -name "*.hpp" | sed -e 's/\s\+/\n/g' | sort > cpp_headers.tmp
echo "LIST (APPEND ${target_name}_SOURCES" > ${output_path}
cat srcs.tmp | sed -e 's/^/ /g' >> ${output_path}
echo ')' >> ${output_path}
echo "LIST (APPEND ${target_name}_HEADERS" >> ${output_path}
cat c_headers.tmp | sed -e 's/^/ /g' >> ${output_path}
cat cpp_headers.tmp | sed -e 's/^/ /g' >> ${output_path}
echo ')' >> ${output_path}
rm -f srcs.tmp c_headers.tmp cpp_headers.tmp
return 1
}
if [ $# -eq 2 ]; then
make_file_list $1 $2
ret=$?
exit $ret
fi
while [ $# -gt 0 ];
do
case $1 in
--help|-h)
usage
exit 0
;;
--version|-v)
version
exit 0
;;
*)
echo "[ERROR] Invalid option $1"
usage
exit 1
;;
esac
shift
done