This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add probe for C99-style static inline.
[metaconfig.git] / U / compline / d_static_inline.U
CommitLineData
e4c387c1
AD
1?RCS: $Id: d_static_inline.U,v $
2?RCS:
3?RCS: Copyright (c) 2010 Andrew Dougherty
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: Andy Dougherty <doughera@lafayette.edu>
12?RCS:
c2508427
AD
13?MAKE:d_static_inline perl_static_inline: Compile Setvar gccversion \
14 cat echo run hint rm rm_try
e4c387c1
AD
15?MAKE: -pick add $@ %<
16?S:d_static_inline:
c2508427 17?S: This variable conditionally defines the HAS_STATIC_INLINE symbol,
e4c387c1
AD
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
20?S: translation unit.
21?S:.
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)
c2508427 29?S: static _inline (older MSVC)
e4c387c1
AD
30?S: static (c89 compilers)
31?S:.
32?C:HAS_STATIC_INLINE :
33?C: This symbol, if defined, indicates that the C compiler supports
c2508427
AD
34?C: C99-style static inline. That is, the function can't be called
35?C: from another translation unit.
e4c387c1
AD
36?C:.
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)
c2508427 47?C: static _inline (older MSVC)
e4c387c1
AD
48?C: static (c89 compilers)
49?C:.
50?H:#$d_static_inline HAS_STATIC_INLINE /**/
51?H:#define PERL_STATIC_INLINE $perl_static_inline /**/
52?H:.
53?LINT:set d_static_inline
c2508427 54?T:inline xxx
e4c387c1
AD
55?F:!try
56: see what flavor, if any, of static inline is supported
57echo " "
c2508427 58echo "Checking to see if your system supports static inline..."
e4c387c1
AD
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.
62?X:.
63$cat > try.c <<'EOCP'
64#include <stdlib.h>
65extern int f_via_a(int x);
66extern int f_via_b(int x);
67int main(int argc, char **argv)
68{
69 int y;
70
71 y = f_via_a(0);
72#ifdef USE_B
73 y = f_via_b(0);
74#endif
75 if (y == 42) {
76 return EXIT_SUCCESS;
77 }
78 else {
79 return EXIT_FAILURE;
80 }
81}
82EOCP
83$cat > a.c <<'EOCP'
c2508427 84static INLINE int f(int x) {
e4c387c1
AD
85 int y;
86 y = x + 42;
87 return y;
88}
89
90int f_via_a(int x)
91{
92 return f(x);
93}
94EOCP
95$cat > b.c <<'EOCP'
96extern int f(int x);
97
98int f_via_b(int x)
99{
100 return f(x);
101}
102EOCP
c2508427
AD
103
104# Respect a hint (or previous) value for perl_static_inline, if there is one.
105case "$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";;
112 esac
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
117 # functions
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
123 val=$undef
124 else
125 $echo "Your compiler supports static $inline." >&4
126 val=$define
127 perl_static_inline="static $inline";
128 break;
129 fi
130 else
131 $echo "Your compiler does NOT support static $inline." >&4
132 val="$undef"
133 fi
134 done
135 ;;
136*inline*) # Some variant of inline exists.
137 echo "Keeping your $hint value of $perl_static_inline."
138 val=$define
139 ;;
140static) # No inline capabilities
141 echo "Keeping your $hint value of $perl_static_inline."
142 val=$undef
143 ;;
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
149 '') val=$define ;;
150 *) val=$d_static_inline ;;
151 esac
152 ;;
153esac
154# Fallback to plain 'static' if nothing worked.
155case "$perl_static_inline" in
156'')
157 perl_static_inline="static"
158 val=$undef
159 ;;
160esac
e4c387c1
AD
161set d_static_inline
162eval $setvar
c2508427 163$rm -f a.[co] b.[co]
e4c387c1
AD
164$rm_try
165