Last active
August 29, 2015 14:03
-
-
Save toyowata/eb46f8e5ba18ec7bc84e to your computer and use it in GitHub Desktop.
armccのプリプロセスファイルから展開されたシステムインクルードファイルを削除するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# | |
# Copyright 2010-2012 ARM Limited. All Rights Reserved. | |
# <[email protected]> | |
# shrink_sysinc.pl - tries to remove expanded system include file from preprocessed source code | |
# | |
# Usage: shrink_sysinc.pl test.ii > test.cpp | |
# TODO: | |
# matching patterns in pre-processed file: | |
# | |
# 1 "J:\\RVCT\\4.1\\713\\include\\rw/_defs.h" | |
# 12 "d:\\SDK\\test\\mneme\\precompiled\\precompiled.h" | |
#line 123 "C:\\RVCT\\4.1\\995\\include\\inttypes.h" | |
use File::Basename; | |
$nested = 0; | |
$mask = 0; | |
$inc_name = ""; | |
$inc_line = 0; | |
$once = 1; | |
$ARMCCINC = $ENV{'ARMCCINC'}; | |
if ($#ARGV == -1) | |
{ | |
print " shrink_sysinc.pl - Remove expanded system include file from a preprocessed source code\n"; | |
print " Usage: shrink_sysinc.pl test.ii > test.cpp\n"; | |
exit(0); | |
} | |
if ($ARMCCINC eq '') | |
{ | |
# if ARMCCINC environement variable is not set, you can hard code system include | |
# path here (forward match and case sensitive) | |
# e.g. $ARMCCINC = 'C:\RVCT\5.02\28\include'; | |
$ARMCCINC = 'J:\RVCT\5.03\102\include'; | |
} | |
# change single back-slash to be 4 (for regexp), since precompiled source has 2 | |
$ARMCCINC =~ s/\\/\\\\\\\\/g; | |
for ($i = 0; $i <= $#ARGV; $i++) { | |
open(IN, $ARGV[$i]); | |
while ($buf = <IN>) { | |
if ($buf =~ /^\#(line)* ([0-9]{1,10}) \"${ARMCCINC}.*\"/ ) { | |
if ($nested =! 0 && $once == 1) { | |
$mask = 1; | |
$once = 0; | |
$sys_inc = $buf; | |
$sys_inc =~ s/(^\#(line)* )([0-9]{1,10})( )(\"${ARMCCINC}.*)(\")/$5/g; | |
chomp($sys_inc); | |
$result = basename($sys_inc); | |
print "#include <$result>\n"; | |
} | |
} else { | |
if ($buf =~ /^\#(line)* ([0-9]{1,10}) \".*?\"/ ) { | |
$inc_name = $buf; | |
$inc_name =~ s/(^\#(line)* )([0-9]{1,10})( )(\".*?\")/$5/g; | |
$nested += 1; | |
$inc_line = 1; | |
print "// $buf"; | |
$once = 1; | |
} | |
} | |
if ( $mask == 1 ) { | |
if (index ($buf, $inc_name) != -1) { | |
$nested -= 1; | |
$mask = 0; | |
} | |
} | |
if ($mask == 0 && $inc_line == 0) { | |
print $buf; | |
} | |
$inc_line = 0; | |
} | |
close(IN); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment