b043298e3da0e45cf9f86c314e653742c7f44544
[mono.git] / eglib / configure.ac
1 #
2 # Copyright 2012 Xamarin Inc
3 #
4 AC_INIT(eglib, [0.3],
5         [http://bugzilla.xamarin.com/enter_bug.cgi?classification=Mono])
6
7 AC_CONFIG_SRCDIR([README])
8 AC_CONFIG_MACRO_DIR([m4])
9 AC_CANONICAL_SYSTEM
10 AC_CANONICAL_HOST
11
12 AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar no-dist-gzip foreign])
13 AC_CONFIG_HEADERS([config.h])
14 AM_MAINTAINER_MODE
15
16 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
17
18 AC_PROG_CC
19 AM_PROG_LIBTOOL
20 # Use dolt (http://dolt.freedesktop.org/) instead of libtool for building.
21 DOLT
22 GNUC_PRETTY=
23 GNUC_UNUSED=
24 BREAKPOINT="G_STMT_START { raise (SIGTRAP); } G_STMT_END"
25 if test x$GCC = xyes; then
26    GNUC_UNUSED='__attribute__((__unused__))'
27    GNUC_NORETURN='__attribute__((__noreturn__))'
28    case $host_cpu in
29      i*86|x86_64) BREAKPOINT="G_STMT_START { __asm__ (\"int \$03\"); } G_STMT_END" ;;
30    esac
31 fi
32 AC_SUBST(GNUC_PRETTY)
33 AC_SUBST(GNUC_UNUSED)
34 AC_SUBST(GNUC_NORETURN)
35 AC_SUBST(BREAKPOINT)
36
37 # We use a separate variable to pass down CPPFLAGS and CFLAGS from the main mono 
38 # configure, because of autoconf brokeness
39 if test "x$CPPFLAGS_FOR_EGLIB" != "x"; then
40    CPPFLAGS=$CPPFLAGS_FOR_EGLIB
41 fi
42 if test "x$CFLAGS_FOR_EGLIB" != "x"; then
43    CFLAGS=$CFLAGS_FOR_EGLIB
44 fi
45
46 CFLAGS="$CFLAGS -g -D_GNU_SOURCE"
47
48 AM_CONDITIONAL(CROSS_COMPILING, [test x$cross_compiling = xyes])
49 AC_C_BIGENDIAN([ORDER=G_BIG_ENDIAN],[ORDER=G_LITTLE_ENDIAN])
50
51 platform_darwin=no
52 platform_android=no
53
54 case $host in
55 *-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-cygwin* | *-*-windows*)
56     PATHSEP='\\'
57     SEARCHSEP=';'
58     OS="WIN32"
59     PIDTYPE='void *'
60     ;;
61 *-*darwin*)
62     platform_darwin=yes
63     PATHSEP='/'
64     SEARCHSEP=':'
65     OS="UNIX"
66     PIDTYPE='int'
67     ;;
68 *-*-linux-android*)
69     platform_android=yes
70         AC_DEFINE(PLATFORM_ANDROID,1,[Targeting the Android platform])
71     PATHSEP='/'
72     SEARCHSEP=':'
73     OS="UNIX"
74     PIDTYPE='int'
75     ;;
76 *)
77     PATHSEP='/'
78     SEARCHSEP=':'
79     OS="UNIX"
80     PIDTYPE='int'
81     ;;
82 esac
83
84 case $host in
85         *-*-solaris*)
86         CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS"
87         ;;
88 esac
89
90 case $target in
91 arm*-darwin*|aarch64*-*)
92     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE"
93     ;;
94 i*86-*-darwin*)
95     ORDER=G_LITTLE_ENDIAN
96     ;;
97 *-*-haiku*)
98     LDFLAGS="$LDFLAGS -ltextencoding"
99     ;;
100 *-*-openbsd*)
101     CFLAGS="$CFLAGS -pthread"
102     LDFLAGS="$LDFLAGS -pthread"
103     ;;
104 esac
105
106 target_osx=no
107 target_ios=no
108
109 if test "x$platform_darwin" = "xyes"; then
110         AC_TRY_COMPILE([#include "TargetConditionals.h"],[
111         #if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
112         #error fail this for ios
113         #endif
114         return 0;
115         ], [
116                 AC_DEFINE(TARGET_OSX,1,[The JIT/AOT targets OSX])
117                 target_osx=yes
118         ], [
119                 AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
120                 target_ios=yes
121         ])
122    AC_DEFINE(TARGET_MACH,1,[The JIT/AOT targets Apple platforms])
123 fi
124
125 AC_SUBST(ORDER)
126 AC_SUBST(CFLAGS)
127 AC_SUBST(PATHSEP)
128 AC_SUBST(SEARCHSEP)
129 AC_SUBST(OS)
130 AC_SUBST(PIDTYPE)
131 AM_CONDITIONAL(HOST_WIN32, test x$OS = xWIN32)
132 AM_CONDITIONAL(TARGET_WIN32, test x$OS = xWIN32)
133 AM_CONDITIONAL(PLATFORM_DARWIN, test x$platform_darwin = xyes)
134 AM_CONDITIONAL(PLATFORM_ANDROID, test x$platform_android = xyes)
135
136 # Defined for all targets/platforms using classic Windows API support.
137 AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support])
138 AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support])
139
140 AC_CHECK_SIZEOF(int)
141 AC_CHECK_SIZEOF(void *)
142 AC_CHECK_SIZEOF(long)
143 AC_CHECK_SIZEOF(long long)
144 AC_CHECK_FUNCS(strlcpy stpcpy strtok_r rewinddir vasprintf strerror_r)
145 AC_CHECK_FUNCS(getrlimit)
146 AC_CHECK_FUNCS(fork execv execve)
147
148 AC_ARG_WITH([overridable-allocators], [  --with-overridable-allocators  allow g_*alloc/g_free to call custom allocators set via g_mem_set_vtable])
149
150 if test x$with_overridable_allocators = xyes; then
151         AC_DEFINE(ENABLE_OVERRIDABLE_ALLOCATORS,1,[Overridable allocator support enabled])
152   AC_MSG_NOTICE([Overridable allocator support enabled])
153 else
154   AC_MSG_NOTICE([Overridable allocator support disabled])
155 fi
156
157 #
158 # Mono currently supports 10.6, but strndup is not available prior to 10.7; avoiding
159 # the detection of strndup on OS X so Mono built on 10.7+ still runs on 10.6. This can be
160 # removed once support for 10.6 is dropped.
161 #
162 # iOS detection of strndup and getpwuid_r is faulty for some reason so let's simply avoid it
163 #
164 if test x$target_osx = xyes; then
165 AC_CHECK_FUNCS(getpwuid_r)
166 elif test x$target_ios = xno; then
167 AC_CHECK_FUNCS(strndup getpwuid_r)
168 fi
169
170 AM_CONDITIONAL(NEED_VASPRINTF, test x$ac_cv_func_vasprintf = xno || test x$with_overridable_allocators = xyes)
171 AM_ICONV()
172 AC_SEARCH_LIBS(sqrtf, m)
173
174 # nanosleep may not be part of libc, also search it in other libraries
175 AC_SEARCH_LIBS(nanosleep, rt)
176
177 AC_SEARCH_LIBS(dlopen, dl)
178 old_ldflags="${LDFLAGS}"
179 LDFLAGS="${LDFLAGS} -Wl,-export-dynamic"
180 AC_TRY_LINK(, [int i;], found_export_dynamic=yes, found_export_dynamic=no)
181 if test $found_export_dynamic = no; then
182         LDFLAGS="${old_ldflags}"
183 fi
184
185 AC_MSG_CHECKING(for varargs macros)
186 AC_TRY_COMPILE([],[
187 int foo (int i, int j);
188 #define bar(...) foo (1, __VA_ARGS__)
189 void main () {
190          bar (2);
191 }
192 ],have_iso_varargs=yes,have_iso_varargs=no)
193 AC_MSG_RESULT($have_iso_varargs)
194 G_HAVE_ISO_VARARGS=0
195 if test "x$have_iso_varargs" = "xyes"; then
196    G_HAVE_ISO_VARARGS=1
197 fi
198 AC_SUBST(G_HAVE_ISO_VARARGS)
199
200 AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h sys/wait.h pwd.h iconv.h localcharset.h sys/types.h sys/resource.h)
201 AC_CHECK_LIB([iconv], [locale_charset],[],[AC_CHECK_LIB([charset], [locale_charset],[LIBS+="-liconv -lcharset"])])
202 AC_CHECK_HEADER(alloca.h, [HAVE_ALLOCA_H=1], [HAVE_ALLOCA_H=0])
203 AC_SUBST(HAVE_ALLOCA_H)
204
205 if test $ac_cv_sizeof_void_p = $ac_cv_sizeof_int; then
206    GPOINTER_TO_INT="((gint) (ptr))"
207    GPOINTER_TO_UINT="((guint) (ptr))"
208    GINT_TO_POINTER="((gpointer) (v))"
209    GUINT_TO_POINTER="((gpointer) (v))"
210    GSIZE="int"
211    GSIZE_FORMAT='"u"'
212 elif test $ac_cv_sizeof_void_p = $ac_cv_sizeof_long; then
213    GPOINTER_TO_INT="((gint)(long) (ptr))"
214    GPOINTER_TO_UINT="((guint)(long) (ptr))"
215    GINT_TO_POINTER="((gpointer)(glong) (v))"
216    GUINT_TO_POINTER="((gpointer)(gulong) (v))"
217    GSIZE="long"
218    GSIZE_FORMAT='"lu"'
219 elif test $ac_cv_sizeof_void_p = $ac_cv_sizeof_long_long; then
220    GPOINTER_TO_INT="((gint)(long long) (ptr))"
221    GPOINTER_TO_UINT="((guint)(unsigned long long) (ptr))"
222    GINT_TO_POINTER="((gpointer)(long long) (v))"
223    GUINT_TO_POINTER="((gpointer)(unsigned long long) (v))"
224    GSIZE="long long"
225    GSIZE_FORMAT='"I64u"'
226 else
227    AC_MSG_ERROR([unsupported pointer size])
228 fi
229
230 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
231
232 pkg_config_path=
233 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir      Change pkg-config dir to custom dir],
234         if test x$with_crosspkgdir = "x"; then
235                 if test -s $PKG_CONFIG_PATH; then
236                         pkg_config_path=$PKG_CONFIG_PATH
237                 fi
238         else
239                 pkg_config_path=$with_crosspkgdir
240                 PKG_CONFIG_PATH=$pkg_config_path
241                 export PKG_CONFIG_PATH
242         fi
243 )
244
245 AC_ARG_ENABLE(werror, [  --enable-werror Pass -Werror to the C compiler], werror_flag=$enableval, werror_flag=no)
246 if test x$werror_flag = xyes; then
247         WERROR_CFLAGS="-Werror"
248 fi
249 AC_SUBST([WERROR_CFLAGS])
250
251 AC_SUBST(GPOINTER_TO_INT)
252 AC_SUBST(GPOINTER_TO_UINT)
253 AC_SUBST(GINT_TO_POINTER)
254 AC_SUBST(GUINT_TO_POINTER)
255 AC_SUBST(GSIZE)
256 AC_SUBST(GSIZE_FORMAT)
257 AC_SUBST(G_GUINT64_FORMAT)
258 AC_SUBST(G_GINT64_FORMAT)
259 AC_SUBST(G_GUINT32_FORMAT)
260 AC_SUBST(G_GINT32_FORMAT)
261
262 AC_OUTPUT([
263 Makefile
264 m4/Makefile
265 src/Makefile
266 src/eglib-config.h
267 test/Makefile
268 ])