Building C2Ada on Linux 2.6.20
By Nasser M. Abbasi
Updated Feb. 2, 2015
Which platform did I build this on?
Changes made to make the code compile/link
Example run and Ada files generated
These are notes to help in building and running C2Ada. Although it compiled and runs, the translator is not perfect, and it does not seem to translate some header files.
$uname -a
Linux my-desktop 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux
Update: Feb. 3, 2015: email from Mike Quentel. A copy of c2ada is now at https://github.com/mikequentel/c2ada
Update: August 17, 2007: Thanks to the help of Jeff Creem, the source code now resides on http://sourceforge.net/ under the project c2ada. Please obtain it from there. It now in a better place under source control.
I'll leave this page up just for archive/historical reasons.
Here is the august 2007 updated source code c2ada_linux_august_2007.zip
This is the OLD source code tar file BEFORE I made my
changes in case someone needs the original. c2ada_OLD_linux_source.tar.gz
This is c2ada binary build for linux. It uses shared libraries are configured on my linux system, so might not work on your linux system.
0) Get the necessary software. On Ubuntu it was easy for me to do this, using adept_manager. I installed latest python, gperf, and bison (for Yacc)
Compiler used in gcc 4.1.2-1. Also make sure you have /bin/csh installed as the script hostinfo included uses this shell and not bash.
1) First, Edit the Makefile and modify the following
GPERF =
PYTHON =
PYTHON_LIB =
PYTHON_INCLUDE =
HERE =
and make them point to correct places in your system. For example, on my system, which is Ubuntu, I have the following:
GPERF = /usr/bin/gperf
PYTHON = /usr/lib/python2.5
PYTHON_LIB = python2.5
PYTHON_INCLUDE = /usr/include/python2.5
HERE = /home/nabbasi/c2ada
In the above, HERE reference to the directory where you extracted the c2Ada sources to.
2)
make realclean
make all
if all is well, you should have file called c2ada in the directory $HERE.
Copy this c2ada to your /usr/local/bin, or any other place, and make sure it is in your path.
This is a log file that shows the outout of the build I did.
To use it, do the following. Assume you have a file foo.c, then do
export PYTHONPATH=/home/nabbasi/c2ada:/usr/lib/python2.5/
export PYTHONHOME=/usr/lib/python2.5
c2ada -I/usr/include -I/usr/include/linux -gnat foo.c
This will create a directory called binding below the current directory. Inside binding you will find the result of the translation.
Type c2ada to obtain help and other options c2ada can accept.
This is the output from
running c2ada on the following file:
#include <stdio.h>
void main()
{
}
And print of some of the ada
files generated.
This
ZIP file contains all the files generated from this command
below.
$ ./c2ada -I/usr/include -I/usr/include/linux -gnat foo.c
/usr/include/gconv.h, line
72, Error: syntax error
G_config, Warning: Order of
types MAY NOT be correct
Info: Generating
bindings/foo.ads bindings/foo.adb
Info: Generating
bindings/stdio.ads bindings/stdio.adb
Info: Generating
bindings/features.ads bindings/features.adb
Info: Generating
bindings/sys-cdefs.ads bindings/sys-cdefs.adb
Info: Generating
bindings/bits-wordsize.ads bindings/bits-wordsize.adb
Info: Generating
bindings/gnu-stubs.ads bindings/gnu-stubs.adb
Info: Generating
bindings/gnu-stubs-32.ads bindings/gnu-stubs-32.adb
Info: Generating
bindings/linux-stddef.ads bindings/linux-stddef.adb
Info: Generating
bindings/bits-types.ads bindings/bits-types.adb
Info: Generating
bindings/bits-typesizes.ads bindings/bits-typesizes.adb
Info: Generating
bindings/libio.ads bindings/libio.adb
Info: Generating
bindings/g_config.ads bindings/g_config.adb
Info: Generating bindings/wchar.ads
bindings/wchar.adb
Info: Generating
bindings/bits-wchar.ads bindings/bits-wchar.adb
Info: Generating
bindings/gconv.ads bindings/gconv.adb
__GNUC_PREREQ untranslated,
/usr/include/features.h line 135
__GLIBC_PREREQ untranslated,
/usr/include/features.h line 309
__NTH untranslated,
/usr/include/sys/cdefs.h line 64
__volatile untranslated,
/usr/include/sys/cdefs.h line 68
__P untranslated,
/usr/include/sys/cdefs.h line 74
__PMT untranslated,
/usr/include/sys/cdefs.h line 75
__CONCAT untranslated,
/usr/include/sys/cdefs.h line 80
__STRING untranslated,
/usr/include/sys/cdefs.h line 81
__USING_NAMESPACE_STD
untranslated, /usr/include/sys/cdefs.h line 116
__USING_NAMESPACE_C99
untranslated, /usr/include/sys/cdefs.h line 119
__bos untranslated, /usr/include/sys/cdefs.h
line 132
__bos0 untranslated,
/usr/include/sys/cdefs.h line 133
__warndecl untranslated,
/usr/include/sys/cdefs.h line 134
__flexarr untranslated,
/usr/include/sys/cdefs.h line 149
__attribute_used__
untranslated, /usr/include/sys/cdefs.h line 218
__attribute_format_arg__
untranslated, /usr/include/sys/cdefs.h line 238
__attribute_format_strfmon__
untranslated, /usr/include/sys/cdefs.h line 249
__nonnull untranslated,
/usr/include/sys/cdefs.h line 257
__always_inline untranslated,
/usr/include/sys/cdefs.h line 279
__LDBL_REDIR1 untranslated,
/usr/include/sys/cdefs.h line 331
__LDBL_REDIR untranslated,
/usr/include/sys/cdefs.h line 332
__LDBL_REDIR1_NTH
untranslated, /usr/include/sys/cdefs.h line 333
__LDBL_REDIR_NTH untranslated,
/usr/include/sys/cdefs.h line 334
__LDBL_REDIR_DECL
untranslated, /usr/include/sys/cdefs.h line 335
NULL untranslated,
/usr/include/linux/stddef.h line 9
__STD_TYPE untranslated,
/usr/include/bits/types.h line 119
__DEV_T_TYPE untranslated, /usr/include/bits/typesizes.h
line 30
__UID_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 31
__GID_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 32
__INO_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 33
__INO64_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 34
__MODE_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 35
__NLINK_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 36
__OFF_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 37
__OFF64_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 38
__PID_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 39
__RLIM_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 40
__RLIM64_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 41
__BLKCNT_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 42
__BLKCNT64_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 43
__FSBLKCNT_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 44
__FSBLKCNT64_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 45
__FSFILCNT_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 46
__FSFILCNT64_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 47
__ID_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 48
__CLOCK_T_TYPE untranslated, /usr/include/bits/typesizes.h
line 49
__TIME_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 50
__USECONDS_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 51
__SUSECONDS_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 52
__DADDR_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 53
__SWBLK_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 54
__KEY_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 55
__CLOCKID_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 56
__BLKSIZE_T_TYPE
untranslated, /usr/include/bits/typesizes.h line 58
__FSID_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 59
__SSIZE_T_TYPE untranslated,
/usr/include/bits/typesizes.h line 60
_G_size_t untranslated,
/usr/include/_G_config.h line 25
_G_wchar_t untranslated,
/usr/include/_G_config.h line 41
_G_stat64 untranslated,
/usr/include/_G_config.h line 43
__UNKNOWN_10646_CHAR
untranslated, /usr/include/gconv.h line 34
nabbasi@my-desktop:~/c2ada_OK$ cd bindings/
nabbasi@my-desktop:~/c2ada_OK/bindings$ ls -lrt
total 124
-rw-r--r-- 1 nabbasi nabbasi
1397 2007-08-12 07:39 wchar.ads
-rw-r--r-- 1 nabbasi
nabbasi 60 2007-08-12 07:39 wchar.adb
-rw-r--r-- 1 nabbasi nabbasi
2371 2007-08-12 07:39 sys-cdefs.ads
-rw-r--r-- 1 nabbasi
nabbasi 68 2007-08-12 07:39
sys-cdefs.adb
-rw-r--r-- 1 nabbasi nabbasi
1081 2007-08-12 07:39 stdio.ads
-rw-r--r-- 1 nabbasi
nabbasi 60 2007-08-12 07:39 stdio.adb
-rw-r--r-- 1 nabbasi
nabbasi 192 2007-08-12 07:39
linux-stddef.ads
-rw-r--r-- 1 nabbasi
nabbasi 74 2007-08-12 07:39
linux-stddef.adb
-rw-r--r-- 1 nabbasi
nabbasi 178 2007-08-12 07:39 libio.ads
-rw-r--r-- 1 nabbasi
nabbasi 60 2007-08-12 07:39 libio.adb
-rw-r--r-- 1 nabbasi
nabbasi 46 2007-08-12 07:39
gnu-stubs.ads
-rw-r--r-- 1 nabbasi
nabbasi 68 2007-08-12 07:39
gnu-stubs.adb
-rw-r--r-- 1 nabbasi nabbasi
2152 2007-08-12 07:39 gnu-stubs-32.ads
-rw-r--r-- 1 nabbasi
nabbasi 74 2007-08-12 07:39
gnu-stubs-32.adb
-rw-r--r-- 1 nabbasi nabbasi
2256 2007-08-12 07:39 gconv.ads
-rw-r--r-- 1 nabbasi
nabbasi 60 2007-08-12 07:39 gconv.adb
-rw-r--r-- 1 nabbasi nabbasi
2269 2007-08-12 07:39 g_config.ads
-rw-r--r-- 1 nabbasi
nabbasi 66 2007-08-12 07:39
g_config.adb
-rw-r--r-- 1 nabbasi
nabbasi 26 2007-08-12 07:39 foo.ads
-rw-r--r-- 1 nabbasi
nabbasi 64 2007-08-12 07:39 foo.adb
-rw-r--r-- 1 nabbasi
nabbasi 896 2007-08-12 07:39
features.ads
-rw-r--r-- 1 nabbasi
nabbasi 66 2007-08-12 07:39
features.adb
-rw-r--r-- 1 nabbasi
nabbasi 185 2007-08-12 07:39
bits-wordsize.ads
-rw-r--r-- 1 nabbasi
nabbasi 76 2007-08-12 07:39
bits-wordsize.adb
-rw-r--r-- 1 nabbasi
nabbasi 457 2007-08-12 07:39
bits-wchar.ads
-rw-r--r-- 1 nabbasi
nabbasi 70 2007-08-12 07:39
bits-wchar.adb
-rw-r--r-- 1 nabbasi
nabbasi 445 2007-08-12 07:39
bits-typesizes.ads
-rw-r--r-- 1 nabbasi
nabbasi 78 2007-08-12 07:39
bits-typesizes.adb
-rw-r--r-- 1 nabbasi nabbasi
6447 2007-08-12 07:39 bits-types.ads
-rw-r--r-- 1 nabbasi
nabbasi 70 2007-08-12 07:39
bits-types.adb
nabbasi@my-desktop:~/c2ada_OK/bindings$
$ cat foo.adb
with C;
with C.Ops; use C.Ops;
package body foo is
end foo;
nabbasi@my-desktop:~/c2ada_OK/bindings$ cat stdio.ads
with C;
package stdio is
STDIO_H : constant := 1; -- /usr/include/stdio.h:27
need_size_t : constant Boolean := True; -- /usr/include/stdio.h:32
need_NULL : constant Boolean := True; -- /usr/include/stdio.h:33
need_FILE : constant Boolean := True; -- /usr/include/stdio.h:37
need_FILE_c0 : constant Boolean := True; -- /usr/include/stdio.h:38
FILE_defined : constant := 1; -- /usr/include/stdio.h:54
FILE_defined_c0 : constant
:= 1; --
/usr/include/stdio.h:64
STDIO_USES_IOSTREAM : constant Boolean :=
True; -- /usr/include/stdio.h:70
type struct_IO_FILE; --
/usr/include/stdio.h:46
type FILE; --
/usr/include/stdio.h:46
type FILE_c0; -- /usr/include/stdio.h:62
subtype FILE is struct_IO_FILE; -- /usr/include/stdio.h:46
subtype FILE_c0 is struct_IO_FILE; -- /usr/include/stdio.h:62
end stdio;
nabbasi@my-desktop:~/c2ada_OK/bindings$
cat features.ads
with C;
package features is
FEATURES_H : constant := 1;
-- /usr/include/features.h:21
KERNEL_STRICT_NAMES : constant Boolean :=
True;
-- /usr/include/features.h:118
USE_ANSI : constant := 1;
-- /usr/include/features.h:122
USE_FORTIFY_LEVEL : constant
:= 0; --
/usr/include/features.h:285
STDC_IEC_559 : constant := 1;
-- /usr/include/features.h:289
STDC_IEC_559_COMPLEX: constant := 1;
-- /usr/include/features.h:290
STDC_ISO_10646 : constant := 200009;
-- /usr/include/features.h:293
GNU_LIBRARY : constant := 6;
-- /usr/include/features.h:302
GLIBC : constant := 2;
-- /usr/include/features.h:306
GLIBC_MINOR : constant := 4;
-- /usr/include/features.h:307
end features;
nabbasi@my-desktop:~/c2ada_OK/bindings$
nabbasi@my-desktop:~/c2ada_OK/bindings$ cat gconv.ads
with C;
package gconv is
GCONV_H : constant := 1;
-- /usr/include/gconv.h:24
need_mbstate_t : constant Boolean := True;
-- /usr/include/gconv.h:27
need_size_t : constant Boolean := True;
-- /usr/include/gconv.h:29
need_wchar_t : constant Boolean := True;
-- /usr/include/gconv.h:30
type enum_anonymous0_t is ( --
/usr/include/gconv.h:51
GCONV_OK, --
/usr/include/gconv.h:39
GCONV_NOCONV, --
/usr/include/gconv.h:40
GCONV_NODB, --
/usr/include/gconv.h:41
GCONV_NOMEM, --
/usr/include/gconv.h:42
GCONV_EMPTY_INPUT, --
/usr/include/gconv.h:44
GCONV_FULL_OUTPUT, -- /usr/include/gconv.h:45
GCONV_ILLEGAL_INPUT, --
/usr/include/gconv.h:46
GCONV_INCOMPLETE_INPUT, --
/usr/include/gconv.h:47
GCONV_ILLEGAL_DESCRIPTOR, -- /usr/include/gconv.h:49
GCONV_INTERNAL_ERROR --
/usr/include/gconv.h:51
);
for enum_anonymous0_t'Size use
C.int'Size; --
/usr/include/gconv.h:51
type enum_anonymous1_t is ( -- /usr/include/gconv.h:59
GCONV_IS_LAST, --
/usr/include/gconv.h:57
GCONV_IGNORE_ERRORS --
/usr/include/gconv.h:59
);
for enum_anonymous1_t use (
GCONV_IS_LAST => 1,
GCONV_IGNORE_ERRORS => 2
);
for enum_anonymous1_t'Size use
C.int'Size; --
/usr/include/gconv.h:59
type struct_gconv_step; --
/usr/include/gconv.h:63
type struct_gconv_step_data; -- /usr/include/gconv.h:64
type struct_gconv_loaded_object; -- /usr/include/gconv.h:65
type struct_gconv_trans_data; -- /usr/include/gconv.h:66
end gconv;
nabbasi@my-desktop:~/c2ada_OK/bindings$