#!/usr/bin/gawk -f
#***************************************************************************************************
# *
# makeDependencies.awk: generate dependency files for sources that include other files. *
# For example texinfo file with the "@include" command. *
# *
#***************************************************************************************************
#***************************************************************************************************
# *
# Copyright (C) 2003 Joerg Kunze *
# *
# This file is part of siliconBrain. *
# *
# siliconBrain is free software; you can redistribute it and/or modify *
# it under the terms of the GNU General Public License as published by *
# the Free Software Foundation; either version 2 of the License, or *
# (at your option) any later version. *
# *
# siliconBrain is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU General Public License for more details. *
# *
# You should have received a copy of the GNU General Public License *
# along with this program; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
# *
#***************************************************************************************************
#***************************************************************************************************
# *
# BEGIN: just print some relase information. *
# *
#***************************************************************************************************
BEGIN {
siliconBrainRelease = "$siliconBrainRelease: 0.2.3 $"
siliconBrainRcsIdentifier = "$Id: makeDependencies.awk,v 1.27 2004/12/14 23:31:26 joerg Exp $"
siliconBrainSaveStamp = "$siliconBrainSaveStamp: 2004/12/14 22:25:50, Joerg Kunze$"
#------------------------------------------------------#
# collect all *.texinfo files found in the source tree #
#------------------------------------------------------#
findCommand = "find * -name \"*.texinfo\" | grep -v \"CVS\""
while( (findCommand | getline) > 0 )
potentialIncludes[ substr( $0, match( $0, "[^/]*$" )) ] = $0
close( findCommand )
}
#***************************************************************************************************
# *
# collectBaseFiles: look for ``@include'' statments and then read the included files. *
# *
#***************************************************************************************************
function collectBaseFiles( fileName, baseFiles ) {
#--------------------------------------#
# prevent reread of alread read mfiles #
#--------------------------------------#
if( !baseFiles[ fileName ] ) {
baseFiles[ fileName ] = 1
if( !potentialIncludes[ fileName ] )
potentialIncludes[ fileName ] = fileName
while( (getline line < potentialIncludes[ fileName ]) > 0) {
if( line ~ /^ *@include / ) {
split( line, parts, " " )
#------------------------------------------------#
# recursion: redo our task for the included file #
#------------------------------------------------#
collectBaseFiles( parts[ 2 ], baseFiles )
}
}
}
}
#***************************************************************************************************
# *
# /include/ *
# *
#***************************************************************************************************
/^ *@include / {
collectBaseFiles( $2, baseFiles )
}
#***************************************************************************************************
# *
# getIdentifierValue: *
# *
#***************************************************************************************************
function getIdentifierValue( source ) {
match( source, /\$.*\$/ )
return substr( source, RSTART, RLENGTH )
}
#***************************************************************************************************
# *
# /versionIdentifier/ *
# *
#***************************************************************************************************
/\$siliconBrainRelease:/ {
sourceRelease = getIdentifierValue( $0 )
}
/\$Id:/ {
sourceRcsId = getIdentifierValue( $0 )
}
/\$siliconBrainSaveStamp:/ {
sourceSaveStamp = getIdentifierValue( $0 )
}
#***************************************************************************************************
# *
# END: create the ``make'' dependency rule. *
# *
#***************************************************************************************************
END {
#-----------------------------------------------------#
# generate the copying notice and version information #
#-----------------------------------------------------#
formatCommand = \
"formatHeader \"#\" " \
"\""sourceRelease"\" " \
"\""sourceRcsId"\" " \
"\""sourceSaveStamp"\" " \
"\"a texinfo dependency file\" " \
"\""siliconBrainRelease"\" " \
"\""siliconBrainRcsIdentifier"\" " \
"\""siliconBrainSaveStamp"\" 2> /dev/null"
# we need to prefix escape the $'s with \'s because else the shell will interpret them #
gsub( /\$/, "\\$", formatCommand )
fflush()
system( formatCommand )
#---------------------------#
# print the dependency rule #
#---------------------------#
rule = target ":"
for( baseFile in baseFiles )
rule = rule " " potentialIncludes[ baseFile ]
print rule
}
# $Log: makeDependencies.awk,v $
# Revision 1.27 2004/12/14 23:31:26 joerg
# published for new release 0.2.3
#
# Revision 1.26 2004/12/14 23:17:05 joerg
# published for new release 0.2.2
#
# Revision 1.25 2004/12/14 22:42:23 joerg
# allFiles: all sources have a Log CVS keyword at the end now.
#