summaryrefslogtreecommitdiff
path: root/tools/gen-deps.sh
blob: ce180913bd52d03176f0746885ee8d2b82bd7e62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh -e

. package/info

echo '#'
echo '# This file has been generated by tools/gen-deps.sh'
echo '#'
echo

for dir in src/include/${package} src/lib* ; do
  for file in $(ls -1 $dir | grep -- \\.h$) ; do
    {
      grep -F "#include <${package}/" < ${dir}/$file | cut -d/ -f2- | cut -d'>' -f1 ;
      grep -- '#include ".*-internal\.h"' < ${dir}/$file | cut -d'"' -f2
    } | sort -u | {
      deps=
      while read dep ; do
        if echo $dep | grep -q -- -internal\\.h$ ; then
          deps="$deps ${dir}/$dep"
        else
          deps="$deps src/include/${package}/$dep"
        fi
      done
      if test -n "$deps" ; then
        echo "${dir}/${file}:${deps}"
      fi
    }
  done
done

for dir in src/lib* ; do
  for file in $(ls -1 $dir | grep -- \\.c$) ; do
    {
      grep -F "#include <${package}/" < ${dir}/$file | cut -d/ -f2- | cut -d'>' -f1 ;
      grep -- '#include ".*-internal\.h"' < ${dir}/$file | cut -d'"' -f2
    } | sort -u | {
      deps=" ${dir}/$file"
      while read dep ; do
        if echo $dep | grep -q -- -internal\\.h$ ; then
          deps="$deps ${dir}/$dep"
        else
          deps="$deps src/include/${package}/$dep"
        fi
      done
      o=$(echo $file | sed s/\\.c$/.o/)
      lo=$(echo $file | sed s/\\.c$/.lo/)
      echo "${dir}/${o} ${dir}/${lo}:${deps}"
    }
  done
done