Friday, May 30, 2014

Managing different versions of a software - update-alternatives

Managing different versions of a software in Ubuntu is made easy by update-alternatives. For example, assume having different versions of eclipse in Ubuntu.

The eclipse can be installed from the tar balls available from eclipse download page. Juno Download page. Indigo Download Page.

Move the downloaded the tar balls to /opt and unzip them. (/opt - just a directory for optional packages)

$cd /opt
/opt$sudo mv ~/Downloads/eclipse-cpp-juno-SR2-linux-gtk-x86_64.tar.gz .
/opt$sudo tar xzvf eclipse-cpp-juno-SR2-linux-gtk-x86_64.tar.gz
/opt$sudo mv eclipse eclipse_juno
/opt$sudo mv ~/Downloads/eclipse-cpp-indigo-SR2-incubation-linux-gtk-x86_64.tar.gz .
/opt$sudo tar xzvf eclipse-cpp-indigo-SR2-incubation-linux-gtk-x86_64.tar.gz
/opt$sudo mv eclipse eclipse_indigo

The launcher executable (eclipse.exe) for the installed versions of eclipse would be in the respective install folder. I.e., In our case there will be a launcher executable (eclipse.exe) inside "/opt/eclipse_juno/" and "/opt/eclipse_indigo".

Now to manage the launch of these two versions of eclipse, we use the "update-alternatives" as shown below.

$sudo update-alternatives --install /usr/bin/eclipse eclipse /opt/eclipse_juno/eclipse 20
$sudo update-alternatives --install /usr/bin/eclipse eclipse /opt/eclipse_indigo/eclipse 10

Now to choose between versions, use "update-alternatives --config".

$ sudo update-alternatives --config eclipse
There are 2 choices for the alternative eclipse (providing /usr/bin/eclipse).

Selection Path                        Priority  Status
------------------------------------------------------------
* 0       /opt/eclipse_juno/eclipse   20        auto mode
  1       /opt/eclipse_indigo/eclipse 10        manual mode
  2       /opt/eclipse_juno/eclipse   20        manual mode

Press enter to keep the current choice[*], or type selection number:

By giving the selection number, the desired version shall be made set for launching.

Now we see the "update-alternatives --install" in detail. Consider the following command we issued above.

$sudo update-alternatives --install /usr/bin/eclipse eclipse /opt/eclipse_juno/eclipse 20

Here the number '20' is the priority for the version of the launcher we configure for alternatives. Higher the number higher the priority.

'/opt/eclipse_juno/eclipse' is the launcher we configure for alternatives.

'eclipse' is a symbolic link to be created in /etc/alternatives/. This symbolic link will point to the launcher we configure. Here it will be '/opt/eclipse_juno/eclipse'.

'/usr/bin/eclipse' is a symbolic link to '/etc/alternatives/eclipse'.

How it works?

'/usr/bin/eclipse' will always link to '/etc/alternatives/eclipse'. And '/etc/alternatives/eclipse' will change its link to the launcher we configure through "update-alternatives --config".

Wednesday, May 28, 2014

TV as display for Laptop through HDMI

TVs can be used as the displays for laptops using HDMI. For this, the TV and the laptop should have the HDMI port supported. And we need a HDMI cable.

I have ASUS X550LD laptop with Ubuntu 14.04 LTS on it and Sony Bravia KDL-40HX750. The laptop and the TV is connected through a HDMI 1.4a cable. To enable the display following are steps done.

Open the system display settings.

In display settings, we can see the built-in display enabled.

Select the TV display (Sony 40" in my case).

Switch-on the TV display.

Also set the launcher placement to TV.

Now switch-off the built-in display.

And apply the settings.

Now the display would be on the TV.

We may have to do some settings for the sound from TV. Open the sound settings.

There we can find the list of audio devices.

We have to select the 'HDMI / DisplayPort 2' audio device.

In my case, I found the sound setting as follows.

The 'HDMI / DisplayPort 2' audio device is not listed. I muted the laptop speakers and restarted the laptop. Then I got the list including 'HDMI / DisplayPort 2' audio device.

Tuesday, May 27, 2014

Makefile - Checking Build Compiler Version

Building executable from sources is made easy by Makefiles. If a build has to be done by checking the version of the build compiler, then the Makefile can be altered for that.

For example, building C sources using GCC compiler. If the C sources require the C++11 standard supported compiler, then the GCC compiler to be used should be greater than or equal to GCC-4.7. If the build environment has the GCC of version lesser than 4.7, then the build will fail.

For this case, the Makefile can be altered with the following check for GCC version:

GCCMAJORVERSIONGTE4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 4)
GCCMINORVERSIONGTE7 := $(shell expr `gcc -dumpversion | cut -f2 -d.` \>= 7)

all:
ifeq ($(GCCMAJORVERSIONGTE4)$(GCCMINORVERSIONGTE7), 11)
        @echo BUILD
else
        @echo NO BUILD
endif