]> git.imager.perl.org - imager.git/commitdiff
probe test code for FT2, including extending Imager::Probe and
authorTony Cook <tony@develop=help.com>
Sun, 26 Sep 2010 01:17:53 +0000 (01:17 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 26 Sep 2010 01:17:53 +0000 (01:17 +0000)
Devel::CheckLib to allow prologue code

FT2/Makefile.PL
inc/Devel/CheckLib.pm
lib/Imager/Probe.pm

index fc191364a37760febfb0fd9015dee3a3ba86a6ef..fbaae50e191a64dd5ca11c77c2f52a1a77c6307d 100644 (file)
@@ -81,6 +81,7 @@ my %probe =
    libbase => "freetype",
    testcode => _ft2_test_code(),
    testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
+   testcodeprologue => _ft2_test_code_prologue(),
    incpath => join($Config{path_sep}, @incpaths),
    libpath => join($Config{path_sep}, @libpaths),
    alternatives =>
@@ -120,10 +121,30 @@ else {
 
 sub _ft2_test_code {
   return <<'CODE';
+FT_Library library = 0;
+FT_Face face = 0;
+FT_Error error;
+error = FT_Init_FreeType(&library);
+if (error) {
+  fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
+  return 1;
+}
+error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
+if (error) {
+  fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
+  return 1;
+}
 return 0;
 CODE
 }
 
+sub _ft2_test_code_prologue {
+  return <<'CODE';
+#include FT_FREETYPE_H
+
+CODE
+}
+
 sub is_exe {
   my ($name) = @_;
 
index 9d02547f2e25d6a1d10f7def543f0e7ed0ca9db5..57cc8e6dc3d7cfba6f1913d2e1601b76dcb17dba 100644 (file)
@@ -138,6 +138,23 @@ This can also be supplied on the command-line.
 
 =back
 
+If you need to perform know more than "does it link?" you can provide
+code to be compiled and run:
+
+=over
+
+=item function
+
+the body of the <main()> function.  If not provided C<return 0;> is
+used.
+
+=item prologue
+
+code to insert between the C<#include> of the headers and the
+definition of main.
+
+=back
+
 =head2 check_lib_or_exit
 
 This behaves exactly the same as C<assert_lib()> except that instead of
@@ -281,6 +298,7 @@ sub assert_lib {
         'assertlibXXXXXXXX', SUFFIX => '.c'
     );
     print $ch qq{#include <$_>\n} foreach (@headers);
+    print $ch "\n$args{prologue}\n" if $args{prologue};
     print $ch "int main(void) { ".($args{function} || 'return 0;')." }\n";
     close($ch);
     for my $link_cfg ( @link_cfgs ) {
index a307deb97c8d721554f9691315df75926c048833..06123f1e0fa51aca5b0e7bb7cb311501fd4bc1ca 100644 (file)
@@ -248,6 +248,7 @@ sub _probe_test {
         INC => $result->{INC},
         header => $req->{testcodeheaders},
         function => $req->{testcode},
+        prologue => $req->{testcodeprologue},
        );
   unless ($good) {
     print "$req->{name}: Test code failed: $@";
@@ -438,6 +439,11 @@ need to set C<testcodeheaders>.
 
 =item *
 
+C<testcodeprologue> - C code to insert between the headers and the
+main function.
+
+=item *
+
 C<incpath> - C<$Config{path_sep}> separated list of header file
 directories to check.