Skip to content

Commit eb121b4

Browse files
author
minggo
committed
Merge pull request #9 from andyque/testScripts
Improve building scripts
2 parents f3291bc + a50adb3 commit eb121b4

27 files changed

+987
-47
lines changed

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,156 @@ This repository is needed for cocos2d-x developers and/or people who want to por
77

88
As an example, if you want to support cocos2d-x in ARM64, you need to compile all these libraries for ARM64.
99

10+
**Note:**
11+
12+
- We use MacOSX to build all the static libraries for iOS, Android, Mac and Tizen.
13+
14+
- We use Windows to build all the static libraries for Win32.
15+
16+
- We use Ubuntu to build all the static libraries for Linux.
17+
18+
- Other platforms is not tested which means if you use Windows or Linux to build static libraries for Android, it might be failed.
19+
1020

1121
## Download
1222

1323
$ git clone https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src.git
1424
$ cd cocos2d-x-dependencies
1525
$ git submodule update --init
26+
27+
## Prerequisite
28+
### For Mac users
29+
- If you want to use these scripts, you should install Git 1.8+, CMake 2.8+ and M4 1.4+.
30+
If you are a Homebrew user, you could simply run the following commands to install these tools:
31+
32+
```cpp
33+
brew install git
34+
brew install cmake
35+
brew install m4
36+
```
37+
38+
- If you want to build static libraries for iOS and Mac, you should install the latest version of XCode. You should also install the `Command Line Tools` bundled with XCode.
39+
40+
41+
- If you want to build static libraries for Android, you should install [NDK](https://developer.android.com/tools/sdk/ndk/index.html). NDK r9d is required at the moment and you should also specify the ANDROID_NDK environment variable in your shell.
42+
43+
- If you want to build static libraries for Tizen, you should download and install [Tizen SDK](https://developer.tizen.org/downloads/tizen-sdk). And you should also add a environment variable named `TIZEN_SDK` in your shell.
44+
45+
### For Linux users
46+
xxx need to improve the document here later.
47+
48+
### For Windows users
49+
In order to run these scripts, you should install [msys2](http://msys2.github.io/) and update the system packages.
50+
51+
After that, you should also install the following dependencies:
52+
53+
```cpp
54+
pacman -S gcc
55+
pacman -S make
56+
pacman -S autoconf
57+
pacman -S automake
58+
pacman -S git
59+
pacman -S cmake
60+
pacman -S libtool
61+
```
62+
63+
## How to use
64+
### For iOS Platform
65+
For building libpng fat library:
66+
67+
```cpp
68+
cd build/ios
69+
./build_png.sh
70+
```
71+
72+
Or you can also use `build.sh` script build each static library for different arch.
73+
The usage would be:
74+
75+
```cpp
76+
usage: $0 [-s] [-k sdk] [-a arch] [-l libname]
77+
78+
OPTIONS
79+
-k <sdk version> Specify which sdk to use ('xcodebuild -showsdks', current: 8.1)
80+
-s Build for simulator
81+
-a <arch> Specify which arch to use (current: armv7)
82+
-l <libname> Specify which static library to build
83+
```
84+
85+
If you want to build *websockets* with *i386* arch, you could use the following command:
86+
87+
```cpp
88+
cd build/ios
89+
./build.sh -s -a i386 -l websockets (Don't forget the -s option, it is stand for simulator, if you omit it, it will give you errors.)
90+
```
91+
92+
In this way, you can only build one arch a time, if you want to build a fat library, please use `build_xxx.sh` instead.(xxx is the library name, we will follow this conversion throughout this document.)
93+
94+
If you use `build_xxx.sh` to build static libraries, all the generated `header files` and `.a files` are under the folder named as `xxx`.
95+
96+
Let's give png as an example, after you run `./build_png.sh`, it will generate a folder named `png`:
97+
98+
The folder structure would be:
99+
100+
```
101+
-png
102+
--include(this folder contains the exported header files)
103+
- prebuilt(this folder contains the fat library)
104+
```
105+
106+
All the other libraries share the same folder structure.
107+
108+
### For Android Platform
109+
For building libpng with armeabi, armeabi-v7a and x86 arch, you can do it like this:
110+
111+
```cpp
112+
cd build/android
113+
./build_png.sh
114+
```
115+
Or you can also use `build.sh` script build each static library for different arch.
116+
The usage would be:
117+
118+
```cpp
119+
-k <sdk> Use the specified Android API level (default: android-19)
120+
-a <arch> Use the specified arch (default: armeabi-v7a)
121+
-n <version> Use the gcc version(default: 4.8)
122+
-l <libname> Use the specified library name
123+
EOF
124+
```
125+
126+
If you want to build a `curl` library with `armeabi` arch support, you can do it like this:
127+
128+
```cpp
129+
cd build/android
130+
./build.sh -a armeabi -l curl
131+
```
132+
133+
### For Mac
134+
For building libpng x86_64 arch library:
135+
136+
```cpp
137+
cd build/mac
138+
./build_png.sh
139+
```
140+
### For Tizen
141+
For building libpng armv7 arch library:
142+
143+
```cpp
144+
cd build/tizen
145+
./build_png.sh
146+
```
147+
148+
### For Linux
149+
xxx After testing these scripts on Linux, document will be update.
150+
151+
## How to build a DEBUG and RELEASE version
152+
xxx we need to improve the script to add debug and release options.
153+
154+
## How to do build clean?
155+
If you use `./build_xxx.sh` to build static libraries, there is no need to do clean. After generating the static library, script will delete the intermediate files.
156+
157+
If you use `./build.sh` manually, you should delete the folders generated in src folder.
158+
159+
## How to upgrade a existing library
160+
If you find a 3rd party library has some critical bug fix, you might need to update it.
161+
You can following the [README](./contrib/src/README) file to do this job.
162+

build/android/build.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ info()
1010
}
1111

1212
# TODO: You must set your ANDROID_NDK path in .bash_profile
13-
source ~/.bash_profile
13+
# source ~/.bash_profile
1414
ANDROID_ABI="armeabi-v7a"
1515
ANDROID_API="android-19"
1616
ANDROID_GCC_VERSION=4.8
1717
ANDROID_ARCH=arm
1818

1919
# TODO: configure to compile specify 3rd party libraries
20-
OPTIONS="
21-
--enable-lua
22-
--enable-freetype2
23-
--enable-png
24-
--enable-zlib
25-
"
20+
OPTIONS=""
2621

2722
usage()
2823
{
@@ -75,6 +70,13 @@ do
7570
esac
7671
done
7772

73+
if test -z "$OPTIONS"
74+
then
75+
echo "You must specify a OPTIONS parameter."
76+
usage
77+
exit 1
78+
fi
79+
7880
if [ "${ANDROID_ABI}" != "x86" ] && [ "${ANDROID_ABI}" != "armeabi-v7a" ] && [ "${ANDROID_ABI}" != "armeabi" ]; then
7981
echo "You must specify the right Android Arch within {armeabi, armeabi-v7a, x86}"
8082
exit 1
@@ -111,8 +113,11 @@ cocos_root=`pwd`/../..
111113

112114
export ANDROID_ABI
113115
export ANDROID_API
114-
# export LDFLAGS="-L${ANDROID_NDK}/platforms/${ANDROID_API}/arch-${ANDROID_ARCH}/usr/lib"
115-
# info "LD FLAGS SELECTED = '${LDFLAGS}'"
116+
117+
if [ "$ANDROID_ABI" = "armeabi-v7a" ]; then
118+
export LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
119+
fi
120+
info "LD FLAGS SELECTED = '${LDFLAGS}'"
116121

117122
export PATH="${toolchain_bin}:${cocos_root}/extras/tools/bin:$PATH"
118123
if [ "$ANDROID_ABI" = "armeabi-v7a" ]; then

build/android/build_without_export.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
set -e
3+
set -x
4+
5+
info()
6+
{
7+
local green="\033[1;32m"
8+
local normal="\033[0m"
9+
echo "[${green}build${normal}] $1"
10+
}
11+
12+
# TODO: You must set your ANDROID_NDK path in .bash_profile
13+
# source ~/.bash_profile
14+
ANDROID_ABI="armeabi-v7a"
15+
ANDROID_API="android-19"
16+
ANDROID_GCC_VERSION=4.8
17+
ANDROID_ARCH=arm
18+
19+
# TODO: configure to compile specify 3rd party libraries
20+
OPTIONS=""
21+
22+
usage()
23+
{
24+
cat << EOF
25+
usage: $0 [options]
26+
Build cocos2d-x 3rd party libraries for Android
27+
OPTIONS:
28+
-h Show some help
29+
-q Be quiet
30+
-k <sdk> Use the specified Android API level (default: $ANDROID_API)
31+
-a <arch> Use the specified arch (default: $ANDROID_ABI)
32+
-n <version> Use the gcc version(default: $ANDROID_GCC_VERSION)
33+
-l <libname> Use the specified library name
34+
EOF
35+
}
36+
37+
spushd()
38+
{
39+
pushd "$1" > /dev/null
40+
}
41+
42+
spopd()
43+
{
44+
popd > /dev/null
45+
}
46+
47+
while getopts "hvk:a:l:" OPTION
48+
do
49+
case $OPTION in
50+
h)
51+
usage
52+
exit 1
53+
;;
54+
q)
55+
set +x
56+
QUIET="yes"
57+
;;
58+
a)
59+
ANDROID_ABI=$OPTARG
60+
;;
61+
k)
62+
ANDROID_API=$OPTARG
63+
;;
64+
n)
65+
ANDROID_GCC_VERSION=$OPTARG
66+
;;
67+
l)
68+
OPTIONS=--enable-$OPTARG
69+
;;
70+
esac
71+
done
72+
73+
if test -z "$OPTIONS"
74+
then
75+
echo "You must specify a OPTIONS parameter."
76+
usage
77+
exit 1
78+
fi
79+
80+
if [ "${ANDROID_ABI}" != "x86" ] && [ "${ANDROID_ABI}" != "armeabi-v7a" ] && [ "${ANDROID_ABI}" != "armeabi" ]; then
81+
echo "You must specify the right Android Arch within {armeabi, armeabi-v7a, x86}"
82+
exit 1
83+
fi
84+
85+
86+
# FIXME: we need a way to determine the toolchina address automatically
87+
toolchain_bin=
88+
89+
if [ "${ANDROID_ABI}" = "x86" ]; then
90+
TARGET="i686-linux-android"
91+
toolchain_bin=${ANDROID_NDK}/toolchains/x86-${ANDROID_GCC_VERSION}/prebuilt/darwin-x86_64/bin
92+
ANDROID_ARCH=x86
93+
else
94+
TARGET="arm-linux-androideabi"
95+
toolchain_bin=${ANDROID_NDK}/toolchains/${TARGET}-${ANDROID_GCC_VERSION}/prebuilt/darwin-x86_64/bin
96+
fi
97+
98+
shift $(($OPTIND - 1))
99+
if [ "x$1" != "x" ]; then
100+
usage
101+
exit 1
102+
fi
103+
#
104+
# Various initialization
105+
#
106+
out="/dev/stdout"
107+
if [ "$QUIET" = "yes" ]; then
108+
out="/dev/null"
109+
fi
110+
111+
info "Building 3rd party libraries for the Android"
112+
cocos_root=`pwd`/../..
113+
114+
export ANDROID_ABI
115+
export ANDROID_API
116+
# export LDFLAGS="-L${ANDROID_NDK}/platforms/${ANDROID_API}/arch-${ANDROID_ARCH}/usr/lib"
117+
# info "LD FLAGS SELECTED = '${LDFLAGS}'"
118+
119+
export PATH="${toolchain_bin}:${cocos_root}/extras/tools/bin:$PATH"
120+
if [ "$ANDROID_ABI" = "armeabi-v7a" ]; then
121+
CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security "
122+
elif [ "$ANDROID_ABI" = "armeabi" ]; then
123+
CFLAGS="-ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
124+
else
125+
CFLAGS="-ffunction-sections -funwind-tables -fstack-protector -fPIC -no-canonical-prefixes -O2 -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
126+
fi
127+
128+
info "CFLAGS is ${CFLAGS}"
129+
130+
#
131+
# build 3rd party libraries
132+
#
133+
info "Building static libraries"
134+
spushd "${cocos_root}/contrib"
135+
mkdir -p "Android-${ANDROID_ABI}" && cd "Android-${ANDROID_ABI}"
136+
137+
138+
../bootstrap ${OPTIONS} \
139+
--host=${TARGET} \
140+
--prefix=${cocos_root}/contrib/${TARGET}-${ANDROID_ABI}> $out
141+
142+
echo "ANDROID_ARCH := ${CFLAGS}" >> config.mak
143+
144+
#
145+
# make
146+
#
147+
make fetch
148+
make list
149+
make

build/ios/build.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ SDK_MIN=6.0
1010
ARCH=armv7
1111

1212
# TODO: configure to compile speficy 3rd party libraries
13-
OPTIONS="
14-
--enable-lua
15-
--enable-freetype2
16-
--enable-png
17-
"
13+
OPTIONS=""
1814

1915

2016
usage()
@@ -77,6 +73,13 @@ do
7773
esac
7874
done
7975

76+
if test -z "$OPTIONS"
77+
then
78+
echo "You must specify a OPTIONS parameter."
79+
usage
80+
exit 1
81+
fi
82+
8083
shift $(($OPTIND - 1))
8184

8285

0 commit comments

Comments
 (0)