Tuesday, March 29, 2011

ALSA tips and tricks

1. If a single channel is selected, the left channel is used. For example using the next function:


int snd_pcm_hw_params_set_channels ( snd_pcm_t *  pcm,


snd_pcm_hw_params_t *  params,


unsigned int  val

)















If val parameter take value 1, meaning 1 channel (mono), the left channeel of the hardware input will be used.































Wednesday, March 9, 2011

Creating a simple RPM binary package


Let take a simple example, you have a binary and a configuration file which you want to install on a Linux machine using a RPM. The binary file “ExampleBin” should be copy on /usr/bin and the configuration file “ExampleBin.conf” should be copy on /etc.
First of all, to be able to create a RPM you need to have installed the rpm-build tool.
Any RPM is created based on a “spec file”. This file basically explains to rpm-build tool how to create and configure the RPM pack.
So let create the “spec file” name “ExampleBin.spec”:

Summary: ExampleBin
Name: ExampleBin
Version: 0.1
Release: 1
Group: ExampleBin
License: ExampleBin
Source: %{expand:%%(pwd)}
BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}

%description
%{summary}

%prep
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin
mkdir -p $RPM_BUILD_ROOT/etc
cd $RPM_BUILD_ROOT
cp %{SOURCEURL0}/iButtonServer ./usr/bin/
cp %{SOURCEURL0}/iButtonServer.cfg ./etc/

%clean
rm -r -f "$RPM_BUILD_ROOT"

%files
%defattr(644,root,root)
%config(noreplace) %{_sysconfdir}/ ExampleBin.cfg
%defattr(755,root,root)
%{_bindir}/ ExampleBin

%post
ExampleBin start

%preun
ExampleBin stop

On this example, the binary and configuration file are placed on the current directory (pwd).


In the %prep section, the build process is prepared. In our example the required files are copied to $RPM_BUILD_ROOT (build directory).

The %post section executes after the package has been installed. 
The %preun section executes before the user uninstall the package.

This script need _topdir environment variable. It should be set inside .rpmmacros file, placed on your home directory.
The next bash script set the _topdir enviroment variable and create the RPM calling using rpm-build tool:
#!/bin/bash

echo '%_topdir '$(pwd) > ~/.rpmmacros
rpmbuild -bb ExampleBin.spec

Running this script placed on the same level like “spec file” the RPM should be generated.