summary refs log tree commit diff
path: root/tools/gen-deps.sh
blob: befe021421bcc534bf9e1a902a4cc450b802c71f (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh -e

. package/info

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

internal_libs=

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

for dir in src/* ; do
  for file in $(ls -1 $dir | grep -- \\.c$) ; do
    {
      grep -F -- "#include <${package}/" < ${dir}/$file | cut -d'<' -f2 | cut -d'>' -f1 ;
      grep -- '#include ".*\.h"' < ${dir}/$file | cut -d'"' -f2
    } | sort -u | {
      deps=" ${dir}/$file"
      while read dep ; do
        if echo $dep | grep -q "^${package}/" ; then
          deps="$deps src/include/$dep"
        elif test -f "${dir}/$dep" ; then
          deps="$deps ${dir}/$dep"
        else
          deps="$deps src/include-local/$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
echo

for dir in $(ls -1 src | grep -v ^include) ; do
  for file in $(ls -1 src/$dir/deps-lib) ; do
    deps=
    libs=
    while read dep ; do
      if echo $dep | grep -q -e ^-l -e '^\${.*_LIB}' ; then
        libs="$libs $dep"
      else
        deps="$deps src/$dir/$dep"
      fi
    done < src/$dir/deps-lib/$file
    echo 'ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)'
    echo "lib${file}.a.xyzzy:$deps"
    echo else
    echo "lib${file}.a.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')"
    echo endif
    if grep -E "^LIB_DEFS [+:]=" package/targets.mak | grep -qF "$file" ; then
      echo "lib${file}.so.xyzzy: EXTRA_LIBS :=$libs"
      echo "lib${file}.so.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')"
    else
      internal_libs="$internal_libs lib${file}.a.xyzzy"
    fi
  done

  for file in $(ls -1 src/$dir/deps-exe) ; do
    deps=
    libs=
    while read dep ; do
      if echo $dep | grep -q -- \\.o$ ; then
        dep="src/$dir/$dep"
      fi
      if echo $dep | grep -q -e ^-l -e '^\${.*_LIB}' ; then
        libs="$libs $dep"
      else
        deps="$deps $dep"
      fi
    done < src/$dir/deps-exe/$file
    echo "$file: EXTRA_LIBS :=$libs"
    echo "$file: src/$dir/$file.o$deps"
  done
done
echo "INTERNAL_LIBS :=$internal_libs"