/build-extras/2008.1-odin/DBD-DB2.Makefile.PL

https://code.google.com/p/camelbox/ · Perl · 178 lines · 139 code · 26 blank · 13 comment · 14 complexity · d575956a40d36f0ef2f5c08e0a23e922 MD5 · raw file

  1. # engn/perldb2/Makefile.PL, engn_perldb2, db2_v82fp9, 1.11 04/09/14 10:47:41
  2. #
  3. # Copyright (c) 1995-2004 International Business Machines Corp.
  4. #
  5. #!/usr/local/bin/perl -sw
  6. use ExtUtils::MakeMaker qw(&WriteMakefile $Verbose );
  7. use Getopt::Std;
  8. use Config;
  9. require 'flush.pl';
  10. use DBI; # The DBI must be installed before we can build a DBD
  11. my %opts = (
  12. 'NAME' => 'DBD::DB2',
  13. 'VERSION_FROM' => 'DB2.pm',
  14. ($] ge '5.005')
  15. ? ( 'AUTHOR' => 'DB2 Perl (db2perl@ca.ibm.com)',
  16. 'ABSTRACT' => 'Perl driver for IBM DB2 Universal Database', )
  17. : (),
  18. ( $Config{archname} =~ /-object\b/i )
  19. ? ( 'CAPI' => 'TRUE', )
  20. : (),
  21. 'OBJECT' => '$(O_FILES)',
  22. );
  23. # --- Introduction
  24. print "\nConfiguring DBD::DB2...\n";
  25. print "Remember to actually read the README and CAVEATS files!\n\n";
  26. # --- Operating system
  27. my $os = $^O;
  28. # --- Where is DB2 installed...
  29. my $envvar = 'DB2_HOME';
  30. my $DB2 = $ENV{$envvar};
  31. if( not $DB2 )
  32. {
  33. $envvar = 'DB2PATH';
  34. $DB2 = $ENV{$envvar};
  35. }
  36. if( not $DB2 )
  37. {
  38. my ($pathsep, $path, @pathlist);
  39. $pathsep = $Config{'path_sep'};
  40. $pathsep = ':' unless $pathsep;
  41. $path = $ENV{'PATH'};
  42. $path =~ s:\\:/:g if $pathsep eq ';';
  43. @pathlist = split /$pathsep/, $path;
  44. foreach $path (@pathlist)
  45. {
  46. if( lc( substr( $path, -4 ) ) eq '/bin' &&
  47. -f "$path/../include/sqlcli.h" )
  48. {
  49. $DB2 = substr( $path, 0, -4 );
  50. last;
  51. }
  52. }
  53. }
  54. $DB2 =~ s:\\:/:g if $os eq 'MSWin32' || $os eq 'MSWin64' || $os eq 'os2';
  55. $DB2 =~ s/"//g;
  56. die "DB2_HOME environment variable must be set to installed location of DB2.\n"
  57. unless $DB2;
  58. die "$envvar environment variable ($DB2) not valid.\n" unless -d $DB2;
  59. print qq(Using DB2 in "$DB2"\n);
  60. # --- Setup include paths and libraries
  61. $opts{INC} .= qq(-I"$DB2/include" -I"$Config{sitearch}/auto/DBI" );
  62. $opts{INC} .= qq(-I"$Config{vendorarch}/auto/DBI") if $Config{vendorarch};
  63. $opts{dynamic_lib} = { OTHERLDFLAGS => '$(COMPOBJS) '};
  64. # libraries required to build DBD::DB2 driver
  65. if( $os eq 'MSWin32' || $os eq 'MSWin64' || $os eq 'os2' )
  66. {
  67. my $DB2LIB = $ENV{'DB2LIB'};
  68. if( not $DB2LIB )
  69. {
  70. if (-e "$DB2/lib64")
  71. {
  72. $DB2LIB = "$DB2/lib64";
  73. }
  74. else
  75. {
  76. if (-e "$DB2/lib32")
  77. {
  78. $DB2LIB = "$DB2/lib32";
  79. }
  80. else
  81. {
  82. $DB2LIB = "$DB2/lib";
  83. }
  84. }
  85. }
  86. $sysliblist = qq(-L"$DB2LIB" db2cli.lib db2api.lib);
  87. my @libpaths = split /;/, $ENV{'LIB'};
  88. my $libpath;
  89. while( @libpaths )
  90. {
  91. ( $libpath = shift(@libpaths) ) =~ s/"//g; # Remove quotes
  92. $libpath =~ s:\\:/:g;
  93. if( $libpath && $sysliblist !~ /-L"$libpath"/i )
  94. {
  95. $sysliblist .= qq( -L"$libpath");
  96. }
  97. }
  98. }
  99. else
  100. {
  101. my $DB2LIB = $ENV{'DB2LIB'};
  102. if( not $DB2LIB )
  103. {
  104. if (-e "$DB2/lib64")
  105. {
  106. $DB2LIB = "$DB2/lib64";
  107. }
  108. else
  109. {
  110. if (-e "$DB2/lib32")
  111. {
  112. $DB2LIB = "$DB2/lib32";
  113. }
  114. else
  115. {
  116. $DB2LIB = "$DB2/lib";
  117. }
  118. }
  119. }
  120. $sysliblist = "-L$DB2LIB -ldb2";
  121. }
  122. # --- Handle special cases ---
  123. if ($os eq 'hpux')
  124. {
  125. $sysliblist .= ' -lcl';
  126. $opts{DEFINE} .= ' +e';
  127. }
  128. #Defining a macro to fix the compile issue in DBD::DB2
  129. #which was due to change in definition of DBIc_CACHED_KIDS in DBIv1.55
  130. #if( $DBI::VERSION > 1.54 )
  131. if( "$DBI::VERSION" ge "1.55" )
  132. {
  133. $opts{DEFINE} .= ' -DDB2_CACHE_FIX ';
  134. }
  135. $opts{LIBS} = [ $sysliblist ];
  136. # log key platform information to help me help you quickly
  137. print "System: perl$] DBI$DBI::VERSION @Config{qw(myuname archname dlsrc)}\n";
  138. print "Compiler: @Config{qw(cc optimize ccflags)}\n";
  139. print "Includes: $opts{INC}\n";
  140. print "Libraries: @{$opts{LIBS}}\n";
  141. print "\n";
  142. WriteMakefile(%opts);
  143. exit 0;
  144. sub MY::post_initialize{
  145. '
  146. default_target: all
  147. ';
  148. }
  149. __END__