1. Toby Inkster
  2. ada-perl-mashup

Commits

Toby Inkster  committed e3e30a7 Draft

more

  • Participants
  • Parent commits 97aefe8
  • Branches dynamic-lib

Comments (0)

Files changed (5)

File Makefile

View file
+all: libgreeter.a libgreeter.so 
+
 greeter.o: greeter.adb greeter.ads
 	gcc-4.4 -c -fPIC greeter.adb
 
 libgreeter.so: b~greeter.o
 	gcc -shared -o libgreeter.so b~greeter.o
 
-all: libgreeter.a libgreeter.so 
-
 clean:
 	rm -rf b_greeter.* b~greeter.* *.o *.so *.a *.ali
 
-test: libgreeter.so libgreeter.a greeter.pl
-	perl greeter.pl
+test-perl: libgreeter.so libgreeter.a greeter-test.pl
+	perl greeter-test.pl
+
+test-c: libgreeter.so libgreeter.a greeter-test.c
+	perl greeter-test.pl

File greeter-test.c

View file
+#include "libgreeter.h"
+
+int main (void)
+{
+	/* First, elaborate the library before using it */
+	greeterinit ();
+	
+	/* Main program, using the library exported entities */
+	hello ();
+	
+	/* Library finalization at the end of the program */
+	greeterfinal ();
+	return 0;
+}

File greeter-test.pl

View file
+#!/usr/bin/env perl
+
+use 5.014;
+use strict;
+use warnings;
+
+#BEGIN { $ENV{PERL_DL_DEBUG} = 1 };
+
+package Greeter
+{
+	use constant ADADIR => '/usr/lib/gcc/x86_64-linux-gnu/4.4/rts-native/adalib/';
+	use constant OURDIR => do { (my $f = __FILE__) =~ s{[^/]+$}//; $f || "." };
+	
+	require DynaLoader;
+	our @ISA = 'DynaLoader';
+	
+	my $runtime = DynaLoader::dl_load_file(
+		ADADIR.'/libgnat.so',
+	) or die DynaLoader::dl_error();
+	
+	my $gep = DynaLoader::dl_find_symbol(
+		$runtime,
+		'__gnat_eh_personality',
+	) or die DynaLoader::dl_error();
+	
+	my $libref = DynaLoader::dl_load_file(
+		OURDIR.'/libgreeter.so',
+		0x01,
+	) or die DynaLoader::dl_error();
+	
+	my $func = DynaLoader::dl_find_symbol(
+		$libref,
+		'greeter__hello',
+	) or die DynaLoader::dl_error();
+
+	print $func, $/;
+}

File greeter.pl

-#!/usr/bin/env perl
-
-use 5.014;
-use strict;
-use warnings;
-
-#BEGIN { $ENV{PERL_DL_DEBUG} = 1 };
-
-package Greeter
-{
-	use constant ADADIR => '/usr/lib/gcc/x86_64-linux-gnu/4.4/rts-native/adalib/';
-	use constant OURDIR => do { (my $f = __FILE__) =~ s{[^/]+$}//; $f || "." };
-	
-	require DynaLoader;
-	our @ISA = 'DynaLoader';
-	
-	my $runtime = DynaLoader::dl_load_file(
-		ADADIR.'/libgnat.so',
-	) or die DynaLoader::dl_error();
-	
-	my $gep = DynaLoader::dl_find_symbol(
-		$runtime,
-		'__gnat_eh_personality',
-	) or die DynaLoader::dl_error();
-	
-	my $libref = DynaLoader::dl_load_file(
-		OURDIR.'/libgreeter.so',
-		0x01,
-	) or die DynaLoader::dl_error();
-	
-	my $func = DynaLoader::dl_find_symbol(
-		$libref,
-		'greeter__hello',
-	) or die DynaLoader::dl_error();
-
-	print $func, $/;
-}

File libgreeter.h

View file
+/* the library elaboration procedure */
+extern void greeterinit (void);
+
+/* the library finalization procedure */
+extern void greeterfinal (void);
+
+/* the interface exported by the library */
+extern void hello (void);