Pullup ticket #2800.
[pkgsrc.git] / mk / bsd.pkg.debug.mk
1 # $NetBSD: bsd.pkg.debug.mk,v 1.20 2007/09/27 12:49:14 rillig Exp $
2 #
3 # Public targets:
4 #
5 # debug:
6 #       outputs the values of some commonly used variables and the
7 #       contents of some files which are useful for tracking bugs,
8 #       especially for packages that use the GNU autotools.
9 #
10
11 PRINTF?=        printf
12
13 # Note: In the many cases where ${x} is used, the quoting is left out
14 # intentionally, since x is an element of a list of shell words, and
15 # passing such a shell word to the shell should still result in one
16 # word. That way, no extra level of quoting is introduced.
17 #
18 # The only exception is the "<" character in CONFIGURE_ARGS, where it
19 # is often used to redirect the input coming from another source. That
20 # character has to be quoted.
21
22 .PHONY: \
23         debug \
24         _show-dbginfo-file-versions \
25         _show-dbginfo-tools \
26         _show-dbginfo-configure \
27         _show-dbginfo-config.status \
28         _show-dbginfo-config.h \
29         _show-dbginfo-build \
30         _show-dbginfo-install \
31         _show-dbginfo-plist-subst
32
33 debug: \
34         _show-dbginfo-file-versions \
35         _show-dbginfo-tools \
36         _show-dbginfo-configure \
37         _show-dbginfo-config.status \
38         _show-dbginfo-config.h \
39         _show-dbginfo-build \
40         _show-dbginfo-install \
41         _show-dbginfo-plist-subst
42
43 _show-dbginfo-file-versions:
44         @${PRINTF} "File versions:\\n"
45         ${RUN} \
46         sedexpr='s,^.*\([$$]NetBSD:[^$$]*\$$\).*,\1,p';                 \
47         ${FIND} * -type f -print                                        \
48         | while read fname; do                                          \
49           ident=`${SED} -n                                              \
50             -e 's,^.*\\([$$]NetBSD:[^$$]*\\$$\\).*,\\1,p'               \
51             -e 's,^.*\\([$$]Id:[^$$]*\\$$\\).*,\\1,p'                   \
52             "$${fname}" | ${SED} 1q` || continue;                       \
53           case $${ident} in                                             \
54           *?*) ${PRINTF} "\\t%s: %s\\n" "$${fname}" "$${ident}";;       \
55           esac;                                                         \
56         done
57         @${PRINTF} "\\n"
58
59 _show-dbginfo-tools:
60         @${PRINTF} "TOOLS:\\n"
61         @${USE_TOOLS:C/:.*//:O:u:@t@${_TOOLS_VARNAME.${t}:D${PRINTF} "\\t%s=%s\\n" ${_TOOLS_VARNAME.${t}} ${${_TOOLS_VARNAME.${t}}:Q};}@}
62         @${PRINTF} "\\n"
63
64 _show-dbginfo-configure:
65         @${PRINTF} "CONFIGURE_DIRS:\\n"; ${CONFIGURE_DIRS:@x@${PRINTF} "\\t%s\\n" ${x};@}
66         @${PRINTF} "\\n"
67         @${PRINTF} "CONFIGURE_ENV (sorted alphabetically):\\n"; ${CONFIGURE_ENV:O:@x@${PRINTF} "\\t%s\\n" ${x};@}
68         @${PRINTF} "\\n"
69         @${PRINTF} "CONFIGURE_SCRIPT:\\n\\t%s\\n" ${CONFIGURE_SCRIPT}
70         @${PRINTF} "\\n"
71         @${PRINTF} "CONFIGURE_ARGS:\\n"; ${CONFIGURE_ARGS:@x@${PRINTF} "\\t%s\\n" ${x:S,<,\<,};@}
72         @${PRINTF} "\\n"
73
74 _show-dbginfo-config.status:
75 .if !empty(CONFIGURE_DIRS:M*)
76         ${RUN} \
77         if ${TEST} -d ${WRKSRC:Q}; then cd ${WRKSRC:Q};                 \
78         for cs in ${CONFIGURE_DIRS:=/config.status}; do                 \
79           if ${TEST} ! -f "$${cs}"; then continue; fi;                  \
80           ${PRINTF} "%s:\\n" "$${cs}";                                  \
81           ${SED} -n -e 's,|#_!!_#|,,g'                                  \
82                 -e '/s,^\\(\[   #\]\*\\)/d'                             \
83                 -e 's:^s,@\([^@]*\)@,\(.*\),;t t$$:     \1=\2:p'        \
84                 -e 's:^s&@\([^@]*\)@&\(.*\)&;t t$$:     \1=\2:p'        \
85                 -e 's:^s,@\([^@]*\)@,\(.*\),g$$:        \1=\2:p'        \
86                 -e 's:^s%@\([^@]*\)@%\(.*\)%g$$:        \1=\2:p'        \
87                 -e 's:^s&@\([^@]*\)@&\(.*\)&g$$:        \1=\2:p'        \
88                 -e 's:^\(s[^[:alnum:]].*\):     &:p'                    \
89                 -e '/:\[FHLC\]/q'                                       \
90                     "$${cs}"                                            \
91           | ${SORT};                                                    \
92           ${PRINTF} "\\n";                                              \
93         done; fi
94 .else
95         @${DO_NADA}
96 .endif
97
98 _show-dbginfo-config.h:
99 .if !empty(CONFIGURE_DIRS:M*)
100         ${RUN} \
101         [ -d ${WRKSRC} ] || exit 0;                                     \
102         print_config_h() {                                              \
103           printf "%s:\\n" "`pwd`/$$1";                                  \
104           awk '/^#define / { print "\t"$$0; } /^\/\* #undef / { print "\t" $$2 " " $$3; }' < "$$1"; \
105           printf "\\n";                                                 \
106         };                                                              \
107         for cdir in ${CONFIGURE_DIRS}; do                               \
108           cd ${WRKSRC}; [ -d "$$cdir" ] || continue; cd "$$cdir";       \
109           [ ! -f config.h ] || { print_config_h config.h; continue; };  \
110           [ ! -f config.status ] || {                                   \
111             : "autoconf 2.59";                                          \
112             chs=`sed -n 's,^config_headers="\([^:]*\).*".*,\1,p' config.status || true`; \
113             : "autoconf 2.13";                                          \
114             [ "$$chs" ] || chs=`sed -n 's,^  CONFIG_HEADERS="\([^:"]*\).*,\1,p' config.status || true`; \
115             done=no;                                                    \
116             for ch in $$chs; do print_config_h "$$ch"; done=yes; done;  \
117             [ $$done = no ] || continue;                                \
118           };                                                            \
119           printf "WARNING: No config header found in `pwd`.\\n\\n";     \
120         done
121 .else
122         @${DO_NADA}
123 .endif
124
125 _show-dbginfo-build:
126         @${PRINTF} "PKGSRC_MAKE_ENV (sorted alphabetically):\\n"; ${PKGSRC_MAKE_ENV:O:@x@${PRINTF} "\\t%s\\n" ${x};@}
127         @${PRINTF} "\\n"
128         @${PRINTF} "BUILD_DIRS:\\n"; ${BUILD_DIRS:@x@${PRINTF} "\\t%s\\n" ${x};@}
129         @${PRINTF} "\\n"
130         @${PRINTF} "MAKE_ENV (sorted alphabetically):\\n"; ${MAKE_ENV:O:@x@${PRINTF} "\\t%s\\n" ${x};@}
131         @${PRINTF} "\\n"
132         @${PRINTF} "MAKE_PROGRAM:\\n\\t%s\\n" ${MAKE_PROGRAM:Q}
133         @${PRINTF} "\\n"
134         @${PRINTF} "MAKE_FLAGS:\\n"; ${MAKE_FLAGS:@x@${PRINTF} "\\t%s\\n" ${x};@}
135         @${PRINTF} "\\n"
136         @${PRINTF} "BUILD_MAKE_FLAGS:\\n"; ${BUILD_MAKE_FLAGS:@x@${PRINTF} "\\t%s\\n" ${x};@}
137         @${PRINTF} "\\n"
138
139 _show-dbginfo-install:
140         @${PRINTF} "INSTALL_DIRS:\\n"; ${INSTALL_DIRS:@x@${PRINTF} "\\t%s\\n" ${x};@}
141         @${PRINTF} "\\n"
142         @${PRINTF} "INSTALL_MAKE_FLAGS:\\n"; ${INSTALL_MAKE_FLAGS:@x@${PRINTF} "\\t%s\\n" ${x};@}
143         @${PRINTF} "\\n"
144
145 _show-dbginfo-plist-subst:
146         @${PRINTF} "PLIST_SUBST (sorted alphabetically):\\n"; ${PLIST_SUBST:O:@x@${PRINTF} "\\t%s\\n" ${x};@}
147         @${PRINTF} "\\n"