2 # This is an awk script which does dependencies. We do NOT want it to
3 # recursively follow #include directives.
4 # We only add to dependencies those files which are inside of the rootdir
8 # Surely there is a more elegant way to see if a file exists. Anyone know
11 function fileExists
(f
, TMP
, dummy
, result
) {
12 if(result=FILEHASH
[f
]) {
17 ERRNO =
getline dummy
< f
20 return FILEHASH
[f
]=
"Yes"
27 function Canonic
(path
) {
28 while (path ~
"/[^/]*/\\.\\./")
29 gsub("/[^/]*/\\.\\./","/",path
)
38 # dolib = "libdirectory libname"
43 sub("/[^/]*$","",rootdir
)
47 } else if ($
0 ~
"^/.*\\.h: \\\\$") {
53 sub("^OBJS=[ ]*\"[ ]*","",objs
)
56 printf "%s: ", dlib
[2]
60 fullname=dlib
[1]"/"obj
[fname
]
61 printf " \\\n %s", fullname
62 sub("\\.o$",".c",obj
[fname
])
69 print "hpath is not set"
73 print "srcdir is not set"
76 sub("[/ ]*$","",srcdir
)
78 sub("^\./$","",srcdir
)
81 sub("^-I","",parray
[path
])
82 sub("[/ ]*$","",parray
[path
])
83 parray
[path
]=Canonic
(parray
[path
])
86 USED
[USEDC
]=Canonic
(srcdir
""ARGV[path
])
91 /^
#[ ]*include[ ]*[<"][^ ]*[>"]/{
93 if(LASTFILE
!=FILENAME) {
102 sub("\\.c$",".o: ",depname
)
103 if (depname==
FILENAME) {
104 depname=srcdir
""depname
105 depname=Canonic
(depname
)
106 cmd=
"\n\t@touch "depname
108 depname=objprefix
""depname
109 sub("\\.h$",".h: ",depname
)
110 if(relpath ~
"^\\." ) {
111 sub("[^/]*$","", relpath
)
113 sub("//","/", relpath
)
119 sub("^#[ ]*include[ ]*[<\"]","",fname
)
120 sub("[>\"].*","",fname
)
121 if(fileExists
(relpath
""fname
)) {
127 fullname=Canonic
(srcdir
""relpath
""fname
)
128 printf " \\\n %s", fullname
129 if(fname ~
"^\\." ) {
130 partname=relpath
""fname
133 if (USED
[name
] == fullname
) {
146 for(path in parray
) {
147 if(fileExists
(parray
[path
]"/"fname
)) {
153 printf " \\\n %s", parray
[path
]"/"fname