forked from chen3feng/blade-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-static-libs
executable file
·59 lines (48 loc) · 1.27 KB
/
merge-static-libs
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
set -e
if [ $# -lt 1 ]; then
echo "Usage <blade-target-name> [build arguments]"
exit 1;
fi
target_pattern="^:[A-Za-z0-9+_.-]+$"
if [[ ! "$1" =~ $target_pattern ]]; then
echo "Invalid target name, can only be :name"
fi
# :poppy -> poppy
name=${1/:/}
blade build $@
source `dirname $0`/bladefunctions
wd=`pwd`
root=`_find_project_root`
relwd="${wd/${root}/}"
o=`blade query "$1" --deps`
cd $root
libname="$wd/lib${name}.a"
rm -f "$libname"
ar -q "$libname"
macname="merge-$$.mac"
echo "OPEN $libname" > $macname
echo "ADDLIB blade-bin$relwd/lib$name.a" >> $macname
libpattern="^[A-Za-z0-9+_./-]+:[A-Za-z0-9+_.-]+$"
syslibpattern="^.+"
echo "$o" | while read line; do
if [[ "$line" =~ $libpattern ]]; then
lib="blade-bin/${line/://lib}.a"
echo "ADDLIB $lib" >> $macname
else
if [[ -n "$line" ]]; then
if [[ "$line" =~ $syslibpattern ]]; then
echo -e "\033[1;33m$line is a system library and then can't be merged,"\
"don't forget to link it\033[m"
else
echo -e "\033[1;33mIgnore unknown libname: $line\033[m"
fi
fi
fi
done
echo "SAVE" >> $macname
echo "END" >> $macname
ar -M < $macname
ranlib $libname
rm $macname
echo "$libname generated"