Add files from parent branch HEAD:
[pkgsrc.git] / mk / check / check-headers.sh
1 # $NetBSD: check-headers.sh,v 1.9 2007/01/02 17:58:11 rillig Exp $
2 #
3 # This program checks the header files for possible problems.
4 #
5 # When a macro definition contains the characters "${", it is likely
6 # that is comes from a GNU-style configure script that didn't use the
7 # ${prefix} or ${exec_prefix} variable correctly.
8 #
9
10 set -eu
11
12 checkdir=`dirname "$0"`
13 . "$checkdir/check-subr.sh"
14 cs_setprogname "$0"
15
16 found_unresolved_variable=no
17
18 # usage: check_header <fname>
19 check_header() {
20         # See the end of the loop for the redirection.
21         while read line; do
22
23                 # Check for "${" in macro definitions.
24                 case "$line" in
25                 "#"*define*[\":]\$\{[A-Za-z]*\}/*\"*)
26                         found_unresolved_variable=yes
27                         cs_error_heading "Found unresolved variable in macro:"
28                         cs_error_msg "$fname: $line"
29                         ;;
30                 esac
31
32         done < "$1"
33 }
34
35 find * -type f -print 2>/dev/null \
36 | {
37         while read fname; do
38
39                 skip=no
40                 eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac"
41                 [ $skip = no ] || continue
42
43                 case "$fname" in
44                 *.h | *.hpp | *.h++ | *.hxx)
45                         check_header "$fname"
46                         ;;
47                 esac
48         done
49
50         if [ $found_unresolved_variable = yes ]; then
51                 cs_explain <<EOF
52 The above macros may contain references to shell variables.
53
54 The cause of this problem is usually that in a configure.ac or
55 configure.in file, there is some code like
56
57     FOO_DIR="\${bindir}"
58     # ...
59     AC_DEFINE_UNQUOTED(FOO_DIR, "\$FOO_DIR", [Directory where foo files go])
60
61 You can fix this by telling the original package author not to use
62 AC_DEFINE_UNQUOTED for directories. Instead, {he,she} should do
63 something like this:
64
65     # in configure.ac:
66     foodir="\${bindir}"
67     AC_SUBST(FOO_DIR)
68
69     # in the Makefile.am files (can be more than one):
70     AM_CPPFLAGS= -DFOO_DIR=\\"@FOO_DIR@\\"
71
72 See also:
73 http://www.gnu.org/software/autoconf/manual/html_node/Defining-Directories.html
74
75 If this check is wrong and the package really wants to have "\${" in the
76 macros, append the above filenames to the CHECK_HEADERS_SKIP variable in
77 the package Makefile.
78 EOF
79
80         fi
81         cs_exit
82 }