SPO Lab 4 (Part 1) - Building Open Source Package

For this lab, I am going to build and test an open source package. I picked units project from gnu.org page which is licensed under GNU GPL. Units converts quantities expressed in various systems of measurement to their equivalents in other systems of measurement.

Compiling

First, download the zipped source files :

    wget . http://ftp.gnu.org/gnu/units/units-2.14.tar.gz

Unzipping the package :

    tar -zxvf units-2.14.tar.gz

Gnu.org units page does not seem to have any installation instructions, however I was able to find INSTALL file that contains useful information regarding configuration, building and installation.

Here’s the list of instructions from INSTALL file:

    The simplest way to compile this package is:
    
      1. cd to the directory containing the package's source code and type
         ./configure to configure the package for your system .....
         
      2. Type make to compile the package.
    
      3. Optionally, type make check to run any self-tests that come with
         the package.
    
      4. Type make install' to install the programs and any data files and
         documentation.
    ...

I only need to run configuration script and make to compile the package, note that 4th instruction will install the package (we don’t want this).

Let’s start by running configuration script :

    [obelavina@xerxes units-2.14]$ ./configure 
    checking for gcc... gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking for gcc option to accept ISO C99... none needed
    checking whether C compiler accepts -fpic... yes
    checking for an ANSI C-conforming const... yes
    checking for a BSD-compatible install... /usr/bin/install -c
    checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
    checking for library containing sin... -lm
    checking for readline in -lreadline... yes
    checking whether rl_completion_suppress_append is declared... no
    checking how to run the C preprocessor... gcc -E
    checking for grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking for string.h... (cached) yes
    checking for stdlib.h... (cached) yes
    checking for strchr... yes
    checking for strspn... yes
    checking for strtok... yes
    checking for setenv... yes
    checking for setlocale... yes
    checking for locale and UTF-8 support... yes
    checking for isfinite... yes
    checking for mksinfo... no
    checking for python... /usr/bin/python
    configure: creating ./config.status
    config.status: creating Makefile

Seems like like it worked. Now units can be compiled with make command :

    [obelavina@xerxes units-2.14]$ make
    gcc -DUNITSFILE=\"/usr/local/share/units/definitions.units\" -DLOCALEMAP=\"/usr/local/share/units/locale_map.txt\" -DREADLINE -DNO_SUPPRESS_APPEND -DSUPPORT_UTF8 -DPACKAGE_NAME=\"GNU\ units\" -DPACKAGE_TARNAME=\"units\" -DPACKAGE_VERSION=\"2.14\" -DPACKAGE_STRING=\"GNU\ units\ 2.14\" -DPACKAGE_BUGREPORT=\"adrianm@gnu.org\" -DPACKAGE_URL=\"http://www.gnu.org/software/units/\" -.....
    .............

Let’s verify that it worked by using make check command suggested in INSTALL file:

    [obelavina@xerxes units-2.14]$ make check
    Checking units
    Units seems to work

Make command produced units binary. Lets try to run it :

    [obelavina@xerxes units-2.14]$ ./units
    units: cannot open units data file '/usr/local/share/units/definitions.units'.  No such file or directory

(Oops!)It complains about missing definitions file because we haven’t installed units binary on the system. As a workaround, you can provide custom units file path with —file option :

    [obelavina@xerxes units-2.14]$ ./units --file ./definitions.units 

Let’s run an example from Gnu.org unit page and see if it works now:

    [obelavina@xerxes units-2.14]$ ./units --file ./definitions.units 
    Currency exchange rates from www.timegenie.com on 2017-03-08 
    2980 units, 109 prefixes, 96 nonlinear units
    
    You have: mile
    You want: km
            * 1.609344
            / 0.62137119

We got the expected conversion result !

Written on September 29, 2017