dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / comp / conf.sh
blobefe6288145606c43f6102343b65f9fc84ff84154
1 ########################################################################
2 # #
3 # This software is part of the ast package #
4 # Copyright (c) 1985-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
8 # #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
12 # #
13 # Information and Software Systems Research #
14 # AT&T Research #
15 # Florham Park NJ #
16 # #
17 # Glenn Fowler <gsf@research.att.com> #
18 # David Korn <dgk@research.att.com> #
19 # Phong Vo <kpv@research.att.com> #
20 # #
21 ########################################################################
22 : generate getconf and limits info
24 # @(#)conf.sh (AT&T Research) 2008-01-31
26 # this script generates these files from the table file in the first arg
27 # the remaining args are the C compiler name and flags
29 # conflim.h supplemental limits.h definitions
30 # conftab.h readonly string table definitions
31 # conftab.c readonly string table data
33 # you may think it should be simpler
34 # but you shall be confused anyway
37 case $-:$BASH_VERSION in
38 *x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
39 esac
41 LC_ALL=C
42 export LC_ALL
44 command=conf
46 shell=`eval 'x=123&&integer n=\${#x}\${x#1?}&&((n==330/(10)))&&echo ksh' 2>/dev/null`
48 append=0
49 debug=
50 extra=0
51 keep_call='*'
52 keep_name='*'
53 trace=
54 verbose=0
55 while :
56 do case $1 in
57 -a) append=1 ;;
58 -c*) keep_call=${1#-?} ;;
59 -d*) debug=$1 ;;
60 -l) extra=1 ;;
61 -n*) keep_name=${1#-?} ;;
62 -t) trace=1 ;;
63 -v) verbose=1 ;;
64 -*) echo "Usage: $command [-a] [-ccall-pattern] [-dN] [-l] [-nname_pattern] [-t] [-v] conf.tab" >&2; exit 2 ;;
65 *) break ;;
66 esac
67 shift
68 done
69 head='#include "FEATURE/standards"
70 #include "FEATURE/common"'
71 tail='#include "FEATURE/param"'
72 generated="/* : : generated by $command from $1 : : */"
73 hdr=
74 ifs=${IFS-'
76 nl='
78 sp=' '
79 ob='{'
80 cb='}'
81 sym=[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*
82 tmp=conf.tmp
83 case $verbose:$debug$trace in
84 1:?*) echo "$command: debug=$debug trace=$trace keep_call=$keep_call keep_name=$keep_name" >&2 ;;
85 esac
86 case $trace in
87 1) PS4='+$LINENO+ '; set -x ;;
88 esac
90 case $# in
91 0) case $extra in
92 0) echo "$command: table argument expected" >&2
93 exit 1
95 esac
96 tab=/dev/null
98 *) tab=$1
99 shift
100 if test ! -f $tab
101 then echo "$command: $tab: cannot read" >&2
102 exit 1
105 esac
106 case $# in
107 0) cc=cc ;;
108 *) cc=$* ;;
109 esac
111 rm -f $tmp.*
112 case $debug in
113 '') trap "code=\$?; rm -f $tmp.*; exit \$code" 0 1 2 ;;
114 esac
116 # determine the intmax_t printf format
118 cat > $tmp.c <<!
119 ${head}
121 main()
123 #if _ast_intmax_long
124 return 1;
125 #else
126 return 0;
127 #endif
130 if $cc -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe
131 then LL_format='ll'
132 else LL_format='l'
135 # determine the intmax_t constant suffix
137 cat > $tmp.c <<!
138 ${head}
140 main()
142 #if _ast_intmax_long
143 return 1;
144 #else
145 _ast_intmax_t s = 0x7fffffffffffffffLL;
146 unsigned _ast_intmax_t u = 0xffffffffffffffffLL;
148 return 0;
149 #endif
152 if $cc -o $tmp.exe $tmp.c >/dev/null 2>&1
153 then if ./$tmp.exe
154 then LL_suffix='LL'
155 else LL_suffix='L'
157 else LL_suffix=''
160 # set up the names and keys
162 keys=
163 standards=
165 case $append$extra in
166 00) case $verbose in
167 1) echo "$command: read $tab" >&2 ;;
168 esac
169 exec < $tab
170 while :
171 do IFS=""
172 read line
173 eof=$?
174 IFS=$ifs
175 case $eof in
176 0) ;;
177 *) break ;;
178 esac
179 case $line in
180 ""|\#*) ;;
181 *) set x $line
182 shift; name=$1
183 shift; standard=$1
184 shift; call=$1
185 shift; section=$1
186 shift; flags=$1
187 alternates=
188 define=
189 values=
190 script=
191 headers=
192 while :
193 do shift
194 case $# in
195 0) break ;;
196 esac
197 case $1 in
198 ":") shift
199 eval script='$'script_$1
200 break
202 *"{") case $1 in
203 "sh{") script="# $name" ;;
204 *) script= ;;
205 esac
206 shift
207 args="$*"
208 IFS=""
209 while read line
210 do case $line in
211 "}") break ;;
212 esac
213 script=$script$nl$line
214 done
215 IFS=$ifs
216 break
218 *.h) case $shell in
219 ksh) f=${1%.h} ;;
220 *) f=`echo $1 | sed 's,\.h$,,'` ;;
221 esac
222 case " $hdr " in
223 *" $f "*)
224 headers=$headers$nl#include$sp'<'$1'>'
226 *" -$f- "*)
228 *) if iffe -n - hdr $f | grep _hdr_$f >/dev/null
229 then hdr="$hdr $f"
230 headers=$headers$nl#include$sp'<'$1'>'
231 else hdr="$hdr -$f-"
234 esac
236 *) values=$values$sp$1
237 case $1 in
238 $sym) echo "$1" >> $tmp.v ;;
239 esac
241 esac
242 done
243 case " $standards " in
244 *" $standard "*)
246 *) standards="$standards $standard"
248 esac
249 case $name:$flags in
250 *:*S*) ;;
251 VERSION)flags="${flags}S" ;;
252 esac
253 case $name in
254 *VERSION*)key=${standard}${section} ;;
255 *) key= ;;
256 esac
257 case $key in
258 ''|*_) key=${key}${name} ;;
259 *) key=${key}_${name} ;;
260 esac
261 eval sys='$'CONF_call_${key}
262 case $sys in
263 ?*) call=$sys ;;
264 esac
265 case $call in
266 SI) sys=CS ;;
267 *) sys=$call ;;
268 esac
269 key=${sys}_${key}
270 keys="$keys$nl$key"
271 eval CONF_name_${key}='$'name
272 eval CONF_standard_${key}='$'standard
273 eval CONF_call_${key}='$'call
274 eval CONF_section_${key}='$'section
275 eval CONF_flags_${key}='$'flags
276 eval CONF_define_${key}='$'define
277 eval CONF_values_${key}='$'values
278 eval CONF_script_${key}='$'script
279 eval CONF_args_${key}='$'args
280 eval CONF_headers_${key}='$'headers
281 eval CONF_keys_${name}=\"'$'CONF_keys_${name} '$'key\"
283 esac
284 done
286 esac
287 case $debug in
288 -d1) for key in $keys
289 do eval name=\"'$'CONF_name_$key\"
290 case $name in
291 ?*) eval standard=\"'$'CONF_standard_$key\"
292 eval call=\"'$'CONF_call_$key\"
293 eval section=\"'$'CONF_section_$key\"
294 eval flags=\"'$'CONF_flags_$key\"
295 eval define=\"'$'CONF_define_$key\"
296 eval values=\"'$'CONF_values_$key\"
297 eval script=\"'$'CONF_script_$key\"
298 eval args=\"'$'CONF_args_$key\"
299 eval headers=\"'$'CONF_headers_$key\"
300 printf "%29s %35s %8s %2s %1d %5s %s$nl" "$name" "$key" "$standard" "$call" "$section" "$flags" "$define${values:+$sp=$values}${headers:+$sp$headers$nl}${script:+$sp$ob$script$nl$cb}"
302 esac
303 done
304 exit
306 esac
308 systeminfo='
309 #if !defined(SYS_NMLEN)
310 #define SYS_NMLEN 9
311 #endif
312 #include <sys/systeminfo.h>'
313 echo "$systeminfo" > $tmp.c
314 $cc -E $tmp.c >/dev/null 2>&1 || systeminfo=
316 # check for native getconf(1)
318 CONF_getconf=
319 CONF_getconf_a=
320 for d in /usr/bin /bin /usr/sbin /sbin
321 do if test -x $d/getconf
322 then case `$d/getconf --?-version 2>&1` in
323 *"AT&T"*"Research"*)
324 : presumably an implementation also configured from conf.tab
326 *) CONF_getconf=$d/getconf
327 if $CONF_getconf -a >/dev/null 2>&1
328 then CONF_getconf_a=-a
331 esac
332 break
334 done
335 export CONF_getconf CONF_getconf_a
337 case $verbose in
338 1) echo "$command: check ${CONF_getconf:+$CONF_getconf(1),}confstr(2),pathconf(2),sysconf(2),sysinfo(2) configuration names" >&2 ;;
339 esac
341 echo "#include <unistd.h>$systeminfo
342 int i = 0;" > $tmp.c
343 $cc -E $tmp.c
345 sed \
346 -e '/^#[^0123456789]*1[ ]*".*".*/!d' \
347 -e 's/^#[^0123456789]*1[ ]*"\(.*\)".*/\1/' |
348 sort -u > $tmp.f
350 sed \
351 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]/ /g' \
352 -e 's/[ ][ ]*/\n/g' \
353 `cat $tmp.f` 2>/dev/null |
354 egrep '^(SI|_(CS|PC|SC|SI))_.'
355 case $CONF_getconf_a in
356 ?*) $CONF_getconf $CONF_getconf_a | sed 's,[=: ].*,,'
358 *) case $CONF_getconf in
359 ?*) for v in `strings $CONF_getconf | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*$'`
360 do if $CONF_getconf $v >/dev/null
361 then echo $v
363 done
365 esac
367 esac 2>/dev/null
369 egrep -v '^_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+_(COUNT|LAST|N|STR)$' |
370 sort -u > $tmp.g
372 grep '^_' $tmp.g
373 grep '^[^_]' $tmp.g
374 } > $tmp.t
375 mv $tmp.t $tmp.g
376 case $debug in
377 -d2) exit ;;
378 esac
380 HOST=`package | sed -e 's,[0123456789.].*,,' | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
381 case $HOST in
382 '') HOST=SYSTEM ;;
383 esac
385 exec < $tmp.g
387 while read line
388 do flags=F
389 section=
390 underscore=
391 define=$line
392 IFS=_
393 set $line
394 IFS=$ifs
395 case $1 in
396 '') case $# in
397 0) continue ;;
398 esac
399 shift
401 esac
402 case $1 in
403 CS|PC|SC|SI)
404 call=$1
405 shift
406 standard=$1
408 *) flags=${flags}R
409 standard=$1
410 while :
411 do case $# in
412 0) continue 2 ;;
413 esac
414 shift
415 case $1 in
416 CS|PC|SC|SI)
417 call=$1
418 shift
419 break
421 O|o|OLD|old)
422 continue 2
424 esac
425 standard=${standard}_$1
426 done
428 esac
429 case $1 in
430 SET) continue ;;
431 esac
432 case $standard in
433 _*) standard=`echo $standard | sed 's,^_*,,'` ;;
434 esac
435 case " $standards " in
436 *" $standard "*)
438 *) case $standard in
439 [0123456789]*)
440 section=$standard
441 standard=POSIX
443 *[0123456789])
444 eval `echo $standard | sed 's,\(.*\)\([0123456789]*\),standard=\1 section=\2,'`
446 esac
448 esac
449 case $flags in
450 *R*) case $call in
451 SI) ;;
452 *) underscore=U ;;
453 esac
455 *) case " $standards " in
456 " C ") shift
458 *" $standard "*)
459 case $call in
460 SI) ;;
461 *) flags=${flags}P
462 underscore=U
464 esac
465 shift
467 *) standard=
469 esac
471 esac
472 case $standard in
473 '') standard=$HOST
474 case $call in
475 SI) ;;
476 *) underscore=U ;;
477 esac
478 case $call in
479 CS|PC|SC)
480 case $define in
481 _${call}_*)
482 standard=POSIX
484 esac
486 esac
488 esac
489 part=$section
490 case $section in
491 '') section=1
492 case $standard in
493 POSIX|XOPEN) part=$section ;;
494 esac
496 esac
497 name=
498 while :
499 do case $# in
500 0) break ;;
501 esac
502 case $name in
503 '') name=$1 ;;
504 *) name=${name}_$1 ;;
505 esac
506 shift
507 done
508 case $name in
509 '') ;;
510 CONFORMANCE|FS_3D|HOSTTYPE|LIBPATH|LIBPREFIX|LIBSUFFIX|PATH_ATTRIBUTES|PATH_RESOLVE|UNIVERSE)
512 *) values=
513 script=
514 args=
515 headers=
516 case $name in
517 V[123456789]_*|V[123456789][0123456789]_*) underscore=VW ;;
518 esac
519 case $call in
520 CS|SI) key=CS ;;
521 *) key=$call ;;
522 esac
523 case $name in
524 *VERSION*)key=${key}_${standard}${part} ;;
525 esac
526 key=${key}_${name}
527 eval x='$'CONF_keys_$name
528 case $x in
529 '') eval x='$'CONF_name_$key
530 case $x in
531 '') case $call in
532 SI) flags=O$flags ;;
533 esac
534 case $underscore in
535 ?*) flags=${flags}${underscore} ;;
536 esac
537 old=QQ
538 case $name in
539 *VERSION*)old=${old}_${standard}${part} ;;
540 esac
541 old=${old}_${name}
542 eval x='$'CONF_name_$old
543 case $x in
544 ?*) eval CONF_name_$old=
545 eval flags='$'flags'$'CONF_flags_$old
546 eval values='$'CONF_values_$old
547 eval script='$'CONF_script_$old
548 eval args='$'CONF_args_$old
549 eval headers='$'CONF_headers_$old
551 esac
552 keys="$keys$nl$key"
553 eval CONF_name_${key}='$'name
554 eval CONF_standard_${key}='$'standard
555 eval CONF_call_${key}='$'call
556 eval CONF_section_${key}='$'section
557 eval CONF_flags_${key}=d'$'flags
558 eval CONF_define_${key}='$'define
559 eval CONF_values_${key}='$'values
560 eval CONF_script_${key}='$'script
561 eval CONF_args_${key}='$'args
562 eval CONF_headers_${key}='$'headers
564 *) eval x='$'CONF_define_$key
565 case $x in
566 ?*) case $call in
567 CS) eval x='$'CONF_call_$key
568 case $x in
569 SI) ;;
570 *) define= ;;
571 esac
573 *) define=
575 esac
577 esac
578 case $define in
579 ?*) eval CONF_define_${key}='$'define
580 eval CONF_call_${key}='$'call
581 eval x='$'CONF_call_${key}
582 case $x in
583 QQ) ;;
584 *) case $flags in
585 *R*) flags=R ;;
586 *) flags= ;;
587 esac
589 esac
590 case $call in
591 SI) flags=O$flags ;;
592 esac
593 eval CONF_flags_${key}=d'$'flags'$'CONF_flags_${key}
595 esac
596 old=QQ
597 case $name in
598 *VERSION*)old=${old}_${standard}${part} ;;
599 esac
600 old=${old}_${name}
601 eval CONF_name_$old=
602 esac
604 *) for key in $x
605 do eval x='$'CONF_call_${key}
606 case $x in
607 XX) eval CONF_call_${key}=QQ
608 eval CONF_flags_${key}=S'$'CONF_flags_${key}
610 esac
611 done
612 esac
614 esac
615 done
617 # sort keys by name
619 keys=`for key in $keys
620 do eval echo '$'CONF_name_$key '$'key
621 done | sort -u | sed 's,.* ,,'`
622 case $debug in
623 -d3) for key in $keys
624 do eval name=\"'$'CONF_name_$key\"
625 case $name in
626 ?*) eval standard=\"'$'CONF_standard_$key\"
627 eval call=\"'$'CONF_call_$key\"
628 eval section=\"'$'CONF_section_$key\"
629 eval flags=\"'$'CONF_flags_$key\"
630 eval define=\"'$'CONF_define_$key\"
631 eval values=\"'$'CONF_values_$key\"
632 eval script=\"'$'CONF_script_$key\"
633 eval headers=\"'$'CONF_headers_$key\"
634 printf "%29s %35s %8s %2s %1d %5s %s$nl" "$name" "$key" "$standard" "$call" "$section" "$flags" "$define${values:+$sp=$values}${headers:+$sp$headers$nl}${script:+$sp$ob$script$nl$cb}"
636 esac
637 done
638 exit
640 esac
642 # mark the dups CONF_PREFIXED
644 prev_key=
645 prev_name=
646 for key in $keys
647 do eval name=\"'$'CONF_name_$key\"
648 case $name in
649 '') continue
651 $prev_name)
652 eval p='$'CONF_flags_${prev_key}
653 eval c='$'CONF_flags_${key}
654 case $p:$c in
655 *L*:*L*);;
656 *L*:*) c=L${c} ;;
657 *:*L*) p=L${p} ;;
658 *) p=P$p c=P$c ;;
659 esac
660 eval CONF_flags_${prev_key}=$p
661 eval CONF_flags_${key}=$c
663 esac
664 prev_name=$name
665 prev_key=$key
666 done
668 # collect all the macros/enums
670 for key in $keys
671 do eval name=\"'$'CONF_name_$key\"
672 case $name in
673 '') continue ;;
674 $keep_name) ;;
675 *) continue ;;
676 esac
677 eval call=\"'$'CONF_call_$key\"
678 case $call in
679 $keep_call) ;;
680 *) continue ;;
681 esac
682 eval standard=\"'$'CONF_standard_$key\"
683 eval section=\"'$'CONF_section_$key\"
684 eval flags=\"'$'CONF_flags_$key\"
685 eval define=\"'$'CONF_define_$key\"
686 eval values=\"'$'CONF_values_$key\"
687 eval script=\"'$'CONF_script_$key\"
688 eval args=\"'$'CONF_args_$key\"
689 eval headers=\"'$'CONF_headers_$key\"
690 conf_name=$name
691 case $call in
692 QQ) call=XX
693 for c in SC PC CS
694 do case $flags in
695 *S*) case $section in
696 1) eval x='$'CONF_call_${c}_${standard}_${name} ;;
697 *) eval x='$'CONF_call_${c}_${standard}${section}_${name} ;;
698 esac
700 *) eval x='$'CONF_call_${c}_${name}
702 esac
703 case $x in
704 ?*) call=$x
705 break
707 esac
708 done
709 case $call in
710 XX) for c in SC PC CS
711 do echo "_${c}_${name}"
712 case $flags in
713 *S*) case $section in
714 1) echo "_${c}_${standard}_${name}" ;;
715 *) echo "_${c}_${standard}${section}_${name}" ;;
716 esac
718 esac
719 done
721 esac
723 esac
724 case $call in
725 CS|PC|SC|SI|XX)
727 *) echo "$command: $name: $call: invalid call" >&2
728 exit 1
730 esac
731 case $flags in
732 *[ABEGHIJQTYZabcefghijklmnopqrstuvwxyz_123456789]*)
733 echo "$command: $name: $flags: invalid flag(s)" >&2
734 exit 1
736 esac
737 case $section in
738 [01]) ;;
739 *) case $flags in
740 *N*) ;;
741 *) name=${section}_${name} ;;
742 esac
743 standard=${standard}${section}
745 esac
746 case $call in
747 XX) ;;
748 *) case $flags in
749 *d*) conf_op=${define} ;;
750 *O*) conf_op=${call}_${name} ;;
751 *R*) conf_op=_${standard}_${call}_${name} ;;
752 *S*) conf_op=_${call}_${standard}_${name} ;;
753 *) conf_op=_${call}_${name} ;;
754 esac
755 echo "${conf_op}"
757 esac
758 case $standard:$flags in
759 C:*) ;;
760 *:*L*) echo "${conf_name}"
761 echo "_${standard}_${conf_name}"
763 *:*M*) case $section in
764 1) echo "_${standard}_${conf_name}" ;;
765 *) echo "_${standard}${section}_${conf_name}" ;;
766 esac
768 esac
769 done > $tmp.q
770 sort -u < $tmp.q > $tmp.t
771 mv $tmp.t $tmp.q
772 sort -u < $tmp.v > $tmp.t
773 mv $tmp.t $tmp.v
774 case $debug in
775 -d4) exit ;;
776 esac
778 # test all the macros in a few batches (some compilers have an error limit)
780 defined() # list-file
782 : > $tmp.p
783 while :
784 do {
785 cat <<!
786 ${head}
787 #include <sys/types.h>
788 #include <limits.h>
789 #include <unistd.h>$systeminfo$headers
790 ${tail}
791 #undef conf
792 unsigned int conf[] = {
794 sed 's/$/,/' $1
795 echo "};"
796 } > $tmp.c
797 [ -f $tmp.1.c ] || cp $tmp.c $tmp.1.c
798 if $cc -c $tmp.c > $tmp.e 2>&1
799 then break
801 [ -f $tmp.1.e ] || cp $tmp.e $tmp.1.e
802 snl='\
804 sed "s/[^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][^_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*/${snl}/g" $tmp.e |
805 grep '^[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz][_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]*$' |
806 sort -u > $tmp.n
807 cmp -s $tmp.n $tmp.p && break
808 fgrep -x -v -f $tmp.n $1 > $tmp.y
809 mv $tmp.y $1
810 mv $tmp.n $tmp.p
811 done
813 cat <<!
814 ${head}
815 #include <sys/types.h>
816 #include <limits.h>
817 #include <unistd.h>$systeminfo$headers
818 ${tail}
819 #undef conf
821 sed 's/.*/conf "&" = &/' $1
822 } > $tmp.c
823 $cc -E $tmp.c 2>/dev/null |
824 sed -e '/conf[ ]*".*"[ ]*=[ ]*/!d' -e '/[_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789][ ]*(/!d' -e 's/.*"\(.*\)".*/\1/' > $tmp.n
825 if test -s $tmp.n
826 then fgrep -x -v -f $tmp.n $1 > $tmp.y
827 mv $tmp.y $1
831 case $verbose in
832 1) echo "$command: check macros/enums as static initializers" >&2 ;;
833 esac
834 defined $tmp.q
835 defined $tmp.v
836 case $debug in
837 -d5) exit ;;
838 esac
840 # mark the constant macros/enums
842 exec < $tmp.q
843 while read line
844 do eval CONF_const_${line}=1
845 done
846 exec < $tmp.v
847 while read line
848 do eval CONF_const_${line}=1
849 done
851 # mark the string literal values
854 cat <<!
855 ${head}
856 #include <sys/types.h>
857 #include <limits.h>
858 #include <unistd.h>$systeminfo$headers
859 ${tail}
860 #undef conf
862 sed 's/.*/conf "&" = &/' $tmp.q
863 } > $tmp.c
864 $cc -E $tmp.c 2>/dev/null |
865 sed -e '/conf[ ]*".*"[ ]*=[ ]*"/!d' -e 's/.*"\([^"]*\)".*/\1/' > $tmp.e
866 exec < $tmp.e
867 while read line
868 do eval CONF_string_${line}=1
869 done
871 # walk through the table
873 case $shell in
874 ksh) integer len name_max ;;
875 esac
876 name_max=1
877 export tmp name standard call cc
879 exec > $tmp.t
880 for key in $keys
881 do eval name=\"'$'CONF_name_$key\"
882 case $name in
883 '') continue ;;
884 $keep_name) ;;
885 *) continue ;;
886 esac
887 eval call=\"'$'CONF_call_$key\"
888 case $call in
889 $keep_call) ;;
890 *) continue ;;
891 esac
892 eval standard=\"'$'CONF_standard_$key\"
893 eval section=\"'$'CONF_section_$key\"
894 eval flags=\"'$'CONF_flags_$key\"
895 eval define=\"'$'CONF_define_$key\"
896 eval values=\"'$'CONF_values_$key\"
897 eval script=\"'$'CONF_script_$key\"
898 eval args=\"'$'CONF_args_$key\"
899 eval headers=\"'$'CONF_headers_$key\"
900 conf_name=$name
901 case $call in
902 QQ) call=XX
903 for c in SC PC CS
904 do case $flags in
905 *S*) case $section in
906 1) eval x='$'CONF_call_${c}_${standard}_${name} ;;
907 *) eval x='$'CONF_call_${c}_${standard}${section}_${name} ;;
908 esac
910 *) eval x='$'CONF_call_${c}_${name}
912 esac
913 case $x in
914 ?*) call=$x
915 break
917 esac
918 done
919 case $call in
920 XX) for c in SC PC CS
921 do case $flags in
922 *S*) case $section in
923 1) eval x='$'CONF_const__${c}_${standard}_${name} ;;
924 *) eval x='$'CONF_const__${c}_${standard}${section}_${name} ;;
925 esac
927 *) eval x='$'CONF_const__${c}_${name}
929 esac
930 case $x in
931 1) call=$c
932 break
934 esac
935 done
937 esac
938 case $call in
939 XX) case $standard in
940 C) standard=POSIX ;;
941 esac
942 case $flags in
943 *L*) flags=lFU ;;
944 *) flags=FU ;;
945 esac
947 esac
949 esac
950 case " $standards " in
951 *" $standard "*)
953 *) standards="$standards $standard"
955 esac
956 conf_standard=CONF_${standard}
957 case $call in
958 CS) conf_call=CONF_confstr
960 PC) conf_call=CONF_pathconf
962 SC) conf_call=CONF_sysconf
964 SI) conf_call=CONF_sysinfo
966 XX) conf_call=CONF_nop
968 esac
969 conf_op=-1
970 for s in _${call}_${standard}${section}_${name} _${call}_${standard}_${name} _${call}_${section}_${name} _${call}_${name} ${call}_${name}
971 do eval x='$'CONF_const_${s}
972 case $x in
973 1) conf_op=${s}
974 break
976 esac
977 done
978 conf_section=$section
979 conf_flags=0
980 case $flags in
981 *C*) conf_flags="${conf_flags}|CONF_DEFER_CALL" ;;
982 esac
983 case $flags in
984 *D*) conf_flags="${conf_flags}|CONF_DEFER_MM" ;;
985 esac
986 case $flags in
987 *F*) conf_flags="${conf_flags}|CONF_FEATURE" ;;
988 esac
989 case $flags in
990 *L*) conf_flags="${conf_flags}|CONF_LIMIT" ;;
991 esac
992 case $flags in
993 *M*) conf_flags="${conf_flags}|CONF_MINMAX" ;;
994 esac
995 case $flags in
996 *N*) conf_flags="${conf_flags}|CONF_NOSECTION" ;;
997 esac
998 case $flags in
999 *P*) conf_flags="${conf_flags}|CONF_PREFIXED" ;;
1000 esac
1001 case $flags in
1002 *S*) conf_flags="${conf_flags}|CONF_STANDARD" ;;
1003 esac
1004 case $flags in
1005 *U*) conf_flags="${conf_flags}|CONF_UNDERSCORE" ;;
1006 esac
1007 case $flags in
1008 *V*) conf_flags="${conf_flags}|CONF_NOUNDERSCORE" ;;
1009 esac
1010 case $flags in
1011 *W*) conf_flags="${conf_flags}|CONF_PREFIX_ONLY" ;;
1012 esac
1013 case $debug in
1014 ?*) case $standard in
1015 ????) sep=" " ;;
1016 ???) sep=" " ;;
1017 ??) sep=" " ;;
1018 ?) sep=" " ;;
1019 *) sep="" ;;
1020 esac
1021 echo "$command: test: $sep$standard $call $name" >&2
1023 esac
1024 case $call in
1025 CS|SI) conf_flags="${conf_flags}|CONF_STRING"
1026 string=1
1028 *) eval string='$'CONF_string_${key}
1030 esac
1031 conf_limit=0
1032 case $flags in
1033 *[Ll]*) d=
1034 case ${conf_name} in
1035 LONG_MAX|SSIZE_MAX)
1038 *) eval x='$'CONF_const_${conf_name}
1040 esac
1041 case $x in
1042 '') for s in ${values}
1043 do case $s in
1044 $sym) eval x='$'CONF_const_${s}
1045 case $x in
1046 1) eval a='$'CONF_const_${standard}_${s}
1047 case $a in
1048 $x) x= ;;
1049 *) x=$s ;;
1050 esac
1051 break
1053 esac
1055 [0123456789]*|[-+][0123456789]*)
1056 d=$s
1057 break
1059 esac
1060 done
1061 case ${x:+1}:$flags:$conf_op in
1062 :*:-1|:*X*:*)
1063 case $verbose in
1064 1) echo "$command: probe for ${conf_name} <limits.h> value" >&2 ;;
1065 esac
1067 case $CONF_getconf in
1068 ?*) if $CONF_getconf $conf_name > $tmp.x 2>/dev/null
1069 then x=`cat $tmp.x`
1070 case $x in
1071 undefined) x= ;;
1072 esac
1075 esac
1076 case ${x:+1} in
1077 '') case $script in
1078 '#'*) echo "$script" > $tmp.sh
1079 chmod +x $tmp.sh
1080 x=`./$tmp.sh 2>/dev/null`
1082 '') case $conf_name in
1083 SIZE_*|U*|*_MAX)
1084 f="%${LL_format}u"
1085 t="unsigned _ast_intmax_t"
1087 *) f="%${LL_format}d"
1088 t="_ast_intmax_t"
1090 esac
1091 cat > $tmp.c <<!
1092 ${head}
1093 #include <stdio.h>
1094 #include <sys/types.h>
1095 #include <limits.h>
1096 #include <unistd.h>$systeminfo$headers
1097 ${tail}
1099 main()
1101 printf("$f\n", ($t)$conf_name);
1102 return 0;
1106 *) cat > $tmp.c <<!
1107 ${head}
1108 #include <sys/types.h>
1109 #include <limits.h>
1110 #include <unistd.h>$systeminfo$headers
1111 ${tail}
1112 ${script}
1115 esac
1116 case $args in
1117 '') set "" ;;
1118 *) eval set '""' '"'$args'"'; shift ;;
1119 esac
1120 for a
1121 do case $script in
1122 '#'*) ./$tmp.sh $a > $tmp.x 2>/dev/null
1123 x=$?
1125 *) $cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null
1126 x=$?
1128 esac
1129 case $x in
1130 0) x=`cat $tmp.x`
1131 case $x in
1132 "-") x=$a ;;
1133 esac
1134 break
1136 *) x=
1138 esac
1139 done
1141 esac
1142 case $x in
1143 '') x=$d ;;
1144 esac
1146 esac
1147 case ${x:+1}:$flags:$conf_op in
1148 1:*:-1|1:*X*:*)
1149 conf_limit=$x
1150 case $flags in
1151 *L*) ;;
1152 *) conf_flags="${conf_flags}|CONF_LIMIT" ;;
1153 esac
1154 conf_flags="${conf_flags}|CONF_LIMIT_DEF"
1155 case $string:$x in
1156 1:*) cat >> $tmp.l <<!
1157 printf("#ifndef ${conf_name}\n");
1158 printf("#define ${conf_name} \"${x}\"\n");
1159 printf("#endif\n");
1162 *:U*) cat >> $tmp.l <<!
1163 printf("#ifndef ${conf_name}\n");
1164 printf("#ifndef ${x}\n");
1165 printf("#define ${x} %lu\n", ${x});
1166 printf("#endif\n");
1167 printf("#define ${conf_name} ${x}\n");
1168 printf("#endif\n");
1171 *:$sym) cat >> $tmp.l <<!
1172 printf("#ifndef ${conf_name}\n");
1173 printf("#ifndef ${x}\n");
1174 printf("#define ${x} %ld\n", ${x});
1175 printf("#endif\n");
1176 printf("#define ${conf_name} ${x}\n");
1177 printf("#endif\n");
1180 *) cat >> $tmp.l <<!
1181 printf("#ifndef ${conf_name}\n");
1182 printf("#define ${conf_name} ${x}\n");
1183 printf("#endif\n");
1186 esac
1188 esac
1190 esac
1192 esac
1193 case $section in
1194 [01]) ;;
1195 *) case $flags in
1196 *N*) ;;
1197 *) name=${section}_${name} ;;
1198 esac
1199 standard=${standard}${section}
1201 esac
1202 conf_minmax=0
1203 case $call:$standard:$flags in
1204 *:C:*M*)for s in _${standard}_${conf_name} ${values}
1205 do case $s in
1206 $sym) ;;
1207 *) conf_minmax=$s
1208 conf_flags="${conf_flags}|CONF_MINMAX_DEF"
1209 break
1211 esac
1212 done
1214 *:C:*) ;;
1215 [CPSX][CSX]:*:*[FM]*)
1217 for s in _${standard}_${conf_name} ${values}
1218 do case $s in
1219 $sym) eval x='$'CONF_const_${s} ;;
1220 *) x=1 ;;
1221 esac
1222 case $x in
1223 1) conf_minmax=$s
1224 case $flags in
1225 *M*) conf_flags="${conf_flags}|CONF_MINMAX_DEF" ;;
1226 esac
1227 break
1229 esac
1230 done
1231 case ${x:+1}:${script:+1} in
1232 :1) case $verbose in
1233 1) echo "$command: probe for _${standard}_${conf_name} minmax value" >&2 ;;
1234 esac
1235 case $CONF_getconf in
1236 ?*) if $CONF_getconf _${standard}_${conf_name} > $tmp.x 2>/dev/null
1237 then x=`cat $tmp.x`
1238 case $x in
1239 undefined) x= ;;
1240 esac
1243 esac
1244 case $x in
1245 '') case $script in
1246 '#'*) echo "$script" > $tmp.sh
1247 chmod +x $tmp.sh
1248 x=`./$tmp.sh 2>/dev/null`
1250 *) cat > $tmp.c <<!
1251 ${head}
1252 #include <sys/types.h>
1253 #include <limits.h>
1254 #include <unistd.h>$systeminfo$headers
1255 ${tail}
1256 ${script}
1259 esac
1260 case $args in
1261 '') set "" ;;
1262 *) eval set '""' "$args"; shift ;;
1263 esac
1264 for a
1265 do case $script in
1266 '#'*) ./$tmp.sh $a > $tmp.x 2>/dev/null
1267 x=$?
1269 *) $cc $a -o $tmp.exe $tmp.c >/dev/null 2>&1 && ./$tmp.exe > $tmp.x 2>/dev/null
1270 x=$?
1272 esac
1273 case $x in
1274 0) x=`cat $tmp.x`
1275 case $x in
1276 "-") x=$a ;;
1277 esac
1278 break
1280 *) x=
1282 esac
1283 done
1285 esac
1286 case $x in
1287 ?*) conf_minmax=$x
1288 case $flags in
1289 *M*) conf_flags="${conf_flags}|CONF_MINMAX_DEF" ;;
1290 esac
1292 esac
1294 esac
1296 esac
1297 case $string in
1298 1) conf_limit="{ 0, $conf_limit }" conf_minmax="{ 0, $conf_minmax }"
1300 *) case $conf_limit in
1301 0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
1303 *[!0123456789abcdefABCDEF]*)
1304 conf_limit=0
1306 *[!0123456789]*)
1307 conf_limit=0x$conf_limit
1309 esac
1310 case $conf_minmax in
1311 0[xX]*|-*|+*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
1313 *[!0123456789abcdefABCDEF]*)
1314 conf_minmax=0
1316 *[!0123456789]*)
1317 conf_minmax=0x$conf_minmax
1319 esac
1320 case $conf_limit in
1321 ?*[-+]*|*['()']*)
1323 *[lLuU])
1324 case $LL_suffix in
1325 ??) case $conf_limit in
1326 *[!lL][lL]|*[!lL][lL][uU])
1327 conf_limit=${conf_limit}L
1329 esac
1331 esac
1333 -*[2468])
1334 case $shell in
1335 ksh) p=${conf_limit%?}
1336 s=${conf_limit#$p}
1337 ((s=s-1))
1339 *) eval `echo '' $conf_limit | sed 's/ *\(.*\)\(.\) */p=\1 s=\2/'`
1340 s=`expr $s - 1`
1342 esac
1343 conf_limit=${p}${s}${LL_suffix}-1${LL_suffix}
1345 0[xX]*[abcdefABCDEF])
1346 conf_limit=${conf_limit}${LL_suffix}
1348 -*[0123456789])
1349 conf_limit=${conf_limit}${LL_suffix}
1351 *[0123456789])
1352 conf_limit=${conf_limit}U${LL_suffix}
1354 esac
1355 case $conf_minmax in
1356 ?*[-+]*|*['()']*)
1358 *[lLuU])
1359 case $LL_suffix in
1360 ??) case $conf_minmax in
1361 *[!lL][lL]|*[!lL][lL][uU])
1362 conf_minmax=${conf_minmax}L
1364 esac
1366 esac
1368 -*[2468])
1369 case $shell in
1370 ksh) p=${conf_minmax%?}
1371 s=${conf_minmax#$p}
1372 ((s=s-1))
1374 *) eval `echo '' $conf_minmax | sed 's/ *\(.*\)\(.\) */p=\1 s=\2/'`
1375 s=`expr $s - 1`
1377 esac
1378 conf_minmax=${p}${s}${LL_suffix}-1${LL_suffix}
1380 0[xX]*[abcdefABCDEF])
1381 conf_minmax=${conf_minmax}${LL_suffix}
1383 -*[0123456789])
1384 conf_minmax=${conf_minmax}${LL_suffix}
1386 *[0123456789])
1387 conf_minmax=${conf_minmax}U${LL_suffix}
1389 esac
1390 conf_limit="{ $conf_limit, 0 }" conf_minmax="{ $conf_minmax, 0 }"
1392 esac
1393 case $conf_flags in
1394 '0|'*) case $shell in
1395 ksh) conf_flags=${conf_flags#0?} ;;
1396 *) conf_flags=`echo "$conf_flags" | sed 's/^0.//'` ;;
1397 esac
1399 esac
1400 echo "{ \"$conf_name\", $conf_limit, $conf_minmax, $conf_flags, $conf_standard, $conf_section, $conf_call, $conf_op },"
1401 case $shell in
1402 ksh) len=${#conf_name}
1403 if ((len>=name_max))
1404 then ((name_max=len+1))
1407 *) len=`echo ${conf_name} | wc -c`
1408 if expr \( $len - 1 \) \>= ${name_max} >/dev/null
1409 then name_max=$len
1412 esac
1413 done
1414 exec > /dev/null
1415 case $debug in
1416 -d6) exit ;;
1417 esac
1419 # conf string table
1421 base=conftab
1422 case $verbose in
1423 1) echo "$command: generate ${base}.h string table header" >&2 ;;
1424 esac
1425 case $shell in
1426 ksh) ((name_max=name_max+3)); ((name_max=name_max/4*4)) ;; # bsd /bin/sh !
1427 *) name_max=`expr \( $name_max + 3 \) / 4 \* 4` ;;
1428 esac
1430 cat <<!
1431 #ifndef _CONFTAB_H
1432 #define _CONFTAB_H
1433 $systeminfo
1435 ${generated}
1437 #if !defined(const) && !defined(__STDC__) && !defined(__cplusplus) && !defined(c_plusplus)
1438 #define const
1439 #endif
1441 #define conf _ast_conf_data
1442 #define conf_elements _ast_conf_ndata
1444 #define prefix _ast_conf_prefix
1445 #define prefix_elements _ast_conf_nprefix
1447 #define CONF_nop 0
1448 #define CONF_confstr 1
1449 #define CONF_pathconf 2
1450 #define CONF_sysconf 3
1451 #define CONF_sysinfo 4
1454 index=0
1455 for standard in $standards
1456 do echo "#define CONF_${standard} ${index}"
1457 case $shell in
1458 ksh) ((index=index+1)) ;;
1459 *) index=`expr ${index} + 1` ;;
1460 esac
1461 done
1462 echo "#define CONF_call ${index}"
1463 case $CONF_getconf in
1464 ?*) echo
1465 echo "#define _pth_getconf \"$CONF_getconf\""
1466 case $CONF_getconf_a in
1467 ?*) echo "#define _pth_getconf_a \"$CONF_getconf_a\"" ;;
1468 esac
1470 esac
1471 cat <<!
1473 #define CONF_DEFER_CALL 0x0001
1474 #define CONF_DEFER_MM 0x0002
1475 #define CONF_FEATURE 0x0004
1476 #define CONF_LIMIT 0x0008
1477 #define CONF_LIMIT_DEF 0x0010
1478 #define CONF_MINMAX 0x0020
1479 #define CONF_MINMAX_DEF 0x0040
1480 #define CONF_NOSECTION 0x0080
1481 #define CONF_NOUNDERSCORE 0x0100
1482 #define CONF_PREFIX_ONLY 0x0200
1483 #define CONF_PREFIXED 0x0400
1484 #define CONF_STANDARD 0x0800
1485 #define CONF_STRING 0x1000
1486 #define CONF_UNDERSCORE 0x2000
1487 #define CONF_USER 0x4000
1489 struct Conf_s; typedef struct Conf_s Conf_t;
1491 typedef struct Value_s
1493 intmax_t number;
1494 const char* string;
1495 } Value_t;
1497 struct Conf_s
1499 const char name[${name_max}];
1500 Value_t limit;
1501 Value_t minmax;
1502 unsigned int flags;
1503 short standard;
1504 short section;
1505 short call;
1506 short op;
1509 typedef struct Prefix_s
1511 const char name[16];
1512 short length;
1513 short standard;
1514 short call;
1515 } Prefix_t;
1517 extern const Conf_t conf[];
1518 extern int conf_elements;
1520 extern const Prefix_t prefix[];
1521 extern int prefix_elements;
1523 #endif
1525 } > $tmp.2
1526 case $debug in
1527 -d7) echo $command: $tmp.2 ${base}.h ;;
1528 *) cmp -s $tmp.2 ${base}.h 2>/dev/null || mv $tmp.2 ${base}.h ;;
1529 esac
1531 case $verbose in
1532 1) echo "$command: generate ${base}.c string table" >&2 ;;
1533 esac
1535 cat <<!
1536 ${head}
1537 #include <sys/types.h>
1538 #include <limits.h>
1539 #include <unistd.h>$systeminfo$headers
1540 ${tail}
1541 #include "${base}.h"
1543 ${generated}
1546 * prefix strings -- the first few are indexed by Conf_t.standard
1549 const Prefix_t prefix[] =
1552 for standard in $standards
1553 do case $shell in
1554 ksh) len=${#standard} ;;
1555 *) len=`echo ${standard} | wc -c`; len=`expr $len - 1` ;;
1556 esac
1557 echo " \"${standard}\", ${len}, CONF_${standard}, -1,"
1558 done
1559 cat <<!
1560 "XX", 2, CONF_POSIX, CONF_nop,
1561 "CS", 2, CONF_POSIX, CONF_confstr,
1562 "PC", 2, CONF_POSIX, CONF_pathconf,
1563 "SC", 2, CONF_POSIX, CONF_sysconf,
1564 "SI", 2, CONF_SVID, CONF_sysinfo,
1567 int prefix_elements = (int)sizeof(prefix) / (int)sizeof(prefix[0]);
1570 * conf strings sorted in ascending order
1573 const Conf_t conf[] =
1576 cat $tmp.t
1577 cat <<!
1580 int conf_elements = (int)sizeof(conf) / (int)sizeof(conf[0]);
1582 } > $tmp.4
1583 case $debug in
1584 -d7) echo $command: $tmp.4 ${base}.c ;;
1585 *) cmp -s $tmp.4 ${base}.c 2>/dev/null || mv $tmp.4 ${base}.c ;;
1586 esac
1588 # limits.h generation code
1590 base=conflim
1591 case $verbose in
1592 1) echo "$command: generate ${base}.h supplemental <limits.h> values" >&2 ;;
1593 esac
1595 cat <<!
1596 ${generated}
1599 * supplemental <limits.h> values
1603 test -f $tmp.l && cat $tmp.l
1604 } > $tmp.5
1605 case $debug in
1606 -d7) echo $command: $tmp.5 ${base}.h ;;
1607 *) cmp -s $tmp.5 ${base}.h 2>/dev/null || mv $tmp.5 ${base}.h ;;
1608 esac
1609 exit 0