赞
踩
1.介绍
ALSA是Advanced Linux Sound Architecture的缩写,高级linux声音架构的简称,它在Linux操作系统上提供了音频和MIDI的支持。在2.6系列内核之后,ALSA已经成为默认的声音子系统,用来替代2.4系列内核中的oss。关于alsa的提出和设计的目的,大家可以自行百度下。本文主要讲解alsa上层提供的调试工具alsa-utils-1.1.5和alsa-lib-1.1.5。alsa官网:https://www.alsa-project.org/
平台:ubuntu 16.04
alsa版本:alsa-utils-1.1.5 alsa-lib-1.1.5
2.编译
(1)whereis:查看文件的位置 用法:whereis [-bmsu] 文件或者目录名称
参数说明:
-b :只找二进制文件
-m:只找在说明文件manual路劲下的文件
-s:只找source源文件
-u:没有说明文档的文件
(2)locate:配合数据库查看文件位置 用法:locate 文件或者目录名称
(3) which 查看可执行文件的位置 用法:which可执行文件名称
(4)type:用来区分某个命令到底是shell自带的,还是由shell外部的独立二进制文件提供的
(5)type命令的使用实例:
$type cd
系统会提示,cd是shell的自带命令(build-in)。
$type grep
系统会提示,grep 是一个外部命令,并显示该命令的路劲。
$type -p grep
加上-p 参数后,就相当于which命令。
2.1linux下用的编译脚本
Linux环境下,安装软件并不是一件容易的事情;如果通过源代码编译后在安装,当然事情就更为复杂一些;现在安装各种软件的教程都非常普通;但万变不离其宗,对基础知识的扎实掌握,安装各种软件的问题就迎刃而解。Configure脚本配置工具就是基础之一,它是autoconf的工具的基本应用。
2.2configure介绍
Configure它是个shell脚本,主要用于编译安装源代码库和软件。./configure是源代码安装的第一步,主要的作用:
首先可以在自己的ubuntu系统下载的软件包下面运行,./configure --help就可以查看所有的配置选项。笔者这里以alsa-lib-1.1.5的源码库为例来说明。
- ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ ./configure --help
- `configure' configures alsa-lib 1.1.5 to adapt to many kinds of systems.
- Usage: ./configure [OPTION]... [VAR=VALUE]...
- To assign environment variables (e.g., CC, CFLAGS...), specify them as
- VAR=VALUE. See below for descriptions of some of the useful variables.
- Defaults for the options are specified in brackets.
- Configuration:
- -h, --help display this help and exit
- --help=short display options specific to this package
- --help=recursive display the short help of all the included packages
- -V, --version display version information and exit
- -q, --quiet, --silent do not print `checking ...' messages
- --cache-file=FILE cache test results in FILE [disabled]
- -C, --config-cache alias for `--cache-file=config.cache'
- -n, --no-create do not create output files
- --srcdir=DIR find the sources in DIR [configure dir or `..']
-
- Installation directories:
- --prefix=PREFIX install architecture-independent files in PREFIX
- [/usr]
- --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
- [PREFIX]
-
- By default, `make install' will install all the files in
- `/usr/bin', `/usr/lib' etc. You can specify
- an installation prefix other than `/usr' using `--prefix',
- for instance `--prefix=$HOME'.
-
- For better control, use the options below.
-
- Fine tuning of the installation directories:
- --bindir=DIR user executables [EPREFIX/bin]
- --sbindir=DIR system admin executables [EPREFIX/sbin]
- --libexecdir=DIR program executables [EPREFIX/libexec]
- --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
- --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
- --localstatedir=DIR modifiable single-machine data [PREFIX/var]
- --libdir=DIR object code libraries [EPREFIX/lib]
- --includedir=DIR C header files [PREFIX/include]
- --oldincludedir=DIR C header files for non-gcc [/usr/include]
- --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
- --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
- --infodir=DIR info documentation [DATAROOTDIR/info]
- --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
- --mandir=DIR man documentation [DATAROOTDIR/man]
- --docdir=DIR documentation root [DATAROOTDIR/doc/alsa-lib]
- --htmldir=DIR html documentation [DOCDIR]
- --dvidir=DIR dvi documentation [DOCDIR]
- --pdfdir=DIR pdf documentation [DOCDIR]
- --psdir=DIR ps documentation [DOCDIR]
-
- Program names:
- --program-prefix=PREFIX prepend PREFIX to installed program names
- --program-suffix=SUFFIX append SUFFIX to installed program names
- --program-transform-name=PROGRAM run sed PROGRAM on installed program names
-
- System types:
- --build=BUILD configure for building on BUILD [guessed]
- --host=HOST cross-compile to build programs to run on HOST [BUILD]
-
- Optional Features:
- --disable-option-checking ignore unrecognized --enable/--with options
- --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
- --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
- --disable-maintainer-mode
- disable make rules and dependencies not useful (and
- sometimes confusing) to the casual installer
- --enable-silent-rules less verbose build output (undo: "make V=1")
- --disable-silent-rules verbose build output (undo: "make V=0")
- --enable-dependency-tracking
- do not reject slow dependency extractors
- --disable-dependency-tracking
- speeds up one-time build
- --enable-static[=PKGS] build static libraries [default=no]
- --enable-shared[=PKGS] build shared libraries [default=yes]
- --enable-fast-install[=PKGS]
- optimize for fast installation [default=yes]
- --disable-libtool-lock avoid locking (might break parallel builds)
- --enable-symbolic-functions
- use -Bsymbolic-functions option if available
- (optmization for size and speed)
- --enable-debug enable assert call at the default error message
- handler
- --enable-resmgr support resmgr (optional)
- --disable-aload disable reading /dev/aload*
- --disable-mixer disable the mixer component
- --disable-pcm disable the PCM component
- --disable-rawmidi disable the raw MIDI component
- --disable-hwdep disable the hwdep component
- --disable-seq disable the sequencer component
- --disable-ucm disable the use-case-manager component
- --disable-topology disable the DSP topology component
- --disable-alisp disable the alisp component
- --disable-old-symbols disable old obsoleted symbols
- --disable-python disable the python components
- --disable-thread-safety disable thread-safe API functions
-
- Optional Packages:
- --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
- --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
- --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
- both]
- --with-gnu-ld assume the C compiler uses GNU ld [default=no]
- --with-sysroot=DIR Search for dependent libraries within DIR
- (or the compiler's sysroot if not specified).
- --with-configdir=dir path where ALSA config files are stored
- --with-plugindir=dir path where ALSA plugin files are stored
- --with-pkgconfdir=dir path where pkgconfig files are stored
- --with-versioned shared library will be compiled with versioned
- symbols (default = yes)
- --with-debug library will be compiled with asserts (default =
- yes)
- --with-tmpdir=directory directory to put tmp socket files (/tmp)
- --with-softfloat do you have floating point unit on this machine?
- (optional)
- --with-libdl Use libdl for plugins (default = yes)
- --with-pthread Use pthread (default = yes)
- --with-librt Use librt for monotonic clock (default = yes)
- --with-wordexp Use wordexp when expanding configs (default = no)
- --with-alsa-devdir=dir directory with ALSA device files (default /dev/snd)
- --with-aload-devdir=dir directory with aload* device files (default /dev)
- --with-pythonlibs=ldflags
- specify python libraries (-lpthread -lm -ldl
- -lpython2.4)
- --with-pythonincludes=Cflags
- specify python C header files
- (-I/usr/include/python)
- --with-pcm-plugins=<list>
- build PCM plugins (default = all)
- --with-ctl-plugins=<list>
- build control plugins (default = all)
- --with-max-cards Specify the max number of cards (default = 32)
- Some influential environment variables:
- CC C compiler command
- CFLAGS C compiler flags
- LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
- nonstandard directory <lib dir>
- LIBS libraries to pass to the linker, e.g. -l<library>
- CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
- you have headers in a nonstandard directory <include dir>
- CPP C preprocessor
- Use these variables to override the choices made by `configure' or to help
- it to find libraries and programs with nonstandard names/locations.
-
- Report bugs to the package provider.

2.21.用法说明
./configure [OPTION]... [VAR=VALUE]...
2.22.几个重点参数说明。
指定软件运行的系统平台,如果没有指定,将会运行'config.guess'来检测。--host指定的是交叉编译工具链的前缀。
指定软件安装的系统平台,如当前我们是在x86_64的ubuntu系统上,那我们的--build就可能是x86_64-unknown-linux-gnu。 如果没有指定,默认将是'--host'选项的值。
以上二个参数,当--build和--host不同的时候就被配置文件认定文进行交叉编译,否则就是表示本地编译。从这个参数的含义来看,说明其处理的目标只有在不同平台下变现为不同的时候才有作用,而这些文件通常都跟目标平台的指令系统直接或间接相关:比如可执行文件,对于不同平台下使用的可执行文件的编码可以是完全不同的,因此必须使用对应能处理该编码的程序才能正确处理,而如果错误的使用则可能导致程序错误或者破坏文件,对于这样要处理不同平台下会出现不同编码的软件,我们就应当对它指定目标平台,以免令其错误处理;而对于文本文件,对于不同的平台同样的内容表达的含义都是相同的,因此我们不需要专门针对平台来处理。
在交叉编译之后,我们用file ***指令,查看生成的文件类型,如果不正确,可以在源码包的目录下面查看config.log文件,看看有没有找到相应的编译工具链。
软件包提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来使用它,这里'FEATURE'是特性的名字,一个特性可能或接收一个可选的参数,例如:
./configure --enable-buffers=128
--prefix是最常用的选项,制作出的'makefile'会查看随此选项传递的参数,当一个包在安装时可以彻底的重新安置他的结构独立部分。
指定二进制文件的安装位置,这里的二进制文件定义为可以被用户直接执行的程序。
指定超级二进制文件的安装位置,这是一些通常只能由超级用户执行的程序。
指定C头文件的安装位置,其他语言如C++的头文件也可以使用此选项。
通过以上介绍,相信你已经对configure有了大体的了解。如果没能理解,也没有关系,跟着接下来的步骤,你也会生成你自己的alsa库。
2.3.交叉编译
准备阶段:在你的ubuntu主机上面创建如下文件夹:比如我的
- /home/ccion/ccion/alsa/usr/local
- ccion@ubuntu:~/ccion/alsa/usr/local$
mkdir share/arm-alsa/ share/alsa/ lib/alsa_lib/
然后进入你下载的alsa-lib源码包,在源码包目前下,你会看到如下:
- ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ ls
- acinclude.m4 config.log depcomp libtool Makefile.in test
- aclocal.m4 config.status doc ltconfig MEMORY-LEAK TODO
- alsalisp config.sub gitcompile ltmain.sh missing utils
- aserver configure include m4 modules version
- ChangeLog configure.ac INSTALL Makefile NOTES
- config.guess COPYING install-sh Makefile.am src
开始编译:
./configure --host=arm-linux-gnueabihf --prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/ --enable-shared --disable-python --witch-configdir=/home/ccion/ccion/alsa/usr/local/share/alsa --with-plugindir=/home/ccion/ccion/alsa/usr/local/lib/alsa_lib CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-ld
- ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ make
- ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ make install
成功编译后,你会在刚才建立的文件夹下面看到:
- ccion@ubuntu:~/ccion/alsa/usr/local$ tree -L 3
- .
- ├── lib
- │ └── alsa_lib
- └── share
- ├── alsa
- │ ├── alsa.conf
- │ ├── alsa.conf.d
- │ ├── cards
- │ ├── pcm
- │ ├── sndo-mixer.alisp
- │ ├── topology
- │ └── ucm
- └── arm-alsa
- ├── bin
- ├── include
- ├── lib
- └── share

其中,arm-alsa下的lib就是生成的库文件,以上这些文件都需要拷贝到开发板相关目录下。
验证下你的库包正确否,还记上面的命令么?
- ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/lib$ file libasound.so.2.0.0
-
- libasound.so.2.0.0: ELF 32-bit LSB shared object, ARM,
- EABI5 version 1 (SYSV), dynamically linked,BuildID[sha1]=d1e68987c2a07d091210685f7610cbd13ce06210,
- not stripped
出现arm就表示是arm平台的文件库。接下来我们开始编译alsa官网提供的调试工具:alsa-utils-1.1.5.
3.交叉编译alsa-utils-1.1.5
不多说直接上命令:
./configure --host=arm-linux-gnueabihf --prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/ --disable-xmlto --with-alsa-inc-prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/include --with-alsa-prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/lib --disable-alsamixer
注意:--prefix是你编译出来存在的位置。--with-alsa-inc-prefix和--with-alsa-prefix分别指定了交叉编译util应用所需要的alsa-lib的头文件和库文件。这里的路径一定要改为你自己的路径。--disable-alsamixer表示不编译生成alsamixer这个应用程序,因为这个程序依赖ncurses这个图形界面库。
ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-utils-1.1.5$ make
sudo make install
注意:install的时候一定要用超级用户,不然会报错。
再来看看我们生成的bin文件。
- ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/bin$ ls
- aconnect alsaloop alsaucm amixer aplaymidi arecordmidi aseqnet iecset
- alsabat alsatplg amidi aplay arecord aseqdump aserver speaker-test
file一下,
- ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/bin$ file aplay
- aplay: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=e2eedccaa34695ed85e0d75294ee9c15f34049af, not stripped
以上是alsa-lib-1.1.5和alsa-utils-1.1.5的交叉编译说明和大体介绍了下configure,在下篇文章中,我将会跟你分享alsa-utils-1.1.5生成的bin的用法和相关api讲解。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。