1 ?RCS: $Id: d_static_inline.U,v $
3 ?RCS: Copyright (c) 2010 Andrew Dougherty
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.
11 ?RCS: Original Author: Andy Dougherty <doughera@lafayette.edu>
13 ?MAKE:d_static_inline perl_static_inline: Compile Setvar gccversion \
14 cat echo run hint rm rm_try
15 ?MAKE: -pick add $@ %<
17 ?S: This variable conditionally defines the HAS_STATIC_INLINE symbol,
18 ?S: which indicates that the C compiler supports C99-style static
19 ?S: inline. That is, the function can't be called from another
22 ?S:perl_static_inline:
23 ?S: This variable defines the PERL_STATIC_INLINE symbol to
24 ?S: the best-guess incantation to use for static inline functions.
25 ?S: Possibilities include
26 ?S: static inline (c99)
27 ?S: static __inline__ (gcc -ansi)
28 ?S: static __inline (MSVC)
29 ?S: static _inline (older MSVC)
30 ?S: static (c89 compilers)
32 ?C:HAS_STATIC_INLINE :
33 ?C: This symbol, if defined, indicates that the C compiler supports
34 ?C: C99-style static inline. That is, the function can't be called
35 ?C: from another translation unit.
37 ?C:PERL_STATIC_INLINE:
38 ?C: This symbol gives the best-guess incantation to use for static
39 ?C: inline functions. If HAS_STATIC_INLINE is defined, this will
40 ?C: give C99-style inline. If HAS_STATIC_INLINE is not defined,
41 ?C: this will give a plain 'static'. It will always be defined
42 ?C: to something that gives static linkage.
43 ?C: Possibilities include
44 ?C: static inline (c99)
45 ?C: static __inline__ (gcc -ansi)
46 ?C: static __inline (MSVC)
47 ?C: static _inline (older MSVC)
48 ?C: static (c89 compilers)
50 ?H:#$d_static_inline HAS_STATIC_INLINE /**/
51 ?H:#define PERL_STATIC_INLINE $perl_static_inline /**/
53 ?LINT:set d_static_inline
56 : see what flavor, if any, of static inline is supported
58 echo "Checking to see if your system supports static inline..."
59 ?X: Build two programs. The first uses static inline in file a.c and
60 ?X: should work. The second also includes b.c which tries to link against
61 ?X: the static function in a.c. This should fail.
65 extern int f_via_a(int x);
66 extern int f_via_b(int x);
67 int main(int argc, char **argv)
84 static INLINE int f(int x) {
104 # Respect a hint (or previous) value for perl_static_inline, if there is one.
105 case "$perl_static_inline" in
106 '') # Check the various possibilities, and break out on success.
107 # For gcc, prefer __inline__, which will still permit
108 # cflags.SH to add in -ansi.
109 case "$gccversion" in
110 '') xxx="inline __inline__ __inline _inline";;
111 *) xxx="__inline__ inline __inline _inline";;
113 for inline in $xxx; do
114 set try -DINLINE=$inline a.c
115 if eval $compile && $run ./try; then
116 # Now make sure there is no external linkage of static
118 set try -DINLINE=$inline -DUSE_B a.c b.c
119 if eval $compile && $run ./try; then
120 $echo "Your compiler supports static $inline, " >&4
121 $echo "but it also creates an external definition," >&4
122 $echo "so I won't use it." >&4
125 $echo "Your compiler supports static $inline." >&4
127 perl_static_inline="static $inline";
131 $echo "Your compiler does NOT support static $inline." >&4
136 *inline*) # Some variant of inline exists.
137 echo "Keeping your $hint value of $perl_static_inline."
140 static) # No inline capabilities
141 echo "Keeping your $hint value of $perl_static_inline."
144 *) # Unrecognized previous value -- blindly trust the supplied
145 # value and hope it makes sense. Use old value for
146 # d_static_inline, if there is one.
147 echo "Keeping your $hint value of $perl_static_inline."
148 case "$d_static_inline" in
150 *) val=$d_static_inline ;;
154 # Fallback to plain 'static' if nothing worked.
155 case "$perl_static_inline" in
157 perl_static_inline="static"