This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
First pass at d_static_inline.U. Needs to be revised
[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:
13?MAKE:d_static_inline perl_static_inline: Compile Setvar cat echo run rm_try
14?MAKE: -pick add $@ %<
15?S:d_static_inline:
16?S: This variable conditionally defines the HAS_STATIC_INLINE symbol,
17?S: which indicates that the C compiler supports C99-style static
18?S: inline. That is, the function can't be called from another
19?S: translation unit.
20?S:.
21?S:perl_static_inline:
22?S: This variable defines the PERL_STATIC_INLINE symbol to
23?S: the best-guess incantation to use for static inline functions.
24?S: Possibilities include
25?S: static inline (c99)
26?S: static __inline__ (gcc -ansi)
27?S: static __inline (MSVC)
28?S: static (c89 compilers)
29?S:.
30?C:HAS_STATIC_INLINE :
31?C: This symbol, if defined, indicates that the C compiler supports
32?C: supports C99-style static inline. That is, the function can't
33?C: be called from another translation unit.
34?C:.
35?C:PERL_STATIC_INLINE:
36?C: This symbol gives the best-guess incantation to use for static
37?C: inline functions. If HAS_STATIC_INLINE is defined, this will
38?C: give C99-style inline. If HAS_STATIC_INLINE is not defined,
39?C: this will give a plain 'static'. It will always be defined
40?C: to something that gives static linkage.
41?C: Possibilities include
42?C: static inline (c99)
43?C: static __inline__ (gcc -ansi)
44?C: static __inline (MSVC)
45?C: static (c89 compilers)
46?C:.
47?H:#$d_static_inline HAS_STATIC_INLINE /**/
48?H:#define PERL_STATIC_INLINE $perl_static_inline /**/
49?H:.
50?LINT:set d_static_inline
51?F:!try
52: see what flavor, if any, of static inline is supported
53echo " "
54?X: Build two programs. The first uses static inline in file a.c and
55?X: should work. The second also includes b.c which tries to link against
56?X: the static function in a.c. This should fail.
57?X:.
58$cat > try.c <<'EOCP'
59#include <stdlib.h>
60extern int f_via_a(int x);
61extern int f_via_b(int x);
62int main(int argc, char **argv)
63{
64 int y;
65
66 y = f_via_a(0);
67#ifdef USE_B
68 y = f_via_b(0);
69#endif
70 if (y == 42) {
71 return EXIT_SUCCESS;
72 }
73 else {
74 return EXIT_FAILURE;
75 }
76}
77EOCP
78$cat > a.c <<'EOCP'
79static inline int f(int x) {
80 int y;
81 y = x + 42;
82 return y;
83}
84
85int f_via_a(int x)
86{
87 return f(x);
88}
89EOCP
90$cat > b.c <<'EOCP'
91extern int f(int x);
92
93int f_via_b(int x)
94{
95 return f(x);
96}
97EOCP
98val="$undef"
99set try a.c
100if eval $compile && $run ./try; then
101 # Now make sure there is no external linkage of static
102 # functions
103 set try -DUSE_B a.c b.c
104 if eval $compile && $run ./try; then
105 $echo "Your compiler supports static inline, " >&4
106 $echo "but it also creates an external definition," >&4
107 $echo "so I won't use it." >&4
108 val=$undef
109 else
110 $echo "Your compiler supports static inline." >&4
111 val=$define
112 fi
113else
114 $echo "Your compiler does NOT support static inline." >&4
115 val="$undef"
116fi
117set d_static_inline
118eval $setvar
119$rm_try
120