3 # find include dependencies in C source
5 # mawk -f deps.awk C_source_files
6 # -- prints a dependency list suitable for make
7 # -- ignores #include < >
11 BEGIN { stack_index = 0 # stack[] holds the input files
13 for(i = 1 ; i < ARGC ; i++)
16 if ( file !~ /\.[cC]$/ ) continue # skip it
17 outfile = substr(file, 1, length(file)-2) ".o"
19 # INCLUDED[] stores the set of included files
20 # -- start with the empty set
21 for( j in INCLUDED ) delete INCLUDED[j]
25 if ( getline line < file <= 0 ) # no open or EOF
27 if ( stack_index == 0 ) break # empty stack
29 { file = stack[ stack_index-- ]
34 if ( line ~ /^#include[ \t]+".*"/ )
36 split(line, X, "\"") # filename is in X[2]
38 if ( X[2] in INCLUDED ) # we've already included it
42 stack[ ++stack_index ] = file
43 INCLUDED[ file = X[2] ] = ""
47 # test if INCLUDED is empty
48 flag = 0 # on once the front is printed
51 { printf "%s : %s" , outfile, j ; flag = 1 }
56 }# end of loop over files in ARGV[i]