啃论文俱乐部——移植speexdsp到OpenHarmony标准系统② 原创 精华

离北况归
发布于 2022-9-2 14:04
浏览
2收藏
  • 大家好!我来自南京,在OpenHarmony成长计划啃论文俱乐部,与华为、软通动力、润和软件、拓维信息、深开鸿等公司一起,学习和研究操作系统技术
    从今年1月11日加入OpenHarmony俱乐部已经有接近8个月时间了。笔者一直在思考啃论文给我带来了些什么,通过啃论文能为OpenHarmony做些什么。笔者利用大二升大三暑假两个月时间移植了Speexdsp这个三方库到OpenHarmony标准系统,而关于前面的问题我似乎找到了答案,现将啃论文和三方库移植分享经验如下:

由于想要分享的内容较多,为避免读者姥爷们失去看下去的耐心,分享将以连载的方式进行。

往期回顾啃论文俱乐部——移植speexdsp到OpenHarmony标准系统①
本期为移植speexdsp到OpenHarmony标准系统的第②期,主要内容如下:

目录

啃论文俱乐部——移植speexdsp到OpenHarmony标准系统②-鸿蒙开发者社区


在linux上生成speexdsp的so动态链接库和.a静态链接库

  • make和make install后会生成speexdsp的.so动态链接库和.a静态链接库
make
make install
  • 1.
  • 2.

啃论文俱乐部——移植speexdsp到OpenHarmony标准系统②-鸿蒙开发者社区

其中build/lib目录下:

├── libspeexdsp.a                              /*静态库*/
├── libspeexdsp.la                             /*记录同名动态库和静态库相关信息的la文本文件*/
├── libspeexdsp.so -> libspeexdsp.so.1.5.2  
├── libspeexdsp.so.1 -> libspeexdsp.so.1.5.2   /*符号链接*/
├── libspeexdsp.so.1.5.2                       /*动态库*/
└── pkgconfig                                  /*pkgconfig 的 *.pc文件*/
    └── speexdsp.pc
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

linux下的so、o、lo、a、la文件

  • o: 编译的目标文件
  • a: 静态库,其实就是把若干o文件打了个包
  • so: 动态链接库(共享库) 动态库文件必须以lib开头,以.so结尾
  • lo: 使用libtool编译出的目标文件,其实就是在o文件中添加了一些信息
  • la: 使用libtool编译出的库文件,其实是个文本文件,记录同名动态库和静态库的相关信息

知识拓展

  • 函数库分为静态库*a动态库*.so两种:
    ①静态库在程序编译时会被连接到目标代码中,程序运行时将不再需要该静态库。
    ②动态库在程序编译时并不会被连接到目标代码中,而是在程序运行是才被载入,因此在程序运行时还需要动态库存在。

  • 符号链接(symbolic link)是 Linux 系统中的一种文件,它指向系统中的另一个文件或目录。符号链接类似于 Windows 系统中的快捷方式。

  • 在linux中,*.la是记录同名动态库和静态库相关信息的文本文件。

三、分析speexdsp在标准Linux系统的编译过程文件

  • 分析speexdsp在标准Linux系统的编译过程文件,找到生成so库和测试用的可执行文件所需的.c源代码,头文件路径,cflags编译器标志,所依赖的库。

对比编译前后的speexdsp原生库结构

  • tree工具能以树形的方式显示指定目录的层级结构。
    非绿色字体是编译后生成的文件。

├── acinclude.m4\color {#0F0} {acinclude.m4}
├── AUTHORS\color {#0F0} {AUTHORS} #speexdsp项目作者信息
├── autogen.sh\color {#0F0} {autogen.sh} #autogen.sh脚本配置文件
├── aclocal.m4 #运行aclocal后生成的aclocal.m4文件和一个缓冲文件夹autom4te.cache
├── autom4te.cache
│   ├── output.0
│   ├── output.1
│   ├── output.2
│   ├── requests
│   ├── traces.0
│   ├── traces.1
│   └── traces.2
├── build
│   ├── include
│   │   └── speex
│   │   ├── speexdsp_config_types.h
│   │   ├── speexdsp_types.h
│   │   ├── speex_echo.h
│   │   ├── speex_jitter.h
│   │   ├── speex_preprocess.h
│   │   └── speex_resampler.h
│   ├── lib
│   │   ├── libspeexdsp.a
│   │   ├── libspeexdsp.la
│   │   ├── libspeexdsp.so -> libspeexdsp.so.1.5.2
│   │   ├── libspeexdsp.so.1 -> libspeexdsp.so.1.5.2
│   │   ├── libspeexdsp.so.1.5.2
│   │   └── pkgconfig
│   │   └── speexdsp.pc
│   └── share
│   └── doc
│   └── speexdsp
│   └── manual.pdf
├── ChangeLog\color {#0F0} {ChangeLog}#spexxds原生库更新日志(和本次移植无关信息)
├── compile\color {#0F0} {compile}
├── config.guess\color {#0F0} {config.guess}#这个是在构建环境上运行的一个脚本,它用来猜测构建机的配置环境,因为这个脚本是在构建机上运行,所以它可以动态执行uname等命令来获得构建机的环境,所以我们一般不要指定这个变量,从而让脚本自动获得。
├── config.h#Config.h是自动生成的头文件,是根据配置文件Config.h.in生成的。config.h主要用于代码移植,产生可移植代码。
├── config.h.in#autoheader后形成config.h.in
├── config.log#该文件在执行configure文件时动态生成,包含了一些行号信息,表示一个文件在哪一行执行,以及执行的什么命令,因此可以知道测试是在哪个位置中完成。
├── config.status\color {#0F0} {config.status}#这是脚本文件,运行该脚本可以生成一个当前相同的配置,从而避免再次执行configure这个比较庞大的代码。也就是config.log生成的是文本文件,而config.status生成的则是命令脚本文件。
├── config.sub\color {#0F0} {config.sub}#这个是将host target build变量正则化的一个脚本,它的sub就是substitute的缩写。因为用户提供的build可能并不符合脚本正规的四元组或者三元组的结构,所以这个脚本将它转换为标准的格式,从而可以进行格式化处理。
├── configure\color {#0F0} {configure}#这个是我们需要监测环境的主要入口文件,使用该文件可以生成Makefile文件,它会替换Makefile中需要替换的变量。
├── configure.ac\color {#0F0} {configure.ac}#该文件为autoconfigure文件使用的一个文件,该文件用来生成configure文件,这个文件一般是开发者维护,我们安装该软件的时候只需要执行configure就可以,这个configure.ac我们一般不用理会
├── COPYING\color {#0F0} {COPYING}
├── depcomp\color {#0F0} {depcomp}#automake --add-missing命令生成install-sh, missing, depcomp文件
├── doc\color {#0F0} {doc}
│   ├── celpdecoder.eps\color {#0F0} {celp_decoder.eps}
│   ├── celpdecoder.odg\color {#0F0} {celp_decoder.odg}
│   ├── components.eps\color {#0F0} {components.eps}
│   ├── components.odg\color {#0F0} {components.odg}
│   ├── echopath.eps\color {#0F0} {echo_path.eps}
│   ├── echopath.odg\color {#0F0} {echo_path.odg}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── manual.lyx\color {#0F0} {manual.lyx}
│   ├── manual.pdf\color {#0F0} {manual.pdf}
│   ├── programming.html\color {#0F0} {programming.html}
│   ├── refshaping.eps\color {#0F0} {ref_shaping.eps}
│   ├── sampledec.c\color {#0F0} {sampledec.c}
│   ├── sampleenc.c\color {#0F0} {sampleenc.c}
│   ├── speexabs.eps\color {#0F0} {speex_abs.eps}
│   ├── speexabs.odg\color {#0F0} {speex_abs.odg}
│   ├── speexanalysis.eps\color {#0F0} {speex_analysis.eps}
│   └── speexanalysis.odg\color {#0F0} {speex_analysis.odg}
├── Doxyfile\color {#0F0} {Doxyfile}
├── html\color {#0F0} {html}
│   ├── speex.png\color {#0F0} {speex.png}
│   ├── speex.webprj\color {#0F0} {speex.webprj}
│   └── speex.xcf\color {#0F0} {speex.xcf}
├── include\color {#0F0} {include}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   └── speex\color {#0F0} {speex}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── speexbuffer.h\color {#0F0} {speex_buffer.h}
│   ├── speexdsp_config_types.h
│   ├── speexdspconfigtypes.h.in\color {#0F0} {speexdsp_config_types.h.in}
│   ├── speexdsptypes.h\color {#0F0} {speexdsp_types.h}
│   ├── speexecho.h\color {#0F0} {speex_echo.h}
│   ├── speexjitter.h\color {#0F0} {speex_jitter.h}
│   ├── speexpreprocess.h\color {#0F0} {speex_preprocess.h}
│   └── speexresampler.h\color {#0F0} {speex_resampler.h}
├── INSTALL\color {#0F0} {INSTALL}
├── installsh\color {#0F0} {install-sh}#automake --add-missing命令生成install-sh, missing, depcomp文件
├── libspeexdsp\color {#0F0} {libspeexdsp}
│   ├── arch.h\color {#0F0} {arch.h}
│   ├── bfin.h\color {#0F0} {bfin.h}
│   ├── buffer.c\color {#0F0} {buffer.c}
│   ├── buffer.lo
│   ├── buffer.o
│   ├── echodiagnostic.m\color {#0F0} {echo_diagnostic.m}
│   ├── fftwrap.c\color {#0F0} {fftwrap.c}
│   ├── fftwrap.h\color {#0F0} {fftwrap.h}
│   ├── fftwrap.lo
│   ├── fftwrap.o
│   ├── filterbank.c\color {#0F0} {filterbank.c}
│   ├── filterbank.h\color {#0F0} {filterbank.h}
│   ├── filterbank.lo
│   ├── filterbank.o
│   ├── fixedarm4.h\color {#0F0} {fixed_arm4.h}
│   ├── fixedarm5e.h\color {#0F0} {fixed_arm5e.h}
│   ├── fixedbfin.h\color {#0F0} {fixed_bfin.h}
│   ├── fixeddebug.h\color {#0F0} {fixed_debug.h}
│   ├── fixedgeneric.h\color {#0F0} {fixed_generic.h}
│   ├── jitter.c\color {#0F0} {jitter.c}
│   ├── jitter.lo
│   ├── jitter.o
│   ├── kissfft.c\color {#0F0} {kiss_fft.c}
│   ├── kissfftguts.h\color {#0F0} {_kiss_fft_guts.h}
│   ├── kissfft.h\color {#0F0} {kiss_fft.h}
│   ├── kissfftr.c\color {#0F0} {kiss_fftr.c}
│   ├── kissfftr.h\color {#0F0} {kiss_fftr.h}
│   ├── libspeexdsp.la
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── mathapprox.h\color {#0F0} {math_approx.h}
│   ├── mdf.c\color {#0F0} {mdf.c}
│   ├── mdf.lo
│   ├── mdf.o
│   ├── miscbfin.h\color {#0F0} {misc_bfin.h}
│   ├── ossupport.h\color {#0F0} {os_support.h}
│   ├── preprocess.c\color {#0F0} {preprocess.c}
│   ├── preprocess.lo
│   ├── preprocess.o
│   ├── pseudofloat.h\color {#0F0} {pseudofloat.h}
│   ├── resample.c\color {#0F0} {resample.c}
│   ├── resample.lo
│   ├── resampleneon.h\color {#0F0} {resample_neon.h}
│   ├── resample.o
│   ├── resamplesse.h\color {#0F0} {resample_sse.h}
│   ├── scal.c\color {#0F0} {scal.c}
│   ├── scal.lo
│   ├── scal.o
│   ├── smallft.c\color {#0F0} {smallft.c}
│   ├── smallft.h\color {#0F0} {smallft.h}
│   ├── smallft.lo
│   ├── smallft.o
│   ├── testdenoise\color {#0F0} {testdenoise}
│   ├── testdenoise.c\color {#0F0} {testdenoise.c} #测试噪音抑制的文件
│   ├── testdenoise.o
│   ├── testecho\color {#0F0} {testecho}
│   ├── testecho.c\color {#0F0} {testecho.c} #测试声学回音消除的文件
│   ├── testecho.o
│   ├── testjitter\color {#0F0} {testjitter} # 测试抖动的文件
│   ├── testjitter.c\color {#0F0} {testjitter.c}
│   ├── testjitter.o
│   ├── testresample\color {#0F0} {testresample}
│   ├── testresample2\color {#0F0} {testresample2}
│   ├── testresample2.c\color {#0F0} {testresample2.c}#测试重采样的文件
│   ├── testresample2.o
│   ├── testresample.c\color {#0F0} {testresample.c}#测试重采样的文件
│   ├── testresample.o
│   └── vorbispsy.h\color {#0F0} {vorbis_psy.h}
├── libtool\color {#0F0} {libtool}
├── ltmain.sh
├── m4
│   ├── libtool.m4
│   ├── lt~obsolete.m4
│   ├── ltoptions.m4
│   ├── ltsugar.m4
│   └── ltversion.m4
├── macosx\color {#0F0} {macosx}
│   ├── English.lproj\color {#0F0} {English.lproj}
│   │   └── InfoPlist.strings\color {#0F0} {InfoPlist.strings}
│   ├── Info.plist\color {#0F0} {Info.plist}
│   ├── SpeexPrefix.pch\color {#0F0} {Speex_Prefix.pch}
│   ├── SpeexUB.xcodeproj\color {#0F0} {Speex_UB.xcodeproj}
│   │   └── project.pbxproj\color {#0F0} {project.pbxproj}
│   └── Speex.xcodeproj\color {#0F0} {Speex.xcodeproj}
│   └── project.pbxproj\color {#0F0} {project.pbxproj}
├── Makefile
├── Makefile.am\color {#0F0} {Makefile.am}
├── Makefile.in
├── missing\color {#0F0} {missing}#automake --add-missing命令生成install-sh, missing, depcomp文件
├── NEWS\color {#0F0} {NEWS}
├── README\color {#0F0} {README}
├── README.blackfin\color {#0F0} {README.blackfin}#汇聚式处理器Blackfin是由ADI和Intel公司联合开发的微信号架构(MSA)
├── README.Trimedia\color {#0F0} {README.Trimedia}#Trimedia 是由Philips公司1996年推出的新一代媒体处理器(Media Processor)芯片。
├── README.win32\color {#0F0} {README.win32}#Win32是指Microsoft Windows操作系统的32位环境
├── regressionfixes\color {#0F0} {regression-fixes}
│   └── 1resamplerunsignedfix.patch\color {#0F0} {1-resampler_unsigned_fix.patch}
├── regressions\color {#0F0} {regressions}
├── SpeexDSP.kdevelop\color {#0F0} {SpeexDSP.kdevelop}
├── speexdsp.pc
├── speexdsp.pc.in\color {#0F0} {speexdsp.pc.in}
├── SpeexDSP.spec
├── SpeexDSP.spec.in\color {#0F0} {SpeexDSP.spec.in}
├── stamp-h1
├── symbian\color {#0F0} {symbian}
│   ├── bld.inf\color {#0F0} {bld.inf}
│   ├── config.h\color {#0F0} {config.h}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   └── speex.mmp\color {#0F0} {speex.mmp}
├── ti\color {#0F0} {ti}#TI公司DSP芯片
│   ├── config.h\color {#0F0} {config.h}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── ossupportcustom.h\color {#0F0} {os_support_custom.h}
│   ├── speexC54test\color {#0F0} {speex_C54_test}
│   │   ├── Makefile
│   │   ├── Makefile.am\color {#0F0} {Makefile.am}
│   │   ├── Makefile.in
│   │   ├── speexC54test.cmd\color {#0F0} {speex_C54_test.cmd}
│   │   └── speexC54test.pjt\color {#0F0} {speex_C54_test.pjt}
│   ├── speexC55test\color {#0F0} {speex_C55_test}
│   │   ├── Makefile
│   │   ├── Makefile.am\color {#0F0} {Makefile.am}
│   │   ├── Makefile.in
│   │   ├── speexC55test.cmd\color {#0F0} {speex_C55_test.cmd}
│   │   └── speexC55test.pjt\color {#0F0} {speex_C55_test.pjt}
│   └── speexC64test\color {#0F0} {speex_C64_test}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── speexC64test.cmd\color {#0F0} {speex_C64_test.cmd}
│   └── speexC64test.pjt\color {#0F0} {speex_C64_test.pjt}
├── tmv\color {#0F0} {tmv}
│   ├── config.h\color {#0F0} {config.h}
│   ├── fftwraptm.h\color {#0F0} {fftwrap_tm.h}
│   ├── filterbanktm.h\color {#0F0} {filterbank_tm.h}
│   ├── fixedtm.h\color {#0F0} {fixed_tm.h}
│   ├── kissfftgutstm.h\color {#0F0} {_kiss_fft_guts_tm.h}
│   ├── kissfftrtm.h\color {#0F0} {kiss_fftr_tm.h}
│   ├── kissffttm.h\color {#0F0} {kiss_fft_tm.h}
│   ├── mdftm.h\color {#0F0} {mdf_tm.h}
│   ├── misctm.h\color {#0F0} {misc_tm.h}
│   ├── preprocesstm.h\color {#0F0} {preprocess_tm.h}
│   ├── profiletm.h\color {#0F0} {profile_tm.h}
│   └── speexconfigtypes.h\color {#0F0} {speex_config_types.h}
├── TODO\color {#0F0} {TODO}
└── win32\color {#0F0} {win32}
├── config.h\color {#0F0} {config.h}
├── libspeexdsp\color {#0F0} {libspeexdsp}
│   ├── libspeexdsp.dsp\color {#0F0} {libspeexdsp.dsp}
│   ├── libspeexdsp.dsw\color {#0F0} {libspeexdsp.dsw}
│   ├── libspeexdspdynamic.dsp\color {#0F0} {libspeexdsp_dynamic.dsp}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   └── Makefile.in
├── libspeexdsp.def\color {#0F0} {libspeexdsp.def}
├── Makefile
├── Makefile.am\color {#0F0} {Makefile.am}
├── Makefile.in
├── speex.iss\color {#0F0} {speex.iss}
├── VS2003\color {#0F0} {VS2003}
│   ├── libspeexdsp\color {#0F0} {libspeexdsp}
│   │   ├── libspeexdsp.vcproj\color {#0F0} {libspeexdsp.vcproj}
│   │   ├── Makefile
│   │   ├── Makefile.am\color {#0F0} {Makefile.am}
│   │   └── Makefile.in
│   ├── libspeexdsp.sln\color {#0F0} {libspeexdsp.sln}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   └── tests\color {#0F0} {tests}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── testdenoise.vcproj\color {#0F0} {testdenoise.vcproj}
│   ├── testecho.vcproj\color {#0F0} {testecho.vcproj}
│   └── testresample.vcproj\color {#0F0} {testresample.vcproj}
├── VS2005\color {#0F0} {VS2005}
│   ├── libspeexdsp\color {#0F0} {libspeexdsp}
│   │   ├── libspeexdsp.vcproj\color {#0F0} {libspeexdsp.vcproj}
│   │   ├── Makefile
│   │   ├── Makefile.am\color {#0F0} {Makefile.am}
│   │   └── Makefile.in
│   ├── libspeexdsp.sln\color {#0F0} {libspeexdsp.sln}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   └── tests\color {#0F0} {tests}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   ├── Makefile.in
│   ├── testdenoise.vcproj\color {#0F0} {testdenoise.vcproj}
│   ├── testecho.vcproj\color {#0F0} {testecho.vcproj}
│   └── testresample.vcproj\color {#0F0} {testresample.vcproj}
└── VS2008\color {#0F0} {VS2008}
├── libspeexdsp\color {#0F0} {libspeexdsp}
│   ├── libspeexdsp.vcproj\color {#0F0} {libspeexdsp.vcproj}
│   ├── Makefile
│   ├── Makefile.am\color {#0F0} {Makefile.am}
│   └── Makefile.in
├── libspeexdsp.sln\color {#0F0} {libspeexdsp.sln}
├── Makefile
├── Makefile.am\color {#0F0} {Makefile.am}
├── Makefile.in
└── tests\color {#0F0} {tests}
├── Makefile
├── Makefile.am\color {#0F0} {Makefile.am}
├── Makefile.in
├── testdenoise.vcproj\color {#0F0} {testdenoise.vcproj}
├── testecho.vcproj\color {#0F0} {testecho.vcproj}
└── testresample.vcproj\color {#0F0} {testresample.vcproj}

分析原生库下make.am文件

  • make.am是一种比Makefile文件抽象程序更高的编译规则文件。 在里面可以指定生成目录,编译用的源码,编译的时候依赖哪些库,要安装到什么目录。

原生库根目录下的make.am如下

## Process this file with automake to produce Makefile.in. -*-Makefile-*-

# To disable automatic dependency tracking if using other tools than
# gcc and gmake, add the option 'no-dependencies'
AUTOMAKE_OPTIONS = 1.8
ACLOCAL_AMFLAGS = -I m4

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = speexdsp.pc

EXTRA_DIST = SpeexDSP.spec SpeexDSP.spec.in SpeexDSP.kdevelop speexdsp.pc.in README.blackfin

#Fools KDevelop into including all files
SUBDIRS = libspeexdsp include doc win32 symbian ti   

DIST_SUBDIRS = libspeexdsp include doc win32 symbian ti

rpm: dist
	rpmbuild -ta ${PACKAGE}-${VERSION}.tar.gz
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

父目录需要包含子目录,在父目录下的Makefile.am中需要添加: SUBDIRS = 子目录。可知speexdsp子目录为libspeexdsp include doc win32 symbian ti 。再逐步查看各个文件夹源码可知只有libspeexdsp include文件夹与本次移植有关。所以接下来查看libspeexdsp目录下的make.am文件

子目录libspeexdsp下的make.am

# Disable automatic dependency tracking if using other tools than gcc and gmake
#AUTOMAKE_OPTIONS = no-dependencies

EXTRA_DIST=echo_diagnostic.m

AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include/speex -I$(top_builddir) @FFT_CFLAGS@
/*top_srcdir工程最顶层目录*/
/*top_builddir定义生成目标文件的最上层目录*/

lib_LTLIBRARIES = libspeexdsp.la

# Sources for compilation in the library
if BUILD_KISS_FFT
  FFTSRC=kiss_fft.c _kiss_fft_guts.h kiss_fft.h kiss_fftr.c kiss_fftr.h 
else
if BUILD_SMALLFT
  FFTSRC=smallft.c
else
  FFTSRC=
endif
endif

libspeexdsp_la_SOURCES = preprocess.c jitter.c mdf.c fftwrap.c filterbank.c resample.c buffer.c 
scal.c $(FFTSRC)/*编译libspeexdsp.so需要preprocess.c jitter.c mdf.c fftwrap.c filterbank.c resample.c 
buffer.c scal.c、smallft.c源文件(特别需要注意$(FFTSRC)的存在,因为FFTSRC=smallft.c)*/

/*noinst_HEADERS:这个表示该头文件只是参加可执行文件的编译,而不用安装到安装目录下
。如果需要安装到系统中,可以用 include_HEADERS来代替。*/
noinst_HEADERS = 	arch.h 	bfin.h \
		fixed_arm4.h \
		fixed_arm5e.h 	fixed_bfin.h 	fixed_debug.h 	\
		math_approx.h 		misc_bfin.h 	\
		fftwrap.h \
	filterbank.h fixed_generic.h os_support.h \
	pseudofloat.h smallft.h vorbis_psy.h resample_sse.h resample_neon.h

libspeexdsp_la_LDFLAGS = -no-undefined -version-info/*LDFLAGS:编译时的选项*/ @SPEEXDSP_LT_CURRENT@:@SPEEXDSP_LT_REVISION@:@SPEEXDSP_LT_AGE@
libspeexdsp_la_LIBADD = $(LIBM)

if BUILD_EXAMPLES /*编译测试文件*/ 
noinst_PROGRAMS = testdenoise testecho testjitter testresample testresample2
testdenoise_SOURCES = testdenoise.c
testdenoise_LDADD = libspeexdsp.la@FFT_LIBS@ /*链接需要libspeexdsp.la库文件*/
testecho_SOURCES = testecho.c /*需要的
testecho_LDADD = libspeexdsp.la @FFT_LIBS@ /*链接需要libspeexdsp.la库文件*/
testjitter_SOURCES = testjitter.c
testjitter_LDADD = libspeexdsp.la @FFT_LIBS@ /*链接需要libspeexdsp.la库文件*/
testresample_SOURCES = testresample.c
testresample_LDADD = libspeexdsp.la @FFT_LIBS@ @LIBM@ /*链接需要libspeexdsp.la库文件*/
testresample2_SOURCES = testresample2.c
testresample2_LDADD = libspeexdsp.la @FFT_LIBS@ @LIBM@ /*链接需要libspeexdsp.la库文件*/
endif
  • 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.

通过分析libspeexdsp下的make.am可以知道:

  • 编译出so库需要的.c源文件有preprocess.c jitter.c mdf.c fftwrap.c filterbank.c resample.c
    buffer.c scal.c、smallft.c
  • 编译出so库需要的.h源文件有arch.h bfin.h fixed_arm4.h fixed_arm5e.h fixed_bfin.h fixed_debug.h math_approx.h misc_bfin.h fftwrap.h filterbank.h fixed_generic.h os_support.h pseudofloat.h smallft.h vorbis_psy.h resample_sse.h resample_neon.h
  • 编译出测试用的testdenoise testecho testjitter testresample testresample2可执行文件需要的.c源文件有testdenoise.c testec.c hotestjitter.c testresample.c testresample2.c

分析原生库下Makefile文件

Makefile里有什么?Makefile里主要包含了五个东西:显式规则、隐晦规则、变量定义、文件指示和注释。

  • 显式规则。显式规则说明了如何生成一个或多个目标文件。这是由Makefile的书写者明显指出要生成的文件、文件的依赖文件和生成的命令。
  • 隐晦规则。由于我们的make有自动推导的功能,所以隐晦的规则可以让我们比较简略地书写 Makefile,这是由make所支持的。
  • 变量的定义。在Makefile中我们要定义一系列的变量,变量一般都是字符串,这个有点像你C语言中的宏,当Makefile被执行时,其中的变量都会被扩展到相应的引用位置上。
  • 文件指示。其包括了三个部分,一个是在一个Makefile中引用另一个Makefile,就像C语言中的include一样;另一个是指根据某些情况指定Makefile中的有效部分,就像C语言中的预编译#if一样;还有就是定义一个多行的命令。有关这一部分的内容,我会在后续的部分中讲述。
  • 注释。Makefile中只有行注释,和UNIX的Shell脚本一样,其注释是用 # 字符,这个就像C/C++中的 // 一样。如果你要在你的Makefile中使用 # 字符,可以用反斜杠进行转义,如: # 。

笔者在speexdsp根目录下的makefile(最基本的Makefile)文件中
搜索关键字CFLAGS找到CFLAGS = -g -O2 -fvisibility=hidden这条语句
啃论文俱乐部——移植speexdsp到OpenHarmony标准系统②-鸿蒙开发者社区

分析“make”过程log

以下是执行make命令后在终端显示的部分log,通过分析也可以知道编译so库需要的.c文件均位于libspeexdsp目录。

jiajiahao@ubuntu:~/Desktop/speexdsp-SpeexDSP-1.2.1$ make
make  all-recursive
make[1]: 进入目录“/home/jiajiahao/Desktop/speexdsp-SpeexDSP-1.2.1”
Making all in libspeexdsp
make[2]: 进入目录“/home/jiajiahao/Desktop/speexdsp-SpeexDSP-1.2.1/libspeexdsp”
  CC       preprocess.lo
  CC       jitter.lo
  CC       mdf.lo
  CC       fftwrap.lo
  CC       filterbank.lo
  CC       resample.lo
  CC       buffer.lo
  CC       scal.lo
  CC       smallft.lo
  CCLD     libspeexdsp.la
make[2]: 离开目录“/home/jiajiahao/Desktop/speexdsp-SpeexDSP-1.2.1/libspeexdsp”
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

分析build安装目录下生成的.pc文件

下图为build/lib/pkgconfig目录的speexdsp.pc文件
啃论文俱乐部——移植speexdsp到OpenHarmony标准系统②-鸿蒙开发者社区

*.pc文件的所有参数:
Name: 该模块的名字,比如你的pc名字是xxxx.pc,那么名字最好也是xxxx。
Description: 模块的简单描述。上文pkg-config –list-all命令出来的结果,每个名字后面就是description。
URL: 用户可以通过该URL获得更多信息,或者下载信息。也是辅助的,可要可不要。
Version: 版本号。
Requires: 该模块有木有依赖于其他模块。一般没有。
Requires.private: 该模块有木有依赖于其他模块,并且还不需要第三方知道的。一般也没有。
Conflicts: 有没有和别的模块冲突。常用于版本冲突。比如,Conflicts: bar < 1.2.3,表示和bar模块的1.2.3以下的版本有冲突。
Cflags: 这个就很重要了。pkg-config的参数–cflags就指向这里。主要用于写本模块的头文件的路径。
Libs: 也很重要,pkg-config的参数–libs就指向这里。主要用于写本模块的库/依赖库的路径。
Libs.private: 本模块依赖的库,但不需要第三方知道。

在文件中的第14行中清楚的指出speexdsp依赖-lm这个库。

分析运行configure命令后生成的config.log

啃论文俱乐部——移植speexdsp到OpenHarmony标准系统②-鸿蒙开发者社区

从中也可以分析出speexdsp依赖的库-lm 和编译器需要添加的C_FLAGS标记-g -O2 -fvisibility=hidden

configure:9932: checking for cos in -lm
configure:9957: gcc -o conftest -g -O2 -fvisibility=hidden   conftest.c -lm   >&5
  • 1.
  • 2.

结论

  • speexdsp依赖的库为-lm
  • 编译出speexdsp动态链接库需要的.c源文件为preprocess.c jitter.c mdf.c fftwrap.c filterbank.c resample.c buffer.c scal.c、smallft.c。
  • 编译出speexdsp动态链接库需要的.h源文件目录为libspeexdsp
  • 编译出测试用的testdenoise testecho testjitter testresample testresample2可执行文件需要的.c源文件有testdenoise.c testec.c hotestjitter.c testresample.c testresample2.c
  • 编译出测试用的testdenoise testecho testjitter testresample testresample2可执行文件需要的.h源文件目录为根目录下include
  • 编译时需要添加的cflags编译器标志为-o -g -O2 -fvisibility=hidden

下期分享内容:将三方库加入到OpenHarmony的编译体系

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-9-2 14:04:41修改
8
收藏 2
回复
举报
8
5
2
5条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

虽然做好了大佬高产的准备,没想到这么快

1
回复
2022-9-2 14:54:17
只看看不说话
只看看不说话

纯干货,必须支持

回复
2022-9-2 17:57:38
离北况归
离北况归 回复了 红叶亦知秋
虽然做好了大佬高产的准备,没想到这么快

还有很多,在整理ing

回复
2022-9-2 21:39:30
红叶亦知秋
红叶亦知秋 回复了 离北况归
还有很多,在整理ing

期待ing

已于2022-9-5 11:07:13修改
回复
2022-9-5 11:07:04
离北况归
离北况归
回复
2022-9-23 00:16:53


回复
    相关推荐
    这个用户很懒,还没有个人简介
    觉得TA不错?点个关注精彩不错过
    帖子
    视频
    声望
    粉丝
    最近发布
    社区精华内容