interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / wasm / mkdist.sh

210 lines · 3960 bytes Raw Blame History
1#!/usr/bin/env bash
2###
3#
4# Builds the SQLite JS/WASM distribution zip file.
5#
6# Usage: $0 build-name ?flags?
7#
8# build-name is the dir/archive name prefix for the
9# build and defaults to sqlite-wasm.
10#
11# -?|--help = Show this text
12#
13# -0 = Use -O0 instead of ${optFlag}
14#
15# -1 = Use make -j1 instead of ${makeFlag}
16#
17# -64 = Include 64-bit builds
18#
19# --noclean = do not run 'make clean' first
20#
21# --snapshot = gives the archive name a distinctive suffix
22#
23###
24
25function die(){
26 local rc=$1
27 shift
28 echo "Error: $@" 1>&2
29 exit $rc
30}
31
32dirTop=../..
33buildName=
34b64=0
35optFlag=-Oz
36clean=1
37makeFlag=-j4
38snapshotSuffix=
39for arg in $@; do
40 case $arg in
41
42 -64) b64=1
43 ;;
44
45 -0) optFlag=-O0
46 ;;
47
48 -1) makeFlag=
49 ;;
50
51 --noclean) clean=0
52 ;;
53
54 --snapshot)
55 snapshotSuffix=-snapshot-$(date +%Y%m%d)
56 ;;
57
58 -?|--help)
59 sed -n -e '2,/^###/p' $0
60 exit
61 ;;
62
63 *) if [[ x != x${buildName} ]]; then
64 die 1 "Unhandled argument: $arg"
65 fi
66 buildName=$arg
67 ;;
68 esac
69done
70
71make=
72for i in gmake make; do
73 make=$(which $i 2>/dev/null)
74 [[ x != x${make} ]] && break
75done
76[[ x = x$make ]] && die 127 "Cannot find make"
77
78
79[[ x = x${buildName} ]] && buildName=sqlite-wasm
80
81buildName=${buildName}${snapshotSuffix}
82
83echo "Creating the SQLite wasm dist bundle..."
84
85#
86# Generates files which, when built, will also build all of the pieces
87# neaded for the dist bundle.
88#
89tgtFiles=(
90 demo-worker1-promiser.html
91 demo-worker1-promiser.js
92 demo-worker1-promiser-esm.html
93 demo-worker1-promiser.mjs
94
95 tester1.html
96 tester1-esm.html
97 tester1-worker.html
98 tester1.js
99 tester1.mjs
100)
101
102if [[ 1 = $b64 ]]; then
103 tgtFiles+=(
104 tester1-64bit.html
105 tester1-esm-64bit.html
106 tester1-worker-64bit.html
107 tester1-64bit.js
108 tester1-64bit.mjs
109 )
110fi
111
112[[ 1 = $clean ]] && $make clean
113$make $makeFlag \
114 t-version-info t-stripccomments \
115 ${tgtFiles[@]} \
116 "emcc_opt=${optFlag}" || die $?
117
118dirTmp=d.dist
119rm -fr $dirTmp
120mkdir -p $dirTmp/jswasm || die $?
121mkdir -p $dirTmp/common || die $?
122
123# Static files for the top-most dir:
124fTop=(
125 demo-123.html
126 demo-123-worker.html
127 demo-123.js
128
129 demo-worker1.html
130 demo-worker1.js
131
132 demo-jsstorage.html
133 demo-jsstorage.js
134
135 module-symbols.html
136)
137
138# Files for the jswasm subdir sans jswasm prefix:
139#
140# fJ1 = JS files to stripccomments -k on
141# fJ2 = JS files to stripccomments -k -k on
142fJ1=(
143 sqlite3-opfs-async-proxy.js
144 sqlite3-worker1.js
145 sqlite3-worker1.mjs
146 sqlite3-worker1-bundler-friendly.mjs
147 sqlite3-worker1-promiser.js
148 sqlite3-worker1-promiser.mjs
149 sqlite3-worker1-promiser-bundler-friendly.mjs
150)
151fJ2=(
152 sqlite3.js
153 sqlite3.mjs
154)
155
156# fW = list of wasm files to copy from jswasm/.
157fW=(sqlite3.wasm)
158if [[ 1 = $b64 ]]; then
159 fW+=(sqlite3-64bit.wasm)
160fi
161
162function fcp() {
163 cp -p $@ || die $?
164 chmod +w ${@: -1}
165}
166
167function scc(){
168 ${dirTop}/tool/stripccomments $@ || die $?
169}
170
171jw=jswasm
172fcp ${tgtFiles[@]} $dirTmp/.
173fcp README-dist.txt $dirTmp/README.txt
174fcp index-dist.html $dirTmp/index.html
175fcp common/*.css common/SqliteTestUtil.js $dirTmp/common/.
176
177for i in ${fTop[@]}; do
178 fcp $i $dirTmp/.
179done
180
181for i in ${fW[@]}; do
182 fcp $jw/$i $dirTmp/$jw/.
183done
184
185for i in ${fJ1[@]}; do
186 scc -k < $jw/$i > $dirTmp/$jw/$i || die $?
187done
188
189for i in ${fJ2[@]}; do
190 scc -k -k < $jw/$i > $dirTmp/$jw/$i || die $?
191done
192
193#
194# Done copying files. Now zip it up...
195#
196svi=./version-info
197vnum=$($svi --download-version)
198[ "" = "$vnum" ] && die "version number is empty!"
199vdir=${buildName}-${vnum}
200fzip=${vdir}.zip
201rm -fr ${vdir} ${fzip}
202mv $dirTmp $vdir || die $?
203zip -rq9 $fzip $(find $vdir -type f | sort) || die $?
204ls -la $fzip
205unzip -lv $fzip || die $?
206cat <<EOF
207**
208** Unzipped files are in $vdir
209**
210EOF