Tuesday, October 18, 2016

Compiling ncurses

Compiling ncurses library

What is ncurses?

ncurses is a library written in C that provides API for running applications in a terminal.

See https://www.gnu.org/software/ncurses/

Why should I use it?

If you want to write an application that uses the terminal as its output, you should use it instead of trying to manipulate text in terminal by yourself. e.g Vim uses it to allow you to edit and view your files.

Step 1: Download ncurses

Go to the ncurses page and download the library.
For this tutorial I'll use ncurses 6.0

I usually put all source code in $HOME/src directory 

Make ncurses directory under src

carmel@carmel:~$ cd src/
carmel@carmel:~/src$ mkdir ncurses
carmel@carmel:~/src$ cd ncurses/
carmel@carmel:~/src/ncurses$ NDIR=`pwd`

From now on $NDIR will be the ncurses source code directory.

Download ncurses

carmel@carmel:~/src/ncurses$ wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz

Extract the files:

carmel@carmel:~/src/ncurses$ tar -xvzf ncurses-6.0.tar.gz
carmel@carmel:~/src/ncurses$ cd ncurses-6.0/
carmel@carmel:~/src/ncurses/ncurses-6.0$ ll

Take a look around.. If you want to learn more about the installation process, you should read the INSTALL file, its very interesting.
You should also run

./configure --help

Take a look in the configuration options and see if you need something that is not covered here.

Step 2: Configure


Due to this issue we need to export a cpp flag

carmel@carmel:~/src/ncurses/ncurses-6.0$ export CPPFLAGS="-P"


Use prefix option to configure changes the root directory for installing ncurses.  The default is normally in subdirectories of /usr/local.

    The package gets installed beneath the --prefix directory as follows:

    In $(prefix)/bin:          tic, infocmp, captoinfo, tset,
reset, clear, tput, toe, tabs
    In $(prefix)/lib:          libncurses*.* libcurses.a
    In $(prefix)/share/terminfo: compiled terminal descriptions
    In $(prefix)/include:      C header files
    Under $(prefix)/man:       the manual pages

I'll install ncurses under the prefix $HOME. 

With the --prefix option, the ./configure command should look like this now:

./configure --prefix=$HOME


Use the --with-shared option to generate shared-libraries. This is useful if you want to compile other programs with the ncurses library.

Now, with the --with-shared option the ./configure command should look like this:

./configure --prefix=$HOME --with-shared

Run the configuration..

carmel@carmel:~/src/ncurses/ncurses-6.0$ ./configure --prefix=$HOME --with-shared

The last lines of the output should look like:

carmel@carmel:~/src/ncurses/ncurses-6.0$ ./configure --prefix=$HOME --with-shared
** Configuration summary for NCURSES 6.0 20150808:

       extended funcs: yes
       xterm terminfo: xterm-new

        bin directory: /home/carmel/bin
        lib directory: /home/carmel/lib
    include directory: /home/carmel/include/ncurses
        man directory: /home/carmel/share/man
   terminfo directory: /home/carmel/share/terminfo

** Include-directory is not in a standard location

If you got an error then post a comment here describing the error and I'll add it into a 'Troubleshooting' section.

Step 3: make


carmel@carmel:~/src/ncurses/ncurses-6.0$ make

Step 4: make install


carmel@carmel:~/src/ncurses/ncurses-6.0$ make install


Error in make

After running
you get the following error:
In file included from ./curses.priv.h:325:0,
                 from ../ncurses/lib_gen.c:19:
_10346.c:843:15: error: expected ‘)’ before ‘int’
../include/curses.h:1631:56: note: in definition of macro ‘mouse_trafo’
 #define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen)

this is a known issue with mawk program. see this for more details
Go through step 2 again. make sure you run

carmel@carmel:~/src/ncurses/ncurses-6.0$ export CPPFLAGS="-P"

BEFORE you configure

Monday, September 5, 2016

compiling Python 2.7

Download Python 2.7 from the download page
Extract it. I'll extract it in

carmel@carmel:~$ cd programs/python/Python-2.7.12/

 configure --help


carmel@carmel:~/programs/python/Python-2.7.12$ ./configure --help

And you'll see the configuration help text.


Use the --prefix flag to install python under a custom directory.
I find it useful if you don't want to give the 'make' program root access. (I think it is a very bad practice)

Configuration line should now be 

carmel@carmel:~/programs/python/Python-2.7.12$ ./configure --prefix=/home/carmel


The help text from the configuration file says:

Optional Features:
   --enable-shared         disable/enable building shared python library

I need this since I want to compile vim with python. Without it I won't have the necessary libraries and config files. 
Configuration line should now be 

carmel@carmel:~/programs/python/Python-2.7.12$ ./configure --prefix=/home/carmel --enable-shared



carmel@carmel:~/programs/python/Python-2.7.12$ ./configure --prefix=/home/carmel --enable-shared && make && make install

Sunday, September 4, 2016

Compiling vim

Download vim



carmel@carmel:~$ cd programs/vim/vim74/
carmel@carmel:~/programs/vim/vim74$ ./configure --help

And you get
`configure' configures this package to adapt to many kinds of systems.

Usage: auto/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.

  -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
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' 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]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --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/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

X features:
  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR

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]
  --enable-fail-if-missing    Fail if dependencies on additional features
     specified on the command line are missing.
  --disable-darwin        Disable Darwin (Mac OS X) support.
  --disable-smack   Do not check for Smack support.
  --disable-selinux   Do not check for SELinux support.
  --disable-xsmp          Disable XSMP session management
  --disable-xsmp-interact Disable XSMP interaction
  --enable-luainterp=OPTS     Include Lua interpreter.  default=no OPTS=no/yes/dynamic
  --enable-mzschemeinterp   Include MzScheme interpreter.
  --enable-perlinterp=OPTS     Include Perl interpreter.  default=no OPTS=no/yes/dynamic
  --enable-pythoninterp=OPTS   Include Python interpreter. default=no OPTS=no/yes/dynamic
  --enable-python3interp=OPTS   Include Python3 interpreter. default=no OPTS=no/yes/dynamic
  --enable-tclinterp=OPTS      Include Tcl interpreter. default=no OPTS=no/yes/dynamic
  --enable-rubyinterp=OPTS     Include Ruby interpreter.  default=no OPTS=no/yes/dynamic
  --enable-cscope         Include cscope interface.
  --enable-workshop       Include Sun Visual Workshop support.
  --disable-netbeans      Disable NetBeans integration support.
  --disable-channel      Disable process communication support.
  --enable-multibyte      Include multibyte editing support.
  --enable-hangulinput    Include Hangul input support.
  --enable-xim            Include XIM input support.
  --enable-fontset        Include X fontset output support.
  --enable-gui=OPTS     X11 GUI default=auto OPTS=auto/no/gtk2/gnome2/gtk3/motif/athena/neXtaw/photon/carbon
  --enable-gtk2-check     If auto-select GUI, check for GTK+ 2 default=yes
  --enable-gnome-check    If GTK GUI, check for GNOME default=no
  --enable-gtk3-check     If auto-select GUI, check for GTK+ 3 default=yes
  --enable-motif-check    If auto-select GUI, check for Motif default=yes
  --enable-athena-check   If auto-select GUI, check for Athena default=yes
  --enable-nextaw-check   If auto-select GUI, check for neXtaw default=yes
  --enable-carbon-check   If auto-select GUI, check for Carbon default=yes
  --disable-gtktest       Do not try to compile and run a test GTK program
  --disable-icon-cache-update        update disabled
  --disable-desktop-database-update  update disabled
  --disable-largefile     omit support for large files
  --disable-acl           Don't check for ACL support.
  --disable-gpm           Don't use gpm (Linux mouse daemon).
  --disable-sysmouse    Don't use sysmouse (mouse in *BSD console).
  --disable-nls           Don't support NLS (gettext()).

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-mac-arch=ARCH    current, intel, ppc or both
  --with-developer-dir=PATH    use PATH as location for Xcode developer tools
  --with-local-dir=PATH   search PATH instead of /usr/local for local libraries.
  --without-local-dir     do not search /usr/local for local libraries.
  --with-vim-name=NAME    what to call the Vim executable
  --with-ex-name=NAME     what to call the Ex executable
  --with-view-name=NAME   what to call the View executable
  --with-global-runtime=DIR    global runtime directory in 'runtimepath'
  --with-modified-by=NAME       name of who modified a release version
  --with-features=TYPE    tiny, small, normal, big or huge (default: huge)
  --with-compiledby=NAME  name to show in :version message
  --with-lua-prefix=PFX   Prefix where Lua is installed.
  --with-luajit           Link with LuaJIT instead of Lua.
  --with-plthome=PLTHOME   Use PLTHOME.
  --with-python-config-dir=PATH  Python's config directory
  --with-python3-config-dir=PATH  Python's config directory

  --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)
  --with-ruby-command=RUBY  name of the Ruby command (default: ruby)
  --with-x                use the X Window System
  --with-gnome-includes=DIR Specify location of GNOME headers
  --with-gnome-libs=DIR   Specify location of GNOME libs
  --with-gnome            Specify prefix for GNOME files
  --with-motif-lib=STRING   Library for Motif
  --with-tlib=library     terminal library to be used

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L if you have libraries in a
              nonstandard directory 
  LIBS        libraries to pass to the linker, e.g. -l
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I if
              you have headers in a nonstandard directory 
  CPP         C preprocessor
  XMKMF       Path to xmkmf, Makefile generator for X Window System

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.


I would like to install vim in a custom directory. This means that all the compiled binaries and libs will be installed under a custom directory and not in the usual locations.
Why I do this? This lets me compile the program without using
and this way I don't give root privileges to the make program.
Take a look at the user package manager out of the LFS project

The configuration says
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

So I'll use that. Configure line now should be:
carmel@carmel:~/programs/vim/vim74$ ./configure --prefix=$HOME


I'd like to enable python3 in this vim installation. I use it for Vdebug.
Configure line now should be 

carmel@carmel:~/programs/vim/vim74$ ./configure --prefix=$HOME --enable-python3interp=yes


You need this for vim to enable python. see this stackoverflow


For this you need to install ncurses.
I installed it with --prefix=$HOME so I'll need to let the configure script know where my libraries are
located. To do this I'll run

carmel@carmel:~/programs/vim/vim74$ export LDFLAGS="-L/home/carmel/lib"

and now I can add the ncurses part to the ./configure parameters

carmel@carmel:~/programs/vim/vim74$ ./configure --prefix=$HOME --enable-python3interp=yes --with-tlib=ncurses


  • After running ./configure I get the following error:
    carmel@carmel:~/programs/vim/vim74$ ./configure --prefix=$HOME
    checking --with-tlib argument... empty: automatic terminal library selection
    checking for tgetent in -ltinfo... no
    checking for tgetent in -lncurses... no
    checking for tgetent in -ltermlib... no
    checking for tgetent in -ltermcap... no
    checking for tgetent in -lcurses... no
    no terminal library found
    checking for tgetent()... configure: error: NOT FOUND!
          You need to install a terminal library; for example ncurses.
          Or specify the name of the library with --with-tlib.
    This is because you don't have any terminal library. Vim is dependent on a 3rd party terminal library to display / edit your text files. During the ./configure phase it checks to see if you have one of the following libraries installed - 'tinfo', 'ncurses', 'termlib', 'termcap' or 'curses'. I never tried to work with any library other than ncurses so I usually install that and pass the lib to the --with-tlib=library parameter. See compiling ncurses