hsk-libs-scripts  270
High Speed Karlsruhe XC878 build scripts
Functions
depends.awk File Reference

Creates a list of dependencies for compiling or linking. More...

Functions

var testf (var file)
 Tests whether a file can be opened. More...
 
var rescape (var str)
 Escape the given string for literal use in a regular expression. More...
 
var sescape (var str)
 Escape the given string for command line use. More...
 
var extract (var a)
 Returns an arbitrary index from an array and deletes it. More...
 
var any (var a)
 Returns whether any of the entries in a given array evalutate to true. More...
 
var compact (var path)
 Returns a compacted version of the path. More...
 
void filter184 ()
 Perform recursive include and output C/C++ file names. More...
 

Detailed Description

Creates a list of dependencies for compiling or linking.

The command line arguments are used to produce a CPP command. The given files need to be processed by CPP in order to make sure macros and conditionals are (correctly) expanded.

The output is filtered to only print files in the same directory or subdirectories of the given file. Paths can be added explicitly by using the -I argument.

The following arguments receive special treatment:

Argument Description
-compile Choose to produce a dependency list for compiling
-link Choose to produce a dependency list for linking
-I<path> Paths are added to the output filter

Modes of Operation

The script can either create a dependency list for compiling or linking.

In any mode the given file (multiple files can be chosen as well, but there is no useful use case) is passed to the CPP. The CPP resolves all includes.

The includes are filtered from the CPP output by this script.

In compile mode all files and includes are output once. In link mode includes are instead checked for heaving a corresponding C/C++ file that ends with the suffix SUFX. Only in that case is the file name printed and also recursively passed to the CPP.

Modes can be combined.

Environment

If the following arguments are not set using AWK's -v argument, they can be set as environment variables.

Variable Description
DEBUG If set output debugging information on stderr
CPP The C/C++ preprocessor command, defaults to cpp
SUFX The file name suffix for c/c++ files

SUFX

The SUFX variable defaults to the file ending of the first file name given in the arguments.

Non-existing files are ignored during list-creation, this can be used to set the file ending by providing the desired file ending as the first argument:

    awk -f depends.awk .c -link <file>

Function Documentation

§ testf()

var testf ( var  file)

Tests whether a file can be opened.

Parameters
fileThe name of the file to test
Return values
1The file exists and can be read
0The file cannot be opened

§ rescape()

var rescape ( var  str)

Escape the given string for literal use in a regular expression.

Parameters
strThe string to escape
Returns
The escaped string

§ sescape()

var sescape ( var  str)

Escape the given string for command line use.

Parameters
strThe string to escape
Returns
The escaped string

§ extract()

var extract ( var  a)

Returns an arbitrary index from an array and deletes it.

Parameters
aThe array to fetch an arbitrary index from
Returns
An array index or nothing, if the array is empty

§ any()

var any ( var  a)

Returns whether any of the entries in a given array evalutate to true.

Parameters
aThe array to check for true entries
Return values
0No true entries
1At least one entry evaluates to true

§ compact()

var compact ( var  path)

Returns a compacted version of the path.

This gets rid of ../ by removing the previous path.

Parameters
pathThe path to compact
Returns
The compacted path

§ filter184()

void filter184 ( )

Perform recursive include and output C/C++ file names.

  • Setup environment setable globals
  • Initialize escape tables for the rescape() and sescape() funcitons
  • Read command line arguments
    • Assemble the CPP command
    • Collect files to pass to cpp
    • Guess the project paths from the given files
    • Detect SUFX using the first file encountered
  • Process files recursively
    Precondition
    BEGIN