c2foreign-c is a program to automatically generate (foreign c) bindings from C header files

It operates based on configuration of which procedures and such to generate bindings for.

## Dependencies

You need to have [c2ffi](https://github.com/rpav/c2ffi) installed. Easiest way
is propably to install it trough Guix.


## Installation

    snow-chibi install --impls=chibi retropikzel.c2foreign-c

## Usage

Say you have this config.scm:

    ((name "sdl2")
     (version "0.1.0")
     (shared-object "SDL2")
     (header-file "SDL2/SDL.h")
     (libraries
       (init
         SDL_Init)
       (version
         SDL_GetRevision)
       (video
         SDL_CreateWindow)
       (render
         SDL_CreateRenderer)))

Assuming you have SDL2 headers and c2ffi installed on your system and you run:

    c2foreign-c config.scm

The program will create directory c2foreing-c with following files:

    c2foreign-c/
    └── sdl2
        ├── init.sld
        ├── render.sld
        ├── sdl2.sld
        ├── VERSION
        ├── version.sld
        └── video.sld


For each config in libraries a corresponding file is created. They contain the
specified (foreign c) bindings. Here is c2foreign-c/sdl/init.sld for example:

    (define-library (c2foreign-c sdl2 init)
      (import (scheme base) (foreign c))
      (export SDL_Init)
      (begin (define-c-library shared-object '("SDL2/SDL.h") "SDL2" '())
             (define-c-procedure SDL_Init shared-object 'SDL_Init 'int '(u32))))

The names are not mangled in any way as rename and prefix can be used when
importing the library.

The c2foreign-c/sdl2/sdl2.sld is file named after the name given in configuration.
It imports all the libraries specified and exports their bindings:

    (define-library (c2foreign-c sdl2)
      (import (scheme base)
              (foreign c)
              (c2foreign-c sdl2 init)
              (c2foreign-c sdl2 version)
              (c2foreign-c sdl2 video)
              (c2foreign-c sdl2 render))
      (export SDL_Init SDL_GetRevision SDL_CreateWindow SDL_CreateRenderer))


This gives the user of the library more options, as they can import everything.
Which might be slow on their implementation, or pick just parts of the library.
For example if so desired every function can exist in their own library file,
allowing to import only what is needed.