manpage.dox
LD_PRELOAD=libgendep.so GENDEP_TARGET=target GENDEP_BINARY=compiler [ GENDEP_cmd=compiler ] [ GENDEP_DEPFILE=depfilename ] cmd [options]
LD_PRELOAD=libgendep.so GENDEP_SOURCE=watchfile GENDEP_OUTPUT=outfilename cmd [options]
libgendep is a library to build dependency files. By preloading libgendep.so with the dynamic linker ld.so, the open(2) and fopen(3) functions of libc are overloaded. libgendep.so logs all calls to open(2) and fopen(3) and creates an according dependency file.
In its alternative form, libgendep can be used to determine the name of the binary that is used to open a specific file. Use this to determine a specific element within your compiler tool chain.
In the first form, the name of a file is added to the dependency list, if:
-
the file is opened read-only
-
and the name of the file does not match the environment variable GENDEP_TARGET
-
and the name of the binary currently executed matches the environment variable GENDEP_BINARY.
-
and the filename matches the regex given in the envirnoment variable GENDEP_[cmd], with [cmd] beeing substituted by the value of GENDEP_BINARY.
-
some special regexps for exclusion are predefined (see below)
If GENDEP_[cmd] is not set, the last condition is not checked.
As the current libc for Linux looks into /proc/meminfo and /etc/mtab for some internal management, gendep ignores accesses to /etc/mtab and /proc/*.
In the second form, all open(2)- and fopen(3)-calls are checked for the filename specified in the GENDEP_SOURCE variable. If the given file is opened, the name of the currently executed binary is written into the filename specified in GENDEP_OUTPUT.
libgendep.so is controlled by the following environment variables.
For the first form:
- GENDEP_TARGET
- The target, the dependency has to be build for. This string is used as the target within the make-rule in the dependency file. Unless GENDEP_DEPFILE is set, the name of the dependency file is build by prepending then name portion of the target with '.', and suffixing this with '.d'.
- GENDEP_BINARY
- The name portion of the command that actually builds the target.
- GENDEP_DEPFILE
- The name of the dependency file. If this variable is unset, .GENDEP_TARGET.d will be used.
- GENDEP_[cmd] ([cmd]=$GENDEP_BINARY)
- Optional. If set, the value is interpreted as an regex. A file is included within the dependency list only if its name matches this regex.
For the second form:
- GENDEP_SOURCE
- The source file to be watched. If this file is opened in read-only mode, the name of the currently executed binary is written into .
- GENDEP_OUTPUT
- The name of the output file for the binary name.
LD_PRELOAD=libgendep.so GENDEP_TARGET=main.o GENDEP_BINARY=cpp gcc main.c -o main.o
This creates a dependency file ".main.o.d" containing all header files opened by the C preprocessor cpp(1) during the compilation of main.o.
LD_PRELOAD=libgendep.so GENDEP_SOURCE=main.c GENDEP_OUTPUT=cppname.txt gcc -c main.c
This creates the file "cppname.txt" containing the name of the binary that opened "main.c". If "main.c" was not opened, "cppname.txt" will not be created.
Han-Wen Nienhuys <hanwen@cs.uu.nl>
Jork Loeser <jork.loeser@inf.tu-dresden.de>
ld.so(1) - dynamic linker/loader
open(2) - open and possibly create a file or device
cpp(1) - The GNU C-Compatible Compiler Preprocessor
Generated on Mon Mar 5 18:54:38 2007 for libgendep by
1.4.2