Skip to content

Commit 2701de5

Browse files
Merge pull request #17 from andyque/testScripts
Improve the build scripts
2 parents f458d66 + 1a7bbe6 commit 2701de5

File tree

6 files changed

+98
-61
lines changed

6 files changed

+98
-61
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository includes the source code of the 3rd party libraries (binary) tha
55

66
This repository is needed for cocos2d-x developers and/or people who want to:
77

8-
* generate a updated version of a certain library (eg: upgrade libpng 1.2.2 to 1.2.14)
8+
* generate a updated version of a certain library (eg: upgrade libpng 1.6.2 to 1.6.14)
99
* port cocos2d-x to other platforms (eg: port it to Android ARM64, or Xbox One, etc)
1010
* generate DEBUG versions of all the 3rd party library
1111

@@ -66,7 +66,7 @@ pacman -S mingw-w64-i686-toolchain
6666
```
6767

6868
## How to use
69-
We have one build script for each platform, they are under `build/platform{ios/mac/android/tizen}` directory.
69+
We have one build script for each platform, they are under `build` directory.
7070

7171
All of them share the same usage:
7272

@@ -81,15 +81,15 @@ All of them share the same usage:
8181
- use comma separated library names, for example, `png,lua,jpeg,webp`, no space between the comma.
8282

8383
- param2:
84-
- use `all` to build all the supported arches. For iOS, they are "armv7, arm64, i386, x86_64", for Android, they are "armeabi, armeabi-v7a, x86, arm64", for Mac, they are "x86_64", for Tizen, they are "armv7"
84+
- use `all` to build all the supported arches. For iOS, they are "armv7, arm64, i386, x86_64", for Android, they are "arm,armv7,arm64,x86", for Mac, they are "x86_64", for Tizen, they are "armv7"
8585
- use comma separated arch name, for example, `armv7, arm64`, no space between the comma.
8686

8787
- param3:
8888
- release: Build library on release mode. This is the default option. We use `-O3 -DNDEBUG` flags to build release library.
8989
- debug: Build library on debug mode. we use `-O0 -g -DDEBUG` flag to build debug library.
9090

9191
- list:
92-
- Use these option to list all the supported libraries.
92+
- Use these option to list all the supported library names and versions.
9393

9494
### Build png on iOS platform
9595
For building libpng fat library with all arch x86_64, i386, armv7, arm64 on release mode:
@@ -126,15 +126,17 @@ cd build
126126

127127
3. Pass `--arch=64` to build the libraries with arm64 support.
128128

129-
130-
For other platforms and other libraries, it is more or less the same way except for some minor changes in `--arch` parameter and `-p` parameter.
129+
Note:
130+
If you build `webp` with arm64, you will get `cpu-features.h` header file not found error. This is a known issue of Android NDK r10c. You could simply create a empty header file
131+
named `cpu-features.h` under `{ANDROID_NDK}/platforms/android-21/arch-arm64/usr/include`.
131132

132133

133134
## How to build a DEBUG and RELEASE version
134135
You can add flag "--mode=[debug | release]" for building DEBUG and RELEASE version.
135136

136137
## How to do build clean?
137-
If you use `./build.sh` to build static libraries, there is no need to do clean. After generating the static library, script will delete the intermediate files.
138+
You could simply turn on the flag `cfg_is_cleanup_after_build` to "yes" in `main.ini` file.
139+
After each build, you could also delete the generated folders under `contrib` directory.
138140

139141

140142
## How to upgrade a existing library

build/android.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ cfg_default_build_arches="all"
44
cfg_default_build_mode="release"
55
cfg_default_build_libraries="all"
66
#specific default values
7-
cfg_default_build_api=19
8-
cfg_default_gcc_version=4.8
7+
cfg_default_build_api=21
8+
cfg_default_gcc_version=4.9
9+
cfg_arm_alias_folder_name="armeabi"
10+
cfg_armv7_alias_folder_name="armeabi-v7a"
11+
cfg_arm64_alias_folder_name="armeabi-v8a"
12+
913

1014
#help message strings goes here
1115
cfg_help_arch_string="arm,armv7,x86,arm64"

build/build.sh

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -270,27 +270,27 @@ function set_build_mode_cflags()
270270
for lib in "${build_library[@]}"
271271
do
272272
library_name=$lib
273-
archive_name=$lib
274273

275-
# parser_lib_archive_alias=${lib}_archive_alias
276-
# archive_name=${!parser_lib_archive_alias}
277-
278-
if [ $lib = "zlib" ]; then
279-
archive_name=z
280-
fi
281-
282-
if [ $lib = "openssl" ];then
283-
archive_name=ssl
274+
parser_lib_archive_alias=${lib}_archive_alias
275+
archive_name=${!parser_lib_archive_alias}
276+
if [ -z $archive_name ];then
277+
archive_name=$lib
284278
fi
285279

286280
mkdir -p $cfg_platform_name/$archive_name/include/
287281

288282
for arch in "${build_arches[@]}"
289283
do
290-
#skip certain arch libraries
291-
#because luajit doesn't support arm64!
292-
if [ $lib = "luajit" ] && [ $arch = "arm64" ]; then
293-
continue
284+
#skip build libraries with certain arch
285+
ignore_arch_library=${lib}_ignore_arch_list
286+
ignore_arch_list=(${!ignore_arch_library})
287+
ignore_arch_list_array=(${ignore_arch_list//,/ })
288+
if [ ! -z ${ignore_arch_list} ]; then
289+
echo ${ignore_arch_list}
290+
if [ $(contains "${ignore_arch_list_array[@]}" $arch) == "y" ];then
291+
echo "ingore $lib for $arch"
292+
continue
293+
fi
294294
fi
295295

296296
#set build mode flags -- debug or release
@@ -302,7 +302,13 @@ do
302302

303303
echo "build $arch for $lib in $cfg_platform_name"
304304

305-
MY_TARGET_ARCH=$arch
305+
parse_arch_folder_name=cfg_${arch}_alias_folder_name
306+
original_arch_name=${!parse_arch_folder_name}
307+
if [ -z $original_arch_name ];then
308+
original_arch_name=$arch
309+
fi
310+
311+
MY_TARGET_ARCH=$original_arch_name
306312
export MY_TARGET_ARCH
307313

308314
if [ ${cfg_is_cross_compile} = "yes" ];then
@@ -338,42 +344,46 @@ do
338344
--host=${!my_target_host} \
339345
--prefix=${PREFIX}
340346

341-
make fetch
342-
make list
343-
make
344347

345348
echo "MY_TARGET_ARCH := ${MY_TARGET_ARCH}" >> config.mak
346349
echo "OPTIM := ${OPTIM}" >> config.mak
350+
351+
make
347352

348353
cd -
349354

350-
local_library_install_path=$cfg_platform_name/$archive_name/prebuilt/$arch
355+
local_library_install_path=$cfg_platform_name/$archive_name/prebuilt/$original_arch_name
351356
if [ ! -d $local_library_install_path ]; then
352357
echo "create folder for library with specify arch. $local_library_install_path"
353358
mkdir -p $local_library_install_path
354359
fi
355360

356-
cp $top_dir/contrib/$install_library_path/$arch/lib/lib$archive_name.a $local_library_install_path/lib$archive_name.a
357-
cp $top_dir/contrib/$install_library_path/$arch/lib/lib$archive_name*.a $local_library_install_path/lib$archive_name.a
361+
#determine the .a achive name with a specified libraries
362+
parse_original_lib_name=${lib}_original_name
363+
original_archive_name=${!parse_original_lib_name}
364+
if [ -z $original_archive_name ];then
365+
original_archive_name=$archive_name
366+
fi
358367

368+
#copy .a archive from install-platform folder
369+
cp $top_dir/contrib/$install_library_path/$arch/lib/lib$original_archive_name.a $local_library_install_path/lib$archive_name.a
359370

360-
if [ $lib = "curl" ]; then
361-
local_library_install_path=$cfg_platform_name/ssl/prebuilt/$arch
362-
mkdir -p $local_library_install_path
363-
cp $top_dir/contrib/$install_library_path/$arch/lib/libssl.a $local_library_install_path/libssl.a
371+
#copy dependent .a archive
372+
parse_dependent_archive_list=${lib}_dependent_archive_list
373+
original_dependent_archive_list=${!parse_dependent_archive_list}
374+
if [ ! -z $original_dependent_archive_list ];then
375+
echo "copying dependent archives..."
376+
original_dependent_archive_list=(${original_dependent_archive_list//,/ })
364377

365-
local_library_install_path=$cfg_platform_name/crypto/prebuilt/$arch
366-
mkdir -p $local_library_install_path
367-
cp $top_dir/contrib/$install_library_path/$arch/lib/libcrypto.a $local_library_install_path/libcrypto.a
378+
for dep_archive in ${original_dependent_archive_list[@]}
379+
do
380+
local_library_install_path=$cfg_platform_name/${dep_archive}/prebuilt/$original_arch_name
381+
mkdir -p $local_library_install_path
382+
cp $top_dir/contrib/$install_library_path/$arch/lib/lib${dep_archive}.a $local_library_install_path/lib${dep_archive}.a
368383

384+
done
369385
fi
370386

371-
if [ $lib = "png" ] || [ $lib = "freetype" ] || [ $lib = "websockets" ] || [ $lib = "curl" ]; then
372-
echo "copying libz..."
373-
local_install_path=$cfg_platform_name/z/prebuilt/$arch
374-
mkdir -p $local_install_path
375-
cp $top_dir/contrib/$install_library_path/$arch/lib/libz.a $local_install_path/libz.a
376-
fi
377387

378388
echo "Copying needed heder files"
379389
copy_include_file_path=${lib}_header_files
@@ -392,13 +402,16 @@ do
392402

393403
create_fat_library $archive_name
394404

395-
if [ $lib = "curl" ]; then
396-
create_fat_library ssl
397-
create_fat_library crypto
398-
fi
405+
parse_dependent_archive_list=${lib}_dependent_archive_list
406+
original_dependent_archive_list=${!parse_dependent_archive_list}
407+
if [ ! -z $original_dependent_archive_list ];then
408+
echo "create fat library for dependent archives..."
409+
original_dependent_archive_list=(${original_dependent_archive_list//,/ })
399410

400-
if [ $lib = "png" ] || [ $lib = "curl" ] || [ $lib = "freetype" ] || [ $lib = "websockets" ]; then
401-
create_fat_library z
411+
for dep_archive in ${original_dependent_archive_list[@]}
412+
do
413+
create_fat_library $dep_archive
414+
done
402415
fi
403416
fi
404417

build/main.ini

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,41 @@
22
# xxx_header_files
33
cfg_all_valid_platforms=(ios mac android linux win32 tizen)
44

5+
#copy libraries header files
56
png_header_files=png*.h
6-
luajit_header_files=luajit-2.0/
7+
luajit_header_files=luajit-2.0
78
lua_header_files=l*.h*
8-
curl_header_files=curl/
9-
freetyp2_header_files=freetype2/
9+
curl_header_files=curl
10+
freetype_header_files=freetype2
1011
jpeg_header_files=j*.h
1112
tiff_header_files=tif*.h
12-
webp_header_files=webp/
13+
webp_header_files=webp
1314
websockets_header_files=libwebsockets.h
1415
zlib_header_files=z*.h
16+
chipmunk_header_files=chipmunk
17+
18+
19+
##archive prebuilt name
20+
luajit_original_name=luajit-5.1
1521

1622
##archive_alias
1723
zlib_archive_alias=z
18-
freetype2_archive_alias=freetype
24+
openssl_archive_alias=ssl
25+
26+
##copy dpendent archives
27+
png_dependent_archive_list=z
28+
freetype_dependent_archive_list=z
29+
websockets_dependent_archive_list=z
30+
curl_dependent_archive_list=z,ssl,crypto
31+
32+
33+
##ignore arch list for specify libraries
34+
#because luajit doesn't support arm64!
35+
#luajit_ignore_arch_list=armv7,armv7s,arm64
36+
luajit_ignore_arch_list=arm64
1937

2038
#clean up flag
21-
cfg_is_cleanup_after_build=yes
39+
cfg_is_cleanup_after_build=no
2240

2341
##valide options
2442
cfg_valid_build_mode=(release debug)

contrib/bootstrap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ check_android_sdk()
227227
## FIXME: the android toolchain path is hardcoded, only MACOSX will work.
228228
if [ ${ANDROID_ABI} = "x86" ]; then
229229
toolchain_path_prefix=x86
230-
elif [ ${ANDROID_ABI} = "arm64" ];then
230+
elif [ ${ANDROID_ABI} = "armeabi-v8a" ];then
231231
toolchain_path_prefix=aarch64-linux-android
232232
else
233233
toolchain_path_prefix=arm-linux-androideabi
234234
fi
235235

236236
# check whether sysroot is exists
237-
if [ $ANDROID_ABI = "arm64" ]; then
237+
if [ $ANDROID_ABI = "armeabi-v8a" ]; then
238238
if [ ! -d ${ANDROID_NDK}/platforms/${ANDROID_API}/arch-arm64 ];then
239239
echo "${ANDROID_NDK} ${ANDROID_API} doesn't support build arm64 architecture!"
240240
exit $?
@@ -248,19 +248,19 @@ check_android_sdk()
248248
fi
249249

250250

251-
if [ ${ANDROID_ABI} = "armv7" ]; then
251+
if [ ${ANDROID_ABI} = "armeabi-v7a" ]; then
252252
add_make_enabled "HAVE_NEON"
253253
add_make_enabled "HAVE_ARMV7A"
254254
add_make "EXTRA_CFLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat "
255255
add_make "EXTRA_LDFLAGS := -march=armv7-a -Wl,--fix-cortex-a8"
256256
fi
257257

258-
if [ ${ANDROID_ABI} = "arm" -a -z "${NO_ARMV6}" ];then
258+
if [ ${ANDROID_ABI} = "armeabi" -a -z "${NO_ARMV6}" ];then
259259
add_make_enabled "HAVE_ARMV6"
260260
add_make "EXTRA_CFLAGS := -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat "
261261
fi
262262

263-
if [ ${ANDROID_ABI} = "arm64" ]; then
263+
if [ ${ANDROID_ABI} = "armeabi-v8a" ]; then
264264
add_make_enabled "HAVE_NEON"
265265
add_make_enabled "HAVE_ARMV8A"
266266
add_make "EXTRA_CFLAGS := -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes"

contrib/src/luajit/rules.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif
3838

3939
.luajit: luajit
4040
ifdef HAVE_ANDROID
41-
cd $< && $(MAKE) HOST_CC="gcc -m32 $(OPTIM)" CROSS=$(HOST)- TARGET_SYS=Linux TARGET_FLAGS="${MY_TARGET_ARCH} ${NDKF}" TARGET_LDFLAGS=$(LUAJIT_LDFLAGS)
41+
cd $< && $(MAKE) HOST_CC="gcc -m32 $(OPTIM)" CROSS=$(HOST)- TARGET_SYS=Linux TARGET_FLAGS="${NDKF} ${EXTRA_CFLAGS}" TARGET_LDFLAGS=$(LUAJIT_LDFLAGS)
4242
endif
4343
ifdef HAVE_MACOSX
4444
cd $< && $(HOSTVARS_PIC) $(MAKE) HOST_CC="$(CC)" HOST_CFLAGS="$(CFLAGS)"

0 commit comments

Comments
 (0)