Skip to content

Commit 1fce9ee

Browse files
committed
refactor some hardcoded values
1 parent 0351604 commit 1fce9ee

File tree

3 files changed

+66
-44
lines changed

3 files changed

+66
-44
lines changed

README.md

Lines changed: 4 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 libraries 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:
@@ -127,9 +127,6 @@ cd build
127127
3. Pass `--arch=64` to build the libraries with arm64 support.
128128

129129

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.
131-
132-
133130
## How to build a DEBUG and RELEASE version
134131
You can add flag "--mode=[debug | release]" for building DEBUG and RELEASE version.
135132

build/build.sh

Lines changed: 43 additions & 35 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
@@ -353,27 +353,32 @@ do
353353
mkdir -p $local_library_install_path
354354
fi
355355

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
356+
#determine the .a achive name with a specified libraries
357+
parse_original_lib_name=${lib}_original_name
358+
original_archive_name=${!parse_original_lib_name}
359+
if [ -z $original_archive_name ];then
360+
original_archive_name=$archive_name
361+
fi
358362

363+
#copy .a archive from install-platform folder
364+
cp $top_dir/contrib/$install_library_path/$arch/lib/lib$original_archive_name.a $local_library_install_path/lib$archive_name.a
359365

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
366+
#copy dependent .a archive
367+
parse_dependent_archive_list=${lib}_dependent_archive_list
368+
original_dependent_archive_list=${!parse_dependent_archive_list}
369+
if [ ! -z $original_dependent_archive_list ];then
370+
echo "copying dependent archives..."
371+
original_dependent_archive_list=(${original_dependent_archive_list//,/ })
364372

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
373+
for dep_archive in ${original_dependent_archive_list[@]}
374+
do
375+
local_library_install_path=$cfg_platform_name/${dep_archive}/prebuilt/$arch
376+
mkdir -p $local_library_install_path
377+
cp $top_dir/contrib/$install_library_path/$arch/lib/lib${dep_archive}.a $local_library_install_path/lib${dep_archive}.a
368378

379+
done
369380
fi
370381

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
377382

378383
echo "Copying needed heder files"
379384
copy_include_file_path=${lib}_header_files
@@ -392,13 +397,16 @@ do
392397

393398
create_fat_library $archive_name
394399

395-
if [ $lib = "curl" ]; then
396-
create_fat_library ssl
397-
create_fat_library crypto
398-
fi
400+
parse_dependent_archive_list=${lib}_dependent_archive_list
401+
original_dependent_archive_list=${!parse_dependent_archive_list}
402+
if [ ! -z $original_dependent_archive_list ];then
403+
echo "create fat library for dependent archives..."
404+
original_dependent_archive_list=(${original_dependent_archive_list//,/ })
399405

400-
if [ $lib = "png" ] || [ $lib = "curl" ] || [ $lib = "freetype" ] || [ $lib = "websockets" ]; then
401-
create_fat_library z
406+
for dep_archive in ${original_dependent_archive_list[@]}
407+
do
408+
create_fat_library $dep_archive
409+
done
402410
fi
403411
fi
404412

build/main.ini

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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
67
luajit_header_files=luajit-2.0/
78
lua_header_files=l*.h*
@@ -13,12 +14,28 @@ webp_header_files=webp/
1314
websockets_header_files=libwebsockets.h
1415
zlib_header_files=z*.h
1516

17+
18+
##archive prebuilt name
19+
luajit_original_name=luajit-5.1
20+
1621
##archive_alias
1722
zlib_archive_alias=z
18-
freetype2_archive_alias=freetype
23+
openssl_archive_alias=ssl
24+
25+
##copy dpendent archives
26+
png_dependent_archive_list=z
27+
freetype_dependent_archive_list=z
28+
websockets_dependent_archive_list=z
29+
curl_dependent_archive_list=z,ssl,crypto
30+
31+
32+
##ignore arch list for specify libraries
33+
#because luajit doesn't support arm64!
34+
#luajit_ignore_arch_list=armv7,armv7s,arm64
35+
luajit_ignore_arch_list=arm64
1936

2037
#clean up flag
21-
cfg_is_cleanup_after_build=yes
38+
cfg_is_cleanup_after_build=no
2239

2340
##valide options
2441
cfg_valid_build_mode=(release debug)

0 commit comments

Comments
 (0)