#!@l_prefix@/bin/perl

my $cc       = '@CC@';
my $cflags   = '@CFLAGS@';
my $cppflags = '@CPPFLAGS@';
my $ldflags  = '@LDFLAGS@';

my @args = ();
my @incs = ();
my @libs = ();

for (my $i = 0; $i < @ARGV; $i++) {
    if ($ARGV[$i] eq "-I") {
        push(@incs, $ARGV[$i++]);
        push(@incs, $ARGV[$i]);
    }
    elsif ($ARGV[$i] =~ m/^-I.+/) {
        push(@incs, $ARGV[$i])
    }
    elsif ($ARGV[$i] eq "-L") {
        push(@libs, $ARGV[$i++]);
        push(@libs, $ARGV[$i]);
    }
    elsif ($ARGV[$i] =~ m/^-L.+/) {
        push(@libs, $ARGV[$i])
    }
    else {
        push(@args, $ARGV[$i])
    }
}

my @ARGV = ($cc);
foreach my $arg (split(/\s+/, $cflags)) {
    push(@ARGV, $arg)
}
foreach my $arg (@incs) {
    push(@ARGV, $arg)
}
foreach my $arg (split(/\s+/, $cppflags)) {
    push(@ARGV, $arg)
}
foreach my $arg (@libs) {
    push(@ARGV, $arg)
}
foreach my $arg (split(/\s+/, $ldflags)) {
    push(@ARGV, $arg)
}
foreach my $arg (@args) {
    push(@ARGV, $arg)
}

exec { $ARGV[0] } @ARGV;

