File: esqlcc

package info (click to toggle)
libdbd-informix-perl 2003.04-3
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k, sarge
  • size: 1,232 kB
  • ctags: 467
  • sloc: perl: 7,349; ansic: 5,340; sh: 184; makefile: 58
file content (91 lines) | stat: -rwxr-xr-x 2,368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl -w
#
# @(#)$Id: esqlcc,v 100.3 2002/11/20 19:05:09 jleffler Exp $ 
#
# DBD::Informix for Perl Version 5
#
# Surrogate C Compiler for Informix ESQL/C versions 4.10.UC1 upwards
#
# Copyright 1996-98 Jonathan Leffler
# Copyright 2002    IBM
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.

# NB: Uses esqlsed script

@ARGS = ();
$libs = 1;

sub firstline
{
	my ($file) = @_;
	my ($line) = `sed 1q $file`;
	chomp $line;
	$line;
}

# Cannot use for $arg (@ARGV) because of '-[Ll] name' processing!
for ($i = 0; $i < @ARGV; $i++)
{
	$arg = $ARGV[$i];
	if ($arg =~ /^[^-].*\.c$/o)
	{
		# C file
		# Use $^X rather than perl to avoid problems with
		# inappropriate versions of perl in system directories
		# (Roderick Schertler <roderick@argon.org> 1999-07-25).
		system "$^X esqlsed $arg"
			if (-w $arg && &firstline($arg) eq "#include <sqlhdr.h>");
		push @ARGS, $arg;
	}
	elsif ($arg =~ /^-c$/o)
	{
		# -c option (no linking)
		$libs = 0;
		push @ARGS, $arg;
	}
	elsif ($arg =~ /^[^-].*\.[ao]$/o)
	{
		# Object file or archive library specified by name
		push @ARGS, $arg if ($libs);
	}
	elsif ($arg =~ /^-[lL].+/o)
	{
		# -lname or -Ldirectory -- not wanted if no libraries
		push @ARGS, $arg if ($libs);
	}
	elsif ($arg =~ /^-[lL]$/o)
	{
		# -l name or -L directory -- not wanted if no libraries
		push @ARGS, $arg if ($libs);
		$arg = $ARGV[++$i];
		push @ARGS, $arg if ($libs);
	}
	else
	{
		# Copy argument to new argument list
		push @ARGS, $arg;
	}
}

# Generalization of DBD_INFORMIX_ESQLLD_NO_G_OPTION...
if ($ENV{DBD_INFORMIX_ESQLCC_REMOVE_OPTIONS_REGEX})
{
	my($env) = $ENV{DBD_INFORMIX_ESQLCC_REMOVE_OPTIONS_REGEX};
	print STDERR "# DBD_INFORMIX_ESQLCC_REMOVE_OPTIONS_REGEX set.\n";
	print STDERR "# Removing options that match regex m%$env%\n";
	print STDERR "# Before: @ARGS\n" if $ENV{DBD_INFORMIX_DEBUG_ESQLCC};
	@ARGS = grep { !m%$env%o } @ARGS;
	print STDERR "# After: @ARGS\n" if $ENV{DBD_INFORMIX_DEBUG_ESQLCC};
}

# Sort out the real compiler.
# Note that if $ENV{ESQLCC} contains, for example, 'cc -G', then we
# need to split this into two words for the exec to work correctly.
$cmd = $ENV{ESQLCC};
$cmd = 'cc' unless ($cmd);
@cmd = split /\s+/, $cmd;

print STDERR "@cmd @ARGS\n" if $ENV{DBD_INFORMIX_DEBUG_ESQLCC};
exec @cmd, @ARGS;