-
Notifications
You must be signed in to change notification settings - Fork 1
/
emlib.sh
executable file
·166 lines (134 loc) · 3.29 KB
/
emlib.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
function usage() {
echo "emscripten library building helper"
echo "usage:"
echo " emlib.sh build <package name>"
echo " emlib.sh rebuild <package name>"
echo " emlib.sh clean <package name>"
echo " emlib.sh list"
}
StartDir=`pwd`
ModifiedPackages=()
SysRootDir=`pwd`
RepositoryDir="${SysRootDir}/repositories"
BuildDirName="build_wasm"
MakeConcurrency=$(grep -c ^processor /proc/cpuinfo)
MakeConcurrency=${MakeConcurrency:="1"}
EnableShared=0
EnableThreads=0
EnableSIMD=0
CMakeCommand=${CMakeCommand:="emcmake cmake"}
MakeCommand=${MakeCommand:="emmake make"}
export CFLAGS=${CFLAGS}
export CXXFLAGS=${CXXFLAGS}
export LDFLAGS=${LDFLAGS}
export MakeFlags=""
function analyse_command_lines() {
shift 1
while [ "${1}" != "" ]; do
case "${1}" in
--sysroot)
SysRootDir="${2}"
shift 2;;
--repository-dir)
RepositoryDir="${2}"
shift 2;;
--build-dir-name)
BuildDirName="${2}"
shift 2;;
--shared)
EnableShared=1
CFLAGS+="-s SIDE_MODULE=2 "
CXXFLAGS+="-s SIDE_MODULE=2 "
LDFLAGS+="-s SIDE_MODULE=2 --oformat=wasm "
shift 1;;
--side-module)
CFLAGS+="-s SIDE_MODULE=2 "
CXXFLAGS+="-s SIDE_MODULE=2 "
LDFLAGS+="-s SIDE_MODULE=2 "
shift 1;;
--simd)
EnableSIMD=1
CFLAGS+="-msimd128 -msse4.2 "
CXXFLAGS+="-msimd128 -msse4.2 "
LDFLAGS+="-msimd128 -msse4.2 "
shift 1;;
--threads)
EnableThreads=1
CFLAGS+="-pthread "
CXXFLAGS+="-pthread "
LDFLAGS+="-pthread "
shift 1;;
-j)
MakeConcurrency="${2}"
shift 2;;
--flags)
MakeFlags+=" ${2}"
shift 2;;
*)
ModifiedPackages+=( "${1}" )
shift 1;;
esac
done
export PKG_CONFIG_PATH="${SysRootDir}/lib/pkgconfig:${SysRootDir}/share/pkgconfig"
export EM_PKG_CONFIG_PATH="${PKG_CONFIG_PATH}"
}
function build_packages() {
if [ ! -e "${RepositoryDir}" ]; then
mkdir "${RepositoryDir}"
fi
emsdk_env.sh
while [ "${1}" != "" ]; do
cd "${StartDir}"
scriptPath="scripts/${1}.sh"
if [ ! -e "${scriptPath}" ]; then
echo "emlib: unknown package '${1}'"
shift 1
continue
fi
echo "emlib: building package '${1}' ..."
source ${scriptPath}
init && build
shift 1
done
}
function clean_packages() {
while [ "${1}" != "" ]; do
cd "${StartDir}"
scriptPath="scripts/${1}.sh"
if [ ! -e "${scriptPath}" ]; then
echo "emlib: unknown package '${1}'"
shift 1
continue
fi
echo "emlib: cleaning package '${1}' ..."
source ${scriptPath}
init && clean
shift 1
done
}
function list() {
echo "available packages:"
for scriptPath in `find ./scripts -type f -path "*/*.sh"`; do
RepositoryLicense=
source ${scriptPath}
echo " ${RepositoryName} <${RepositoryAddress}> (${RepositoryLicense})"
done
}
function main() {
analyse_command_lines $*
case "${1}" in
build)
build_packages "${ModifiedPackages[@]}";;
rebuild)
clean_packages "${ModifiedPackages[@]}"
build_packages "${ModifiedPackages[@]}";;
clean)
clean_packages "${ModifiedPackages[@]}";;
list)
list;;
*)
usage;;
esac
}
main $*