dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libshell / common / features / math.sh
blobb06fcefbb294e6fb6695f88aa3d5b06e5d1a56e0
1 ########################################################################
2 # #
3 # This software is part of the ast package #
4 # Copyright (c) 1982-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 # David Korn <dgk@research.att.com> #
18 # #
19 ########################################################################
20 : generate the ksh math builtin table
21 : include math.tab
23 # @(#)math.sh (AT&T Research) 2009-08-18
25 command=$0
26 iffeflags="-n -v"
27 iffehdrs="math.h ieeefp.h"
28 iffelibs="-lm"
29 table=/dev/null
31 eval $1
32 shift
33 table=$1
35 names=
36 tests=
38 : check long double
40 eval `iffe $iffeflags -c "$cc" - typ long.double 2>&$stderr`
42 : check ast_standards.h
44 eval `iffe $iffeflags -F ast_standards.h -c "$cc" - tst use_ast_standards -lm 'note{' 'math.h needs ast_standards.h' '}end' 'link{' '#include <math.h>' '#ifndef isgreater' '#define isgreater(a,b) 0' '#endif' 'int main() { return isgreater(0.0,1.0); }' '}end'`
45 case $_use_ast_standards in
46 1) iffeflags="$iffeflags -F ast_standards.h" ;;
47 esac
49 : read the table
51 exec < $table
52 while read type args name aka comment
53 do case $type in
54 [fi]) names="$names $name"
55 tests="$tests,$name"
56 case $_typ_long_double in
57 1) tests="$tests,${name}l" ;;
58 esac
59 eval TYPE_$name=$type ARGS_$name=$args AKA_$name=$aka
61 esac
62 done
64 : check the math library
66 eval `iffe $iffeflags -c "$cc" - lib $tests $iffehdrs $iffelibs 2>&$stderr`
67 lib=
68 for name in $names
69 do eval x='$'_lib_${name}l y='$'_lib_${name}
70 case $x in
71 1) lib="$lib,${name}l" ;;
72 esac
73 case $y in
74 1) case $x in
75 '') lib="$lib,${name}" ;;
76 esac
78 esac
79 done
80 eval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr`
82 cat <<!
83 #pragma prototyped
85 /* : : generated by $command from $table : : */
87 typedef Sfdouble_t (*Math_f)(Sfdouble_t,...);
90 case $_use_ast_standards in
91 1) echo "#include <ast_standards.h>" ;;
92 esac
93 echo "#include <math.h>"
94 case $_hdr_ieeefp in
95 1) echo "#include <ieeefp.h>" ;;
96 esac
97 echo
99 : generate the intercept functions and table entries
101 nl='
103 ht=' '
104 tab=
105 for name in $names
106 do eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name}
107 case $x:$y in
108 1:*) f=${name}l
109 t=Sfdouble_t
110 local=
112 *:1) f=${name}
113 t=double
114 local=$_typ_long_double
116 *) case $aka in
117 *=*) f=${aka%%=*}
118 v=${aka#*=}
119 eval x='$'_lib_${f}l y='$'_lib_${f}
120 case $x:$y in
121 1:*) f=${f}l
123 *:1) ;;
124 *) continue
126 esac
127 L=local_$name r=int R=1
128 echo "#ifdef $v${nl}static $r $L(Sfdouble_t x) { return $f(x) == $v; }${nl}#endif"
129 tab="$tab$nl#ifdef $v$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)${L},${nl}#endif"
131 esac
132 continue
134 esac
135 eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f
136 case $r in
137 i) L=int r=int R=1 ;;
138 *) L=Sfdouble_t r=$t R=0 ;;
139 esac
140 case $d:$m:$n in
141 1:*:*|*:1:*)
143 *:*:1) code="extern $r $f("
144 sep=
145 for p in 1 2 3 4 5 6 7
146 do code="$code${sep}$t"
147 case $a in
148 $p) break ;;
149 esac
150 sep=","
151 done
152 code="$code);"
153 echo "$code"
155 esac
156 case $local:$m:$n:$d in
157 1:*:*:*|*:1:*:*|*:*:1:)
158 args=
159 code="static $L local_$f("
160 sep=
161 for p in 1 2 3 4 5 6 7 8 9
162 do args="$args${sep}a$p"
163 code="$code${sep}Sfdouble_t a$p"
164 case $a in
165 $p) break ;;
166 esac
167 sep=","
168 done
169 code="$code){return $f($args);}"
170 echo "$code"
171 f=local_$f
173 esac
174 for x in $name $aka
175 do tab="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f,"
176 done
177 done
178 tab="$tab$nl$ht\"\",$ht$ht(Math_f)0"
180 cat <<!
183 * first byte is two-digit octal number. Last digit is number of args
184 * first digit is 0 if return value is double, 1 for integer
186 const struct mathtab shtab_math[] =
187 {$tab