Creating an Eiffel wrapper for The GNU Multiple Precision Arithmetic Library (GMP)

Installing CIL (if not yet done):
git clone git://cil.git.sourceforge.net/gitroot/cil/cil; cd cil
./configure
make
export PATH=$PATH:`pwd`/bin

1. Compiling the library (business as usual)

wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2
tar xfj gmp-5.0.5.tar.bz2; cd gmp-5.0.5
./configure
make

2. CIL preprocessing

  1. Creating the C file:
    You have to create a C file that includes all necessary library header files; for GMP this is only gmp.h.
    [GMP specific] Since gmp.h excludes certain functions if stdio.h is not present (but we want all functions), we also add it:
    echo -e "#include <stdio.h>\n#include \"gmp.h\"" > gmp.c
  2. Creating the CIL C file:
    export CILLY_DONT_COMPILE_AFTER_MERGE=1
    cilly --merge --save-temps --keepunused --noWrap gmp.c
  3. Removing compiler builtins (we don't want to translate them):
    perl -0pi -e 's/\/\* compiler builtin:.*?\*\/\n//sg' gmp.cil.c
  4. Removing inlined functions (we don't want to translate them):
    perl -0pi -e 's/__inline extern [^;]*?{.*?\n}\n}\n//sg' gmp.cil.c

Done

Now you can translate the created gmp.cil.c with C2Eif. It will create an Eiffel library that is an interface to the C library.