view tools/find-gcc-include-path @ 894:989bdd85e8af

a little better zfill
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 06 Apr 2014 16:02:30 +0900
parents c005a392e27e
children
line wrap: on
line source

#!/usr/bin/perl

my $CC = $ARGV[1];
my $gcc = `echo '#include <stdio.h>' | $CC -E - `;

$gcc =~ m=\"(/[^"]+/)stdio\.h"=;
my $gcc_path = $1;

my $gcc1 = `echo '#include <stddef.h>' | $CC -E - `;

$gcc1 =~ m=\"(/[^"]+/)stddef\.h"=;
my $gcc_path1 = $1;

my $path = <<EOF;
    "$gcc_path",
EOF
if ($gcc_path1 ne $gcc_path) {
 $path = <<EOF;
    "$gcc_path",
    "$gcc_path1",
EOF
}

if ($ARGV[0]=~/-l/) {
print <<EOF
char *l_include_path[] = {
$path
    "/usr/include/",
    0
};
EOF
} elsif ($ARGV[0]=~/-s/) {
   open my $fd, "<", "stdio.template" or die("can't open stdio.template");
   my $repl = 1;
   while(<$fd>) {
      if ($repl && /\#include \"\/usr\/include\/stdio.h\"/) {
          print "#include \"${gcc_path}stdio.h\"\n";
          $repl = 0;
          next;
      }
      print;
   }
} else {
	print "$gcc_path\n";
}