# This is an awk script which does dependencies. We do NOT want it to
|
# This is an awk script which does dependencies. We do NOT want it to
|
# recursively follow #include directives.
|
# recursively follow #include directives.
|
#
|
#
|
# The HPATH environment variable should be set to indicate where to look
|
# The HPATH environment variable should be set to indicate where to look
|
# for include files. The -I in front of the path is optional.
|
# for include files. The -I in front of the path is optional.
|
|
|
#
|
#
|
# Surely there is a more elegant way to see if a file exists. Anyone know
|
# Surely there is a more elegant way to see if a file exists. Anyone know
|
# what it is?
|
# what it is?
|
#
|
#
|
function fileExists(f, TMP, dummy, result) {
|
function fileExists(f, TMP, dummy, result) {
|
if(result=FILEHASH[f]) {
|
if(result=FILEHASH[f]) {
|
if(result=="Yes") {
|
if(result=="Yes") {
|
return "Yes"
|
return "Yes"
|
} else {return ""}
|
} else {return ""}
|
}
|
}
|
ERRNO = getline dummy < f
|
ERRNO = getline dummy < f
|
if(ERRNO >= 0) {
|
if(ERRNO >= 0) {
|
close(f)
|
close(f)
|
return FILEHASH[f]="Yes"
|
return FILEHASH[f]="Yes"
|
} else {
|
} else {
|
FILEHASH[f]="No"
|
FILEHASH[f]="No"
|
return ""
|
return ""
|
}
|
}
|
}
|
}
|
|
|
function endfile(f) {
|
function endfile(f) {
|
if (hasconfig && !needsconfig) {
|
if (hasconfig && !needsconfig) {
|
printf "%s doesn't need config\n",f > "/dev/stderr"
|
printf "%s doesn't need config\n",f > "/dev/stderr"
|
}
|
}
|
if (hasdep) {
|
if (hasdep) {
|
print cmd
|
print cmd
|
}
|
}
|
}
|
}
|
|
|
BEGIN{
|
BEGIN{
|
hasdep=0
|
hasdep=0
|
hasconfig=0
|
hasconfig=0
|
needsconfig=0
|
needsconfig=0
|
incomment=0
|
incomment=0
|
if(!(TOPDIR=ENVIRON["TOPDIR"])) {
|
if(!(TOPDIR=ENVIRON["TOPDIR"])) {
|
print "Environment variable TOPDIR is not set"
|
print "Environment variable TOPDIR is not set"
|
exit 1
|
exit 1
|
}
|
}
|
split(ENVIRON["HPATH"],parray," ")
|
split(ENVIRON["HPATH"],parray," ")
|
for(path in parray) {
|
for(path in parray) {
|
sub("^-I","",parray[path])
|
sub("^-I","",parray[path])
|
sub("[/ ]*$","",parray[path])
|
sub("[/ ]*$","",parray[path])
|
}
|
}
|
}
|
}
|
|
|
# eliminate comments
|
# eliminate comments
|
{
|
{
|
# remove all comments fully contained on a single line
|
# remove all comments fully contained on a single line
|
gsub("\\/\\*.*\\*\\/", "")
|
gsub("\\/\\*.*\\*\\/", "")
|
if (incomment) {
|
if (incomment) {
|
if ($0 ~ /\*\//) {
|
if ($0 ~ /\*\//) {
|
incomment = 0;
|
incomment = 0;
|
gsub(".*\\*\\/", "")
|
gsub(".*\\*\\/", "")
|
} else {
|
} else {
|
next
|
next
|
}
|
}
|
} else {
|
} else {
|
# start of multi-line comment
|
# start of multi-line comment
|
if ($0 ~ /\/\*/)
|
if ($0 ~ /\/\*/)
|
{
|
{
|
incomment = 1;
|
incomment = 1;
|
sub("\\/\\*.*", "")
|
sub("\\/\\*.*", "")
|
} else if ($0 ~ /\*\//) {
|
} else if ($0 ~ /\*\//) {
|
incomment = 0;
|
incomment = 0;
|
sub(".*\\*\\/", "")
|
sub(".*\\*\\/", "")
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/^[ ]*#[ ]*if.*[^A-Za-z_]CONFIG_/ {
|
/^[ ]*#[ ]*if.*[^A-Za-z_]CONFIG_/ {
|
needsconfig=1
|
needsconfig=1
|
if (!hasconfig) {
|
if (!hasconfig) {
|
printf "%s needs config but has not included config file\n",FILENAME > "/dev/stderr"
|
printf "%s needs config but has not included config file\n",FILENAME > "/dev/stderr"
|
# only say it once per file..
|
# only say it once per file..
|
hasconfig = 1
|
hasconfig = 1
|
}
|
}
|
}
|
}
|
|
|
/^[ ]*#[ ]*include[ ]*[<"][^ ]*[>"]/{
|
/^[ ]*#[ ]*include[ ]*[<"][^ ]*[>"]/{
|
found=0
|
found=0
|
if(LASTFILE!=FILENAME) {
|
if(LASTFILE!=FILENAME) {
|
endfile(LASTFILE)
|
endfile(LASTFILE)
|
hasdep=0
|
hasdep=0
|
hasconfig=0
|
hasconfig=0
|
needsconfig=0
|
needsconfig=0
|
incomment=0
|
incomment=0
|
cmd=""
|
cmd=""
|
LASTFILE=FILENAME
|
LASTFILE=FILENAME
|
depname=FILENAME
|
depname=FILENAME
|
relpath=FILENAME
|
relpath=FILENAME
|
sub("\\.c$",".o: ",depname)
|
sub("\\.c$",".o: ",depname)
|
sub("\\.S$",".o: ",depname)
|
sub("\\.S$",".o: ",depname)
|
if (depname==FILENAME) {
|
if (depname==FILENAME) {
|
cmd="\n\t@touch "depname
|
cmd="\n\t@touch "depname
|
}
|
}
|
sub("\\.h$",".h: ",depname)
|
sub("\\.h$",".h: ",depname)
|
if(relpath ~ "^\\." ) {
|
if(relpath ~ "^\\." ) {
|
sub("[^/]*$","", relpath)
|
sub("[^/]*$","", relpath)
|
relpath=relpath"/"
|
relpath=relpath"/"
|
sub("//","/", relpath)
|
sub("//","/", relpath)
|
} else {
|
} else {
|
relpath=""
|
relpath=""
|
}
|
}
|
}
|
}
|
fname=$0
|
fname=$0
|
sub("^#[ ]*include[ ]*[<\"]","",fname)
|
sub("^#[ ]*include[ ]*[<\"]","",fname)
|
sub("[>\"].*","",fname)
|
sub("[>\"].*","",fname)
|
if (fname=="linux/config.h") {
|
if (fname=="linux/config.h") {
|
hasconfig=1
|
hasconfig=1
|
}
|
}
|
rfname=relpath""fname
|
rfname=relpath""fname
|
if(fileExists(rfname)) {
|
if(fileExists(rfname)) {
|
found=1
|
found=1
|
if (!hasdep) {
|
if (!hasdep) {
|
printf "%s", depname
|
printf "%s", depname
|
}
|
}
|
hasdep=1
|
hasdep=1
|
printf " \\\n %s", rfname
|
printf " \\\n %s", rfname
|
if(fname ~ "^\\." ) {
|
if(fname ~ "^\\." ) {
|
fnd=0;
|
fnd=0;
|
for(i in ARGV) {
|
for(i in ARGV) {
|
if(ARGV[i]==rfname) {
|
if(ARGV[i]==rfname) {
|
fnd=1
|
fnd=1
|
}
|
}
|
}
|
}
|
if(fnd==0) {
|
if(fnd==0) {
|
ARGV[ARGC]=rfname
|
ARGV[ARGC]=rfname
|
++ARGC
|
++ARGC
|
}
|
}
|
}
|
}
|
} else {
|
} else {
|
for(path in parray) {
|
for(path in parray) {
|
if(fileExists(parray[path]"/"fname)) {
|
if(fileExists(parray[path]"/"fname)) {
|
shortp=parray[path]
|
shortp=parray[path]
|
found=1
|
found=1
|
if (!hasdep) {
|
if (!hasdep) {
|
printf "%s", depname
|
printf "%s", depname
|
}
|
}
|
hasdep=1
|
hasdep=1
|
printf " \\\n %s", parray[path]"/"fname
|
printf " \\\n %s", parray[path]"/"fname
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
END{
|
END{
|
endfile(FILENAME)
|
endfile(FILENAME)
|
}
|
}
|
|
|