diff --git a/lzma/BUILD.gn b/lzma/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c60230fbc253183ca416d6642b14f13af705f0b8 --- /dev/null +++ b/lzma/BUILD.gn @@ -0,0 +1,208 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +declare_args() { + enable_lzma_test = false +} + +config("liblzma_config") { + include_dirs = [ + "./adapted", + "./lzma", + "./lzma/src", + "./lzma/src/liblzmadec", + ] + + cflags = [ + "-fPIC", + "-Wall", + "-Wextra", + "-fexceptions", + "-DHAVE_CONFIG_H", + "-DCOMPRESS_MF_BT", + "-DCOMPRESS_MF_BT4", + "-DCOMPRESS_MF_HC", + "-D_LZMA_IN_CB", + "-D_LZMA_OUT_READ", + "-D_LZMA_SYSTEM_SIZE_T", + "-D_LZMA_PROB32", + "-Wno-error=unused-parameter", + "-Wno-error=int-conversion", + "-Wno-error=format", + ] +} + +ohos_shared_library("lzma_shared") { + sources = [ + "./lzma/src/liblzmadec/main.c", + "./lzma/src/liblzmadec/buffer.c", + "./lzma/src/liblzmadec/io.c", + ] + + configs = [ + ":liblzma_config" + ] + + deps = [ + ] + + part_name = "lzma" +} + +config ("lzma_config") { + include_dirs = [ + "./adapted", + "./lzma/", + "./lzma/src", + "./lzma/src/liblzmadec", + "./lzma/src/lzma", + "./lzma/src/lzmadec", + "./lzma/src/lzmainfo", + "./lzma/src/sdk", + "./lzma/src/sdk/7zip", + "./lzma/src/sdk/7zip/Common", + "./lzma/src/sdk/Common", + "./lzma/src/sdk/7zip/Compress/LZMA/", + "./lzma/src/sdk/7zip/Compress/LZ/", + "./lzma/src/sdk/7zip/Compress/RangeCoder/", + ] + + cflags_cc = [ + "-fPIC", + "-Wall", + "-Wextra", + "-fexceptions", + "-DHAVE_CONFIG_H", + "-DHAVE_ERRNO_H", + "-DCOMPRESS_MF_BT", + "-DCOMPRESS_MF_BT4", + "-DCOMPRESS_MF_HC", + "-D_LZMA_IN_CB", + "-D_LZMA_OUT_READ", + "-D_LZMA_SYSTEM_SIZE_T", + "-D_LZMA_PROB32", + "-Wno-error=unused-parameter", + "-Wno-error=unused-variable", + "-Wno-error=sign-compare", + "-Wno-error=undef", + "-Wno-error=macro-redefined", + "-Wno-error=int-conversion", + "-Wno-error=format", + "-Wno-error=logical-op-parentheses", + "-Wno-error=parentheses", + ] + + cflags = [ + "-fPIC", + "-Wall", + "-Wextra", + "-fexceptions", + "-DHAVE_CONFIG_H", + "-DHAVE_ERRNO_H", + "-DCOMPRESS_MF_BT", + "-DCOMPRESS_MF_BT4", + "-DCOMPRESS_MF_HC", + "-D_LZMA_IN_CB", + "-D_LZMA_OUT_READ", + "-D_LZMA_SYSTEM_SIZE_T", + "-D_LZMA_PROB32", + "-Wno-error=unused-parameter", + "-Wno-error=unused-variable", + "-Wno-error=sign-compare", + "-Wno-error=undef", + "-Wno-error=macro-redefined", + "-Wno-error=int-conversion", + "-Wno-error=format", + ] +} + +ohos_executable("lzma") { + sources = [ + "./lzma/src/lzma/lzmp.cpp", + "./lzma/src/sdk/Common/C_FileIO.cpp", + "./lzma/src/sdk/Common/CRC.cpp", + "./lzma/src/sdk/Common/Alloc.cpp", + "./lzma/src/sdk/7zip/Common/FileStreams.cpp", + "./lzma/src/sdk/7zip/Common/InBuffer.cpp", + "./lzma/src/sdk/7zip/Common/OutBuffer.cpp", + "./lzma/src/sdk/7zip/Compress/LZMA/LZMAEncoder.cpp", + "./lzma/src/sdk/7zip/Compress/LZMA/LZMADecoder.h", + "./lzma/src/sdk/7zip/Compress/LZMA/LZMADecoder.cpp", + "./lzma/src/sdk/7zip/Compress/LZ/LZInWindow.cpp", + "./lzma/src/sdk/7zip/Compress/RangeCoder/RangeCoderBit.cpp", + "./lzma/src/sdk/7zip/Common/StreamUtils.cpp", + "./lzma/src/sdk/7zip/Compress/LZ/LZOutWindow.cpp", + ] + + public_configs = [ ":lzma_config" ] + + deps = [ + "//third_party/lzma:lzma_shared", + ] + + defines = [ + "PACKAGE_VERSION", + ] + + part_name = "lzma" +} + +ohos_executable("lzmadec") { + sources = [ + "./lzma/src/lzmadec/lzmadec.c" + ] + + public_configs = [ ":lzma_config" ] + + deps = [ + "//third_party/lzma:lzma_shared", + ] + + defines = [ + "PACKAGE_VERSION", + ] + + part_name = "lzma" +} + +ohos_executable("lzmainfo") { + sources = [ + "./lzma/src/lzmainfo/lzmainfo.c" + ] + + public_configs = [ ":lzma_config" ] + + deps = [ + "//third_party/lzma:lzma_shared", + ] + + defines = [ + "PACKAGE_VERSION", + ] + + part_name = "lzma" +} + +group("samples") { + if (enable_lzma_test) { + deps = [ + ":lzma", + ":lzmadec", + ":lzmainfo", + ] + } else { + deps = [] + } +} diff --git a/lzma/README.OpenSource b/lzma/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..a1d320edf91febaf0bf70fb8791e5ff7221f87a3 --- /dev/null +++ b/lzma/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "lzma", + "License": "GNU LGPLv2+", + "License File": "COPYRIGHT", + "Version Number": "4.32.7", + "Owner": "caiqi14@huawei.com", + "Upstream URL": "https://tukaani.org/lzma/", + "Description": "LZMA utils is a traditional data compression software with high compression ratio. LZMA utils uses the LZMA format." + } +] \ No newline at end of file diff --git a/lzma/README_zh.md b/lzma/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..af18c2225e06f1abbbc0a311af24ba2068d31456 --- /dev/null +++ b/lzma/README_zh.md @@ -0,0 +1,10 @@ +# lzma 三方库说明 +## 功能简介 +LZMA(Lempel-Ziv-Markov chain-Algorithm的缩写)是2001年以来得到发展的一个数据压缩算法,它是一种高压缩比的传统数据压缩软件。 +## 使用约束 +- ROM版本:OpenHarmony3.2 Beta1 +- 三方库版本:4.32.7 +- 当前适配的功能:完成了 .lzma 格式文件的压缩、解压缩 +- [License : LGPLv2+](https://tukaani.org/lzma/) +## 集成方式 ++ [系统Rom包集成](docs/rom_integrate.md) \ No newline at end of file diff --git a/lzma/adapted/config.h b/lzma/adapted/config.h new file mode 100644 index 0000000000000000000000000000000000000000..74e8fa1b58f6281259b81292f0684d060a3595c0 --- /dev/null +++ b/lzma/adapted/config.h @@ -0,0 +1,192 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't. + */ +#define HAVE_DECL_GETENV 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `futimes' function. */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the `futimesat' function. */ +#define HAVE_FUTIMESAT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long_only' function. */ +#define HAVE_GETOPT_LONG_ONLY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if stdbool.h conforms to C99. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strrchr' function. */ +#define HAVE_STRRCHR 1 + +/* Define to 1 if you have the `strtol' function. */ +#define HAVE_STRTOL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +#define HAVE_UTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if the system has the type `_Bool'. */ +#define HAVE__BOOL 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Define to disable debugging code. */ +#define NDEBUG 1 + +/* Name of package */ +#define PACKAGE "lzma" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "lasse.collin@tukaani.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "LZMA" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "LZMA 4.32.7" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "lzma" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "4.32.7" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Version number of package */ +#define VERSION "4.32.7" + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to rpl_ if the getopt replacement functions and variables should be + used. */ +/* #undef __GETOPT_PREFIX */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `int16_t' if or does not define it. */ +/* #undef int_fast16_t */ + +/* Define to `int32_t' if or does not define it. */ +/* #undef int_fast32_t */ + +/* Define to `int64_t' if or does not define it. */ +/* #undef int_fast64_t */ + +/* Define to `int8_t' if or does not define it. */ +/* #undef int_fast8_t */ + +/* Define to `int' if does not define. */ +/* #undef mode_t */ + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define to `uint16_t' if or does not define it. */ +/* #undef uint_fast16_t */ + +/* Define to `uint32_t' if or does not define it. */ +/* #undef uint_fast32_t */ + +/* Define to `uint64_t' if or does not define it. */ +/* #undef uint_fast64_t */ + +/* Define to `uint8_t' if or does not define it. */ +/* #undef uint_fast8_t */ diff --git a/lzma/bundle.json b/lzma/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..0c1bf6b7660976a00d15ada5d3e87f9d5d9261b8 --- /dev/null +++ b/lzma/bundle.json @@ -0,0 +1,33 @@ +{ + "name": "@ohos/lzma", + "description": "LZMA utils is a traditional data compression software with high compression ratio. LZMA utils uses the LZMA format.", + "version": "3.2", + "license": "GNU LGPLv2+", + "publishAs": "code-segment", + "segment": { + "destPath": "third_party/lzma" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "lzma", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": ["//third_party/lzma:lzma_shared","//third_party/lzma:samples"], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/lzma/docs/pic/results.png b/lzma/docs/pic/results.png new file mode 100644 index 0000000000000000000000000000000000000000..3daf46bbe228d0e38ffc2dd4690b838ad21c7b8d Binary files /dev/null and b/lzma/docs/pic/results.png differ diff --git a/lzma/docs/rom_integrate.md b/lzma/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..721e910fe580863a1aa7880d2096e2b598c9ba85 --- /dev/null +++ b/lzma/docs/rom_integrate.md @@ -0,0 +1,112 @@ +# lzma如何集成到系统Rom +## 准备源码工程 +本库是基于OpenHarmony-v3.2-Beta1版本,在润和RK3568开发板上验证的。如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 准备系统Rom源码 +源码获取方法请参照:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta1/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md#%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96) +## 增加构建脚本及配置文件 +- 下载本仓库代码 + ``` + cd ~/ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/lzma + |-- adapted # 存放三方库适配需要的代码文件 + |-- docs # 存放三方库相关文档的文件夹 + |-- BUILD.gn # 构建脚本,支持rom包集成 + |-- bundle.json # 三方库组件定义文件 + ├── README.OpenSource # 说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将本仓库文件夹拷贝到third_party下 + ``` + cp ~/tpc_c_cplusplus/lzma ~/openharmony/third_party/ -rf + ``` +## 准备三方库源码 +- 将源码下载到lzma目录并将其解压出来。 +``` +cd ~/openharmony/third_party/lzma # 进入到lzma目录 +wget https://tukaani.org/lzma/lzma-4.32.7.tar.gz # 下载三方库 +tar -zxf lzma-4.32.7.tar.gz # 解压三方库 +mv lzma-4.32.7 lzma # 修改库外层文件夹名称 +``` +## 系统Rom中引入三方库 +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md)。 +我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +在OpenHarmony源码的vendor/hihope/rk3568/config.json文件中,新增需要编译的组件,如下: +``` +{ + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "lzma", + "features": [] + } + ] +} +``` +## 系统Rom中引入三方库测试程序 +在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项,如下: +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "lzma", + "features": ["enable_lzma_test=true"] + } + ] + } +``` +## 编译工程 +在OpenHarmony源码根目录下 +``` +cd ~/openharmony +``` +- 选择产品 +``` +hb set # 该命令会列出所有可选平台,这里我们选择rk3568 +``` +- 运行编译 +``` +hb build --target-cpu arm64 # 编译64位系统使用:arm64, 编译32位系统使用:arm +``` +- 生成文件的路径,可执行文件和库文件都在out/rk3568/thirdparty/lzma目录下,同时也打包到了镜像中 +## 安装应用程序 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 + ``` + hb set # 源码根目录下使用hb set 选择产品ohos-sdk + hb build # 然后编译,编译出来在out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 将原生库测试需要的所有文件打包成lzma.tar,并拷贝到windows下 +- 将文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -o remount,rw / # 修改系统权限为可读写 + hdc_std file send lzma.tar / # 将文件包推入开发板 + hdc_std shell # 进入开发板 + tar xvf lzma.tar # 解压 + cd lzma # 进入lzma目录 + mv liblzma_shared.z.so /system/lib64/ # 64位系统需要将库文件拷贝到系统lib64目录, 32位系统则是lib目录 + ``` +## 运行效果 +程序安装完后,我们通过运行如下命令测试了该库常用的.lzma文件压缩和解压缩功能,并和期望结果做对比,内容一致,总体运行结果如图: + + ![results](pic/results.png) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta1/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md#%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md)