DBD-SQLite

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

					ExtUtils::MM_Unix->maybe_command($file);
				}
			}
		}
	}

	sub can_run {
		my $cmd = shift;
		my $_cmd = $cmd;
		return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));

		for my $dir ( (split /$Config::Config{path_sep}/, $ENV{PATH}), '.' ) {
			next if $dir eq '';
			my $abs = File::Spec->catfile($dir, $_[1]);
			return $abs if (-x $abs or $abs = MM->maybe_command($abs));
		}

		return;
	}

	sub can_cc {
		my @chunks = split(/ /, $Config::Config{cc}) or return;

		# $Config{cc} may contain args; try to find out the program part
		while ( @chunks ) {
			return can_run("@chunks") || (pop(@chunks), next);
		}

		return;
	}

	unless ( can_cc() ) {
		print "We can't locate a C compiler from your Config.pm.\n";
		exit(0);
	}
}

# Determine if we are going to use the provided SQLite code, or an already-
# installed copy. To this end, look for two command-line parameters:
#
#    USE_LOCAL_SQLITE -- If non-false, force use of the installed version
#    SQLITE_LOCATION  -- If passed, look for headers and libs under this root
#
# In absense of either of those, expect SQLite 3.X.X libs and headers in the
# common places known to Perl or the C compiler.
# 
# Note to Downstream Packagers:
# This block is if ( 0 ) to discourage casual users building against
# the system SQLite. We expect that anyone sophisticated enough to use
# a system sqlite is also sophisticated enough to have a patching system
# that can change the if ( 0 ) to if ( 1 )
my ($sqlite_local, $sqlite_base, $sqlite_lib, $sqlite_inc);
if ( 0 ) {
	require File::Spec;
	if ( $sqlite_base = (grep(/SQLITE_LOCATION=.*/, @ARGV))[0] ) {
		$sqlite_base =~ /=(.*)/;
		$sqlite_base = $1;
		$sqlite_lib = File::Spec->catdir( $sqlite_base, 'lib'     );
		$sqlite_inc = File::Spec->catdir( $sqlite_base, 'include' );
	}
	if ( $sqlite_local = (grep(/USE_LOCAL_SQLITE=.*/, @ARGV))[0] ) {
		$sqlite_local =~ /=(.*)/;
		$sqlite_local = "$1" ? 1 : 0;
		if ( $sqlite_local ) {
			# Keep these from making into CFLAGS/LDFLAGS
			undef $sqlite_lib;
			undef $sqlite_inc;
		}
	}
	if ( my $my_inc = (grep /SQLITE_INC=.*/, @ARGV)[0] ) {
		$my_inc =~ /=(.*)/;
		$sqlite_inc = $1;
	}
	if ( my $my_lib = (grep /SQLITE_LIB=.*/, @ARGV)[0] ) {
		$my_lib =~ /=(.*)/;
		$sqlite_lib = $1;
	}

	# Now check for a compatible sqlite3
	unless ( $sqlite_local ) {
		my ($dir, $file, $fh, $version);
		print "Checking installed SQLite version...\n" if $ENV{AUTOMATED_TESTING};
		if ( $sqlite_inc ) {
			open($fh, '< ' , File::Spec->catfile($sqlite_inc, 'sqlite3.h'))
				or die "Error opening sqlite3.h in $sqlite_inc: $!";
			while ( defined($_ = <$fh>) ) {
				if (/\#define\s+SQLITE_VERSION_NUMBER\s+(\d+)/) {
					$version = $1;
					last;
				}
			}
			close($fh);
		} else {
			# Go hunting for the file (Matt: Add more dirs here as you see fit)
			foreach $dir ( [ qw(usr include) ], [ qw(usr local include) ] ) {
				$file = File::Spec->catfile('', @$dir, 'sqlite3.h');
				next unless (-f $file);
				open($fh, "<", $file) or die "Error opening $file: $!";
				while ( defined($_ = <$fh>) ) {
					if (/\#define\s+SQLITE_VERSION_NUMBER\s+(\d+)/) {
						$version = $1;
						last;
					}
				}
				close($fh);
				last if $version;
			}
		}
		unless ( $version && ($version >= 3006000) ) {
			warn "SQLite version must be at least 3.6.0. No header file at that\n";
			warn "version or higher was found. Using the local version instead.\n";
			$sqlite_local = 1;
			undef $sqlite_lib;
			undef $sqlite_inc;
		} else {
			print "Looks good\n" if $ENV{AUTOMATED_TESTING};
		}
	}
} else {
	# Always the bundled one.
	# XXX: ... and this message should be more informative.



( run in 1.297 second using v1.01-cache-2.11-cpan-5837b0d9d2c )