-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.sh
executable file
·121 lines (107 loc) · 2.7 KB
/
build.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
#!/bin/sh
# directories
SOURCE="quickjs-2020-04-12"
SOURCE_URL="https://bellard.org/quickjs/quickjs-2020-04-12.tar.xz"
FAT="QuickJS_iOS"
THIN=`pwd`/"thin"
ARCHS="x86_64h arm64 x86_64"
COMPILE="y"
LIPO="y"
XCFRAMEWORK="y"
DEPLOYMENT_TARGET="10.0"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
XCFRAMEWORK=
elif [ "$*" = "fw" ]
then
# skip compile
COMPILE=
LIPO=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
if [ ! -r $SOURCE ]
then
echo 'QuickJS source not found. Trying to download...'
curl $SOURCE_URL -o quickjs.tar.xz && tar -xf ./quickjs.tar.xz \
|| exit 1
ln -s $SOURCE/VERSION ./VERSION
cat ./environ.h >> $SOURCE/quickjs.h
fi
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
CONFIG_XCRUN_EXTRA_FLAG="-sdk iphonesimulator"
CONFIG_EXTRA_CFLAGS="-arch $ARCH -mios-simulator-version-min=$DEPLOYMENT_TARGET"
elif [ "$ARCH" = "x86_64h" ]
then
MACOSX_SDK_DIR=`xcrun --show-sdk-path`
CONFIG_XCRUN_EXTRA_FLAG=""
CONFIG_EXTRA_CFLAGS="-arch $ARCH --target=x86_64-apple-ios13-macabi -isysroot $MACOSX_SDK_DIR -isystem $MACOSX_SDK_DIR/System/iOSSupport/usr/include -iframework $MACOSX_SDK_DIR/System/iOSSupport/System/Library/Frameworks"
else
CONFIG_XCRUN_EXTRA_FLAG="-sdk iphoneos"
CONFIG_EXTRA_CFLAGS="-arch $ARCH -mios-simulator-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
fi
if [ "$ARCH" = "i386" -o "$ARCH" = "armv7" ]
then
CONFIG_M32="y"
fi
TMPDIR=${TMPDIR/%\/} CONFIG_M32=${CONFIG_M32} CONFIG_EXTRA_CFLAGS=${CONFIG_EXTRA_CFLAGS} CONFIG_XCRUN_EXTRA_FLAG=${CONFIG_XCRUN_EXTRA_FLAG} make -f ../Makefile -C $CWD/$SOURCE clean libquickjs.a || exit 1
mkdir -p $THIN/$ARCH/lib
mv $CWD/$SOURCE/libquickjs.a $THIN/$ARCH/lib/libquickjs.a
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
rm -rf ./$FAT/lib
mkdir -p $FAT/lib
mkdir -p $FAT/headers
cp $CWD/$SOURCE/quickjs*.h $FAT/headers
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done
fi
if [ "$XCFRAMEWORK" ]
then
echo "building xcframework..."
rm -rf ./$FAT/framework
mkdir -p $FAT/framework
mkdir -p $FAT/headers
CWD=`pwd`
cp $CWD/$SOURCE/quickjs*.h $FAT/headers
set - $ARCHS
CWD=`pwd`
BUILD_FW="xcodebuild -create-xcframework"
for ARCH in $ARCHS
do
BUILD_FW="$BUILD_FW -library $THIN/$ARCH/lib/libquickjs.a -headers $FAT/headers"
done
BUILD_FW="$BUILD_FW -output $FAT/framework/QuickJS.xcframework"
echo $BUILD_FW
$BUILD_FW
fi
echo Done