📄 getdep.pl
字号:
#! /usr/bin/env perl
#############################################################################
#
# G E T D E P
#
# GENERAL DESCRIPTION
# Process the output of the C preprocessor into a nice list of dependencies.
# The -M option on tcc works poorly, and can't handle an assembly file.
# The first argument is the name of our object file.
# The second object is the name of our source (needed for <stdin>
# replacement).
#
# INVOCATION
# perl getdep.pl file.o file.c
#
# Copyright (c) 1998 - 2002 by QUALCOMM Incorporated. All Rights Reserved.
#############################################################################
#
# EDIT HISTORY FOR FILE
#
# $PVCSPath: L:/src/asw/MSM6050/vcs/getdep.plv 1.1 10 Apr 2002 12:28:48 ropalsky $
# $Header: //depot/asic/MSMSHARED/tools/jnand/getdep.pl#1 $ $DateTime: 2003/02/06 15:47:46 $ $Author: pingguan $
#
# when who what, where, why
# -------- --- --------------------------------------------------------
# 02/06/03 pg Moved from ASWP402 server to ASWP401 server.
# 04/09/02 ro Support dependencies that are in the build's subdirectories
# 07/13/01 jmk Modified #line pattern matching string to accept leading
# whitespace as well
# 02/21/00 mt Changes for GNU make - put source as first dependency.
# 09/15/00 mt Change algorithm to remove dependencies on files that
# are not in the directory. Previous algorithm did not
# always remove them. Also, we now only want to remove
# dependencies that are .h files. This is because for
# internal RAM builds we have dependencies that are
# source files located in TARGETDIR.
# 06/20/00 jcw Changed TARGET to TARGETDIR since they can be different
# in MSM5000 builds
# 10/13/98 dlb Initial version.
#
#############################################################################
die "Usage: perl getdep.pl file.o file.c\n"
unless $#ARGV == 1;
$object = $ARGV[0];
$source = $ARGV[1];
# The object is probably of the form 'XXnnnn\name.o'. Fix this to be
# '$(TARGETDIR)\name.o'.
$object =~ s/^[A-Z0-9a-z]+\\/\$\(TARGETDIR\)\\/;
%deps = ();
while (<STDIN>) {
# Process lines that match "#line <num> "file"
next unless (/^\s*\#line\s+\d+\s+\"(.*)\"/);
# Fix up a few names.
$name = $1;
# replace "<stdin>" with the name of the source file
$name =~ s/\<stdin\>/$source/;
#print $name, "\n" if $name !~ /$source/;
# Save the dependencies excluding the source file
$deps{$name} = 1 if $name !~ /$source/;
}
# Tricky stuff. Need to remove any dependencies on .h files that are not
# present in this directory. This indicates that it probably came
# from a -I.
#
# This is needed due to stupidity in the ARM compiler to not output
# paths on the #line directives.
# Print out the dependencies, with the C source being the first.
print "$object: $source\n";
for $name (sort keys %deps) {
# To really remove .h files that are not in this directory, we must
# strip $name of its path. This is because statements such as
# #include "string.h" preprocesses to
# #include "c:\apps\ads100\INCLUDE\string.h" and the -f $name test
# fails because $name becomes "c:\apps\ads100\INCLUDE\string.h" and this
# file exists. This happens in cases where source files use
# #include "string.h" instead of #include <string.h> or in *_.c sources
# (preprocessed files generated by csplit.pl) where the
# #include <string.h> in the original source file preprocesses to
# #include "string.h" which in turn preprocesses to
# #include "c:\apps\ads100\INCLUDE\string.h."
# $name =~ s/.*\\(\w+\.h)/$1/i;
# Strip the drive letter and/or any leading '\' from the path
# if it is present.
if (($name =~ /^\s*[a-zA-Z]:\\(.*\\\w+\.h)\s*$/) ||
($name =~ /^\s*\\(.*\\\w+\.h)\s*$/))
{
$name = $1;
}
# Does the file exist in this directory tree?
next unless -f $name;
print "$object: $name\n";
}
###########################################################################
# End of Perl script.
###########################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -