Original source came from on by Han-Wen Nienhuys under GPL. Minor changes made by Christopher Lester to make it compile with
[lester@localhost gendep-0.1]$ gcc --version
gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

[lester@localhost gendep-0.1]$ cat /etc/issue
Fedora Core release 6 (Zod)
Kernel \r on an \m

[lester@localhost gendep-0.1]$ uname -a
Linux localhost.localdomain 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686 i686 i386 GNU/Linux

Basic changes amount to telling the test part of the makefile that the binary which it should be snooping for inclusions is called "cc1" now, not "cpp". Also one of the headers seems to be called "syscall.h" now not "syscall-list.h".
Resulting repackaging is gendep-0.1-gcc4-fc6-lester.tar.gz still under GPL.

How it works

The idea is that a library is created that can intercept calls to open() made by a specified progam (determined by environment variable GENDEP_BINARY), and then inspect the opened files to see if they match a set of regexps (determined by environment variables GENDEP_XXX, where XXX is a value of GENDEP_BINARY) and if they do matchm, these filenames are recorded in a dependency file suitable for reading by gnu make. The target file is controlled by environment variable GENDEP_TARGET. To get the library that intercepts calls to open loaded, it is necessary to use a preload mechanism such as that controlled by the LD_PRELOAD environment variable in many versions of linux.

If all that is very confusing, download the source code, build the library with "make" and then type "make test" to run an example which will compile an example program "simple-cat.c" and output dependency information twice. Here is the test target of the makefile:

        GENDEP_TARGET='simple-cat' \
                GENDEP_cc1='+\.h$$ -^/usr' \
                LD_PRELOAD=$(shell pwd)/\
                gcc -o simple-cat simple-cat.c
        GENDEP_TARGET='badexp' \
                LD_PRELOAD=$(shell pwd)/\
                gcc -o simple-cat simple-cat.c
        @echo ====================
        @echo == simple-cat.dep ==
        cat simple-cat.dep
        @echo ================
        @echo == badexp.dep ==
        cat badexp.dep
        @echo ================
You should see output similar to the following:
== simple-cat.dep ==
cat simple-cat.dep
simple-cat: gendep.h
== badexp.dep ==
cat badexp.dep
badexp: simple-cat.c/usr/include/stdio.h/usr/include/features.h\
in which you can see that the good regexp in the first example caused only relevant dependencies to be printed, whereas the second example ("badexp") showed how a bad regexp could lead to an excessive number of dependencies being recorded.



means "snoop binaries called cc1". This is currently a straight string comparison, but could be converted to be a regexp match or similar.

GENDEP_cc1='+\.h$$ -^/usr'

means "if you find yourself snooping a binary called cc1, then within that snoop only look at opened files whose names match this space-separated list of regexps". You could have multiple such GENDEP_BLAH env-vars, one for every binary you plan to snoop. NOTE THAT FOR EVERY GENDEP_BINARY="MOO" there must be a corresponding "GENDEP_MOO=......" or you will never snoop anything!


means: "when you write the .dep file, call it 'simple-cat.dep' and make it's first line 'simple-cat: '"
Note that only the first part of the "make test" command is supposed to work and make simple-cat.dep. The second two parts are supposed to fail. Target "blahblah" fails as there is no env-var corresp to GENDEP_BINARY. Target "badexp" fails as the regexp is pooly formed.
This page is