Contents of /trunk/depend-tools/included_headers.sh
Parent Directory | Revision Log
Revision 331 -
(show annotations)
(download)
(as text)
Mon Feb 20 00:14:24 2006 UTC (18 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 4381 byte(s)
Mon Feb 20 00:14:24 2006 UTC (18 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 4381 byte(s)
new files
1 | #!/bin/bash |
2 | |
3 | # CHANGES |
4 | # |
5 | # 20051211: Add qfile use from portage-utils, prefer over equery. Create new |
6 | # function track_headers() to handle package manager queries for both |
7 | # relative and absolute headers. Split relative and absolute queries into two |
8 | # separate places, since relative aren't quite as reliable. Prefer headers |
9 | # found in the tarball over those in /usr/include. Also, note which headers |
10 | # weren't considered in the calculation and the reasons why not. |
11 | |
12 | location=${1} |
13 | |
14 | usage() { |
15 | echo "${0##*/} [ -d ] source_location" |
16 | echo " Returns owners of all include files used. ${0##*/} defaults to" |
17 | echo " files in /usr/include, so if a file with the same name within the" |
18 | echo " source is the actual one used, false dependencies may be printed." |
19 | echo |
20 | echo " -d" |
21 | echo " Show debug output: Print files not found" |
22 | exit 1 |
23 | } |
24 | |
25 | decho() { |
26 | if [[ -n "${DEBUG}" ]]; then |
27 | echo "${1}" |
28 | fi |
29 | } |
30 | |
31 | if [[ $# -le 0 ]] || [[ $# -ge 3 ]]; then |
32 | usage |
33 | fi |
34 | |
35 | # Handle command-line options |
36 | while getopts d options; do |
37 | case ${options} in |
38 | d) DEBUG=1 |
39 | ;; |
40 | *) usage |
41 | ;; |
42 | esac |
43 | done |
44 | # Reset post-option stuff to positional parameters |
45 | shift $((OPTIND - 1)) |
46 | |
47 | get_absolute_includes() { |
48 | grep '^#[[:space:]]*include' -r ${1} | grep '.*.[ch]' | grep -e '<' -e '>' \ |
49 | | cut -d':' -f2 | cut -d'<' -f2 | cut -d'>' -f1 | grep '.*.[ch]' \ |
50 | | sort | uniq |
51 | } |
52 | |
53 | get_relative_includes() { |
54 | grep '^#[[:space:]]*include' -r ${1} | grep '.*.[ch]' | grep -e '"' -e '"' \ |
55 | | cut -d':' -f2 | cut -d'"' -f2 | cut -d'"' -f1 | grep '.*.[ch]' \ |
56 | | sort | uniq |
57 | } |
58 | |
59 | track_headers() { |
60 | if [[ -x $(which qfile 2> /dev/null) ]]; then |
61 | qfile ${@} | cut -d'(' -f1 | sort | uniq |
62 | elif [[ -x $(which equery 2> /dev/null) ]]; then |
63 | equery -q belongs ${@} | cut -d'(' -f1 |
64 | elif [[ -x /sbin/magequery ]]; then |
65 | for i in ${@}; do |
66 | /sbin/magequery -f ${i} |
67 | done | sort -u |
68 | elif [[ -x $(which rpm 2> /dev/null) ]]; then |
69 | rpm -qf ${@} |
70 | else |
71 | echo "Couldn't find package query tool! Printing headerpaths instead." |
72 | echo |
73 | for header in ${@}; do |
74 | echo ${header} |
75 | done |
76 | fi |
77 | } |
78 | |
79 | echo "Analyzing source ... " |
80 | absolute_headers="$(get_absolute_includes ${1})" |
81 | relative_headers="$(get_relative_includes ${1})" |
82 | |
83 | echo "Looking for absolute headers ... " |
84 | echo |
85 | for header in ${absolute_headers}; do |
86 | absheader="/usr/include/${header}" |
87 | if [[ -e ${absheader} ]]; then |
88 | abs_headerpaths="${abs_headerpaths} ${absheader}" |
89 | echo " Looking for ${absheader} ... OK" |
90 | else |
91 | # Try as a relative header in case people use -I with <> |
92 | relative_headers="${relative_headers} ${header}" |
93 | decho " Looking for ${absheader} ... Not found!" |
94 | fi |
95 | done |
96 | |
97 | echo |
98 | echo "Looking for relative headers ... " |
99 | echo |
100 | for header in ${relative_headers}; do |
101 | fullheader=${header} |
102 | header=${header##*/} |
103 | # Prefer headers in tarball over /usr/include |
104 | header_options=$(find ${location} -name ${header} | grep ${fullheader}) |
105 | if [[ -z ${header_options} ]]; then |
106 | header_options="$(find /usr/include -name ${header} | grep ${fullheader})" |
107 | header_loc="/usr/include" |
108 | else |
109 | decho " Local header ${header} ... Not considering." |
110 | local_headers="${local_headers} ${header}" |
111 | continue |
112 | fi |
113 | count="0" |
114 | for found in ${header_options}; do |
115 | (( count++ )) |
116 | done |
117 | if [[ ${count} -ge 2 ]]; then |
118 | echo " Looking for ${header} ... " |
119 | echo " More than one option found for ${header} in ${header_loc}." |
120 | echo " Not considering ${header}." |
121 | duplicate_headers="${duplicate_headers} ${header}" |
122 | continue |
123 | elif [[ ${count} -le 0 ]]; then |
124 | decho " Looking for ${header} ... Not found!" |
125 | unfound_headers="${unfound_headers} ${header}" |
126 | continue |
127 | fi |
128 | header=${header_options} |
129 | if [[ -e ${header} ]] && [[ ${header_loc} = /usr/include ]]; then |
130 | rel_headerpaths="${rel_headerpaths} ${header}" |
131 | echo " Looking for ${header} ... OK" |
132 | else |
133 | decho " Looking for ${header} ... Not found!" |
134 | fi |
135 | done |
136 | |
137 | echo "Tracing headers back to packages ..." |
138 | echo |
139 | echo "Headers ignored because they exist in the tarball:" |
140 | echo |
141 | for header in ${local_headers}; do |
142 | echo "${header}" |
143 | done |
144 | echo |
145 | echo "Headers ignored because of duplicates in /usr/include:" |
146 | echo |
147 | for header in ${duplicate_headers}; do |
148 | echo "${header}" |
149 | done |
150 | echo |
151 | echo "Headers ignored because they weren't found:" |
152 | echo |
153 | for header in ${unfound_headers}; do |
154 | echo "${header}" |
155 | done |
156 | echo |
157 | echo "Absolute headers:" |
158 | echo |
159 | track_headers ${abs_headerpaths} |
160 | echo |
161 | echo "Relative headers:" |
162 | echo |
163 | track_headers ${rel_headerpaths} |