This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RE: [perl #26136] localtime(3) calls tzset(3), but localtime_r(3) may not.
[metaconfig.git] / U / modified / Findhdr.U
CommitLineData
959f3c4c
JH
1?RCS: $Id: Findhdr.U,v 3.0.1.2 1994/10/29 15:53:08 ram Exp $
2?RCS:
3?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
8?RCS: that same Artistic Licence; a copy of which may be found at the root
9?RCS: of the source tree for dist 3.0.
10?RCS:
11?RCS: Original Author: Thomas Neumann <tom@smart.bo.open.de>
12?RCS:
13?RCS: $Log: Findhdr.U,v $
14?RCS: Revision 3.0.1.2 1994/10/29 15:53:08 ram
15?RCS: patch36: added ?F: line for metalint file checking
16?RCS:
17?RCS: Revision 3.0.1.1 1994/05/06 14:03:56 ram
18?RCS: patch23: cppminus must be after other cppflags, not before
19?RCS:
20?RCS: Revision 3.0 1993/08/18 12:04:54 ram
21?RCS: Baseline for dist 3.0 netwide release.
22?RCS:
23?X:
24?X: This unit produces a findhdr script which is used to locate the header
25?X: files in $usrinc or other stranger places using cpp capabilities. The
26?X: script is given an include file base name, like 'stdio.h' or 'sys/file.h'
27?X: and it returns the full path of the include file and a zero status or an
28?X: empty string with an error status if the file could not be located.
29?X:
30?MAKE:Findhdr: grep test tr rm +usrinc awk cat startsh \
e8970d08 31 cppstdin cppminus +cppflags osname
959f3c4c
JH
32?MAKE: -pick add $@ %<
33?LINT:define fieldn
34?S:fieldn:
35?S: This variable is used internally by Configure. It contains the position
36?S: of the included file name in cpp output. That is to say, when cpp
37?S: pre-processes a #include <file> line, it replaces it by a # line which
38?S: contains the original position in the input file and the full name of
39?S: included file, between "quotes".
40?S:.
41?V:fieldn
42?F:./findhdr !fieldn
4795084e 43?T:cline pos wanted name awkprg usrincdir status cppfilter testaccess
959f3c4c
JH
44: determine filename position in cpp output
45echo " "
46echo "Computing filename position in cpp output for #include directives..." >&4
4795084e
JH
47case "$osname" in
48vos) testaccess=-e ;;
49*) testaccess=-r ;;
50esac
959f3c4c
JH
51echo '#include <stdio.h>' > foo.c
52$cat >fieldn <<EOF
53$startsh
54$cppstdin $cppflags $cppminus <foo.c 2>/dev/null | \
55$grep '^[ ]*#.*stdio\.h' | \
56while read cline; do
57 pos=1
58 set \$cline
59 while $test \$# -gt 0; do
4795084e 60 if $test $testaccess \`echo \$1 | $tr -d '"'\`; then
959f3c4c
JH
61 echo "\$pos"
62 exit 0
63 fi
64 shift
65 pos=\`expr \$pos + 1\`
66 done
67done
68EOF
69chmod +x fieldn
70fieldn=`./fieldn`
71$rm -f foo.c fieldn
72case $fieldn in
73'') pos='???';;
741) pos=first;;
752) pos=second;;
763) pos=third;;
77*) pos="${fieldn}th";;
78esac
79echo "Your cpp writes the filename in the $pos field of the line."
80
e8970d08
JH
81case "$osname" in
82vos) cppfilter="tr '\\\\>' '/' |" ;; # path component separator is >
1056f0f3 83os2) cppfilter="sed -e 's|\\\\\\\\|/|g' |" ;; # path component separator is \
e8970d08
JH
84*) cppfilter='' ;;
85esac
959f3c4c
JH
86?X: To locate a header file, we cannot simply check for $usrinc/file.h, since
87?X: some machine have the headers in weird places and our only hope is that
88?X: the C pre-processor will know how to find those headers. Thank you NexT!
89: locate header file
90$cat >findhdr <<EOF
91$startsh
92wanted=\$1
93name=''
94for usrincdir in $usrinc
95do
96 if test -f \$usrincdir/\$wanted; then
97 echo "\$usrincdir/\$wanted"
98 exit 0
99 fi
100done
101awkprg='{ print \$$fieldn }'
102echo "#include <\$wanted>" > foo\$\$.c
103$cppstdin $cppminus $cppflags < foo\$\$.c 2>/dev/null | \
e8970d08 104$cppfilter $grep "^[ ]*#.*\$wanted" | \
959f3c4c
JH
105while read cline; do
106 name=\`echo \$cline | $awk "\$awkprg" | $tr -d '"'\`
107 case "\$name" in
108 *[/\\\\]\$wanted) echo "\$name"; exit 1;;
109 *[\\\\/]\$wanted) echo "\$name"; exit 1;;
110 *) exit 2;;
111 esac;
112done;
113#
114# status = 0: grep returned 0 lines, case statement not executed
115# status = 1: headerfile found
116# status = 2: while loop executed, no headerfile found
117#
118status=\$?
119$rm -f foo\$\$.c;
120if test \$status -eq 1; then
121 exit 0;
122fi
123exit 1
124EOF
125chmod +x findhdr
126