-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathlibraries.sh
107 lines (87 loc) · 2.15 KB
/
libraries.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
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
#!/bin/bash
ROOT="../.."
if [ -f "$ROOT/variables.sh" ]; then
. "$ROOT/variables.sh"
fi
. "$ROOT/ghost.sh"
. "$ROOT/applications/shared.sh"
#
# LIBRARY BUILD
#
# This is a preset build script for a library. It defines a set of targets to build the library,
# install it to the system target and also install the headers respectively.
#
# Requirements
requireVar "ARTIFACT_NAME"
requireVar "ARTIFACT_NAME_SHARED"
requireTool changes
# Variables
TARGET=$@
with TARGET "all"
with SRC "src"
with OBJ "obj"
with INC "inc"
with ARTIFACT_LOCAL "$ARTIFACT_NAME"
with ARTIFACT_TARGET "$SYSROOT_SYSTEM_LIB/$ARTIFACT_NAME"
with ARTIFACT_LOCAL_SHARED "$ARTIFACT_NAME_SHARED"
with ARTIFACT_TARGET_SHARED "$SYSROOT_SYSTEM_LIB/$ARTIFACT_NAME_SHARED"
with CFLAGS_ADD ""
with CFLAGS "-std=c++11 -I$INC $CFLAGS_ADD"
with LDFLAGS "-shared"
# Targets
target_headline $TARGET
target_clean() {
echo "cleaning:"
rm $ARTIFACT_LOCAL
rm $ARTIFACT_LOCAL_SHARED
cleanDirectory $OBJ
changes --clear
}
target_archive() {
echo "archiving:"
$CROSS_AR -r $ARTIFACT_LOCAL $OBJ/*.o
$CROSS_CC $LDFLAGS -o $ARTIFACT_LOCAL_SHARED $OBJ/*.o
}
target_clean_target() {
echo "removing $ARTIFACT_TARGET"
rm $ARTIFACT_TARGET 2 &>/dev/null
echo "removing $ARTIFACT_TARGET_SHARED"
rm $ARTIFACT_TARGET_SHARED 2 &>/dev/null
}
target_install_headers() {
echo "installing headers"
cp -r $INC/* $SYSROOT_SYSTEM_INCLUDE/
}
target_install() {
target_clean_target
target_install_headers
echo "installing artifacts"
cp $ARTIFACT_LOCAL $ARTIFACT_TARGET
cp $ARTIFACT_LOCAL_SHARED $ARTIFACT_TARGET_SHARED
}
print_help() {
echo "Usage: $0"
echo " clean cleans the output directory"
echo " all builds, links and installs the library"
echo " install-headers installs only the headers"
echo ""
}
# Execute
for var in $TARGET; do
if [[ $var = "install-headers" ]]; then
target_install_headers
elif [[ $var == "all" ]]; then
target_compile
target_archive
target_install
elif [[ $var == "clean" ]]; then
target_clean
elif [[ "$var" = "--help" || "$var" = "-h" || "$var" = "?" ]]; then
print_help
exit 0
else
echo "unknown target: '$TARGET'"
exit 1
fi
done
exit 0