Makefile.PL 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Net::ZooKeeper - Perl extension for Apache ZooKeeper
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. use 5.008_008;
  19. use Config;
  20. use ExtUtils::MakeMaker;
  21. use Getopt::Long;
  22. my $ZOO_MAJOR_VERSION = 3;
  23. my $ZOO_REQUIRED_VERSION = qr{^$ZOO_MAJOR_VERSION\.\d+.\d+$}ismx;
  24. my @zk_inc_paths;
  25. my @zk_lib_paths;
  26. my $with_sasl2 = 0;
  27. my @sasl2_inc_paths;
  28. my @sasl2_lib_paths;
  29. GetOptions(
  30. 'zookeeper-include=s' => \@zk_inc_paths,
  31. 'zookeeper-lib=s' => \@zk_lib_paths,
  32. 'with-sasl2!' => \$with_sasl2,
  33. 'sasl2-include=s' => \@sasl2_inc_paths,
  34. 'sasl2-lib=s' => \@sasl2_lib_paths
  35. );
  36. my $zk_inc = (join(' ', map("-I$_", @zk_inc_paths)) . ' -I.');
  37. my $zk_libs = (join(' ', map("-L$_", @zk_lib_paths)) . ' -lzookeeper_mt');
  38. my $cc = $Config{'cc'};
  39. my $check_file = 'build/check_zk_version';
  40. my $check_out = qx($cc $zk_inc -o $check_file $check_file.c $zk_libs 2>&1);
  41. if ($?) {
  42. if ($check_out =~ /zookeeper_version\.h/) {
  43. die("Could not determine ZooKeeper version:\n\n$check_out");
  44. }
  45. else {
  46. ## keep in sync with build/check_zk_version.h
  47. die("Net::ZooKeeper requires at least ZooKeeper version 3.1.1\n");
  48. }
  49. }
  50. chomp(my $zk_ver = qx($check_file));
  51. if ($? >> 8 != 0) {
  52. die "Couldn't check zookeeper version: $zk_ver: $r";
  53. }
  54. elsif ($zk_ver !~ $ZOO_REQUIRED_VERSION) {
  55. warn "Net::ZooKeeper requires ZooKeeper 3.x, found $zk_ver!";
  56. }
  57. my @inc = ($zk_inc);
  58. my @libs = ($zk_libs);
  59. my %mmopt = ();
  60. if ($with_sasl2) {
  61. push(@inc, join(' ', map("-I$_", @sasl2_inc_paths)));
  62. push(@libs, join(' ', map("-L$_", @sasl2_lib_paths)) . ' -lsasl2');
  63. $mmopt{DEFINE} = '-DHAVE_CYRUS_SASL_H';
  64. }
  65. WriteMakefile(
  66. 'INC' => join(' ', @inc),
  67. 'LIBS' => \@libs,
  68. 'NAME' => 'Net::ZooKeeper',
  69. 'VERSION_FROM' => 'ZooKeeper.pm',
  70. 'clean' => { 'FILES' => 'build/check_zk_version.o' },
  71. %mmopt,
  72. );