Update lightrec 20220910 (#686)
[pcsx_rearmed.git] / deps / lightning / configure.ac
1 dnl
2 dnl Copyright 2000, 2001, 2002, 2012-2019 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GNU lightning.
5 dnl
6 dnl GNU lightning is free software; you can redistribute it and/or modify it
7 dnl under the terms of the GNU Lesser General Public License as published
8 dnl by the Free Software Foundation; either version 3, or (at your option)
9 dnl any later version.
10 dnl
11 dnl GNU lightning is distributed in the hope that it will be useful, but
12 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 dnl or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14 dnl License for more details.
15 dnl
16
17 AC_PREREQ(2.64)
18 AC_INIT([GNU lightning], 2.1.3, pcpa@gnu.org, lightning)
19 AC_CONFIG_AUX_DIR([build-aux])
20 AC_CANONICAL_TARGET
21 AC_CONFIG_SRCDIR([Makefile.am])
22 AM_INIT_AUTOMAKE([dist-bzip2])
23 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
24 AC_CONFIG_MACRO_DIR([m4])
25
26 AC_CONFIG_HEADERS([config.h])
27
28 AC_PROG_CC
29 gl_EARLY
30 AM_PROG_AR
31 LT_INIT
32 gl_INIT
33
34 case "$target_cpu" in
35     ia64)
36         case "$host_os" in
37             # Only supported mode
38             *hpux*)
39                 LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -mlp64"             ;;
40             *)                                  ;;
41         esac                                    ;;
42     *mips*)
43         case "$host_os" in
44             # (Hack) Flags to pass configure with gcc 3.x
45             # Should not set LIGHTNINT_CFLAGS
46             *irix*)
47                 CFLAGS="$CFLAGS -D__c99 -Drestrict=";;
48             *)                                  ;;
49         esac                                    ;;
50     alpha*)
51         case "$host_os" in
52             osf*)
53                 # Get proper varargs and mmap prototypes and definitions
54                 CFLAGS="$CFLAGS -D_ANSI_C_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE -D_POSIX_C_SOURCE=199309L"
55                 # Want to generate NaN with 0.0/0.0 and Inf with 1.0/0.0
56                 if test x$GCC = "xyes"; then
57                     CFLAGS="$CFLAGS -mieee"
58                 else
59                     CFLAGS="$CFLAGS -ieee_with_no_inexact"
60                 fi                              ;;
61             *)                                  ;;
62         esac                                    ;;
63     *)                                          ;;
64 esac
65
66 AC_CHECK_FUNCS(mmap mremap ffsl getopt_long_only isnan isinf,,)
67
68 AC_CHECK_HEADERS([getopt.h stdint.h],,,)
69
70 AC_ARG_ENABLE(disassembler,
71               AS_HELP_STRING([--enable-disassembler],
72                              [Enable jit disassembler using binutils]),
73               [DISASSEMBLER=$enableval], [DISASSEMBLER=auto])
74 if test "x$DISASSEMBLER" != "xno"; then
75
76     AC_CHECK_LIB(iberty, htab_try_create, ,
77                  [HAVE_IBERTY="no"])
78     AC_CHECK_LIB(bfd, bfd_init, ,
79                  [HAVE_BFD="no"])
80     AC_CHECK_LIB(z, compressBound, ,
81                  [HAVE_Z="no"])
82     AC_CHECK_LIB(opcodes, init_disassemble_info, ,
83                  [HAVE_OPCODES="no"])
84
85     if test "x$HAVE_IBERTY" = "xno"; then
86         if test "x$DISASSEMBLER" = "xyes"; then
87             AC_MSG_ERROR([libiberty not found])
88         else
89             AC_MSG_WARN([libiberty not found])
90             DISASSEMBLER="no"
91         fi
92     fi
93
94     if test "x$HAVE_BFD" = "xno"; then
95         if test "x$DISASSEMBLER" = "xyes"; then
96             AC_MSG_ERROR([binutils BFD not found, see http://www.gnu.org/software/binutils/])
97         else
98             AC_MSG_WARN([binutils BFD not found, see http://www.gnu.org/software/binutils/])
99             DISASSEMBLER="no"
100         fi
101     fi
102
103     if test "x$HAVE_Z" = "xno"; then
104         if test "x$DISASSEMBLER" = "xyes"; then
105             AC_MSG_ERROR([zlib not found, see https://zlib.net/])
106         else
107             AC_MSG_WARN([zlib not found, see https://zlib.net/])
108             DISASSEMBLER="no"
109         fi
110     fi
111
112     if test "x$HAVE_OPCODES" = "xno"; then
113         if test "x$DISASSEMBLER" = "xyes"; then
114             AC_MSG_ERROR([binutils opcodes not found, see https://www.gnu.org/software/binutils/])
115         else
116             AC_MSG_WARN([binutils opcodes not found, see https://www.gnu.org/software/binutils/])
117             DISASSEMBLER="no"
118         fi
119     fi
120
121 fi
122 AM_CONDITIONAL(with_disassembler, [test "x$DISASSEMBLER" != "xno"])
123 if test "x$DISASSEMBLER" != "xno"; then
124     LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DDISASSEMBLER=1"
125     save_CFLAGS=$CFLAGS
126     CFLAGS="$CFLAGS -I$PWD/include -D_GNU_SOURCE"
127     AC_COMPILE_IFELSE([AC_LANG_SOURCE(
128         #include <lightning.h>
129         #include <lightning/jit_private.h>
130         #include <dis-asm.h>
131         int main(int argc, char *argv[])
132         {
133                 disassembler_ftype       print;
134                 bfd                     *abfd;
135                 print = disassembler(abfd);
136                 return 0;
137         }
138     )], [ac_cv_test_new_disassembler=no],,)
139     AC_COMPILE_IFELSE([AC_LANG_SOURCE(
140         #include <dis-asm.h>
141         int main(int argc, char *argv[])
142         {
143                 struct disassemble_info dinfo;
144                 INIT_DISASSEMBLE_INFO(dinfo, NULL, NULL, NULL);
145                 return 0;
146         }
147     )], [ac_cv_test_new_disassemble_info=yes],[ac_cv_test_new_disassemble_info=no],)
148     CFLAGS="$save_CFLAGS"
149     if test "x$ac_cv_test_new_disassembler" != "xno"; then
150         LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DBINUTILS_2_29=1"
151     fi
152     if test "x$ac_cv_test_new_disassemble_info" != "xno"; then
153         LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DBINUTILS_2_38=1"
154     fi
155 fi
156
157 AC_ARG_ENABLE(devel-disassembler,
158               AS_HELP_STRING([--enable-devel-disassembler],
159                              [Enable extra disassembly options]),
160               [DEVEL_DISASSEMBLER=$enableval], [DEVEL_DISASSEMBLER=no])
161 if test "x$DEVEL_DISASSEMBLER" != "xno"; then
162     if test "x$DISASSEMBLER" = "xno"; then
163         AC_MSG_ERROR(devel-disassembler needs disassembler enabled)
164     fi
165     LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DDEVEL_DISASSEMBLER=1"
166 fi
167
168 AC_ARG_ENABLE(assertions,
169               AS_HELP_STRING([--enable-assertions],
170                              [Enable runtime code generation assertions]),
171               [DEBUG=$enableval], [DEBUG=auto])
172 if test "x$DEBUG" = xyes; then
173     LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DDEBUG=1"
174 else
175     LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -DNDEBUG"
176     DEBUG=no
177 fi
178
179 # This option is only useful during development.
180 AC_ARG_ENABLE(devel-get-jit-size,
181               AS_HELP_STRING([--enable-devel-get-jit-size],
182                              [Devel mode to regenerate jit size information]),
183               [GET_JIT_SIZE=$enableval], [GET_JIT_SIZE=no])
184 AM_CONDITIONAL(get_jit_size, [test $GET_JIT_SIZE = yes])
185
186 case "$host_os" in
187     *bsd*|osf*)         SHLIB=""        ;;
188     *hpux*)             SHLIB="-ldld"   ;;
189     *)                  SHLIB="-ldl"    ;;
190 esac
191 AC_SUBST(SHLIB)
192
193 cpu=
194 case "$target_cpu" in
195     i?86|x86_64|amd64)  cpu=x86         ;;
196     *arm*)              cpu=arm         ;;
197     *mips*)             cpu=mips        ;;
198     *powerpc*)          cpu=ppc         ;;
199     *sparc*)            cpu=sparc       ;;
200     ia64)               cpu=ia64        ;;
201     hppa*)              cpu=hppa        ;;
202     aarch64)            cpu=aarch64     ;;
203     s390*)              cpu=s390        ;;
204     alpha*)             cpu=alpha       ;;
205     riscv*)             cpu=riscv       ;;
206     *)                                  ;;
207 esac
208 AM_CONDITIONAL(cpu_arm,     [test cpu-$cpu = cpu-arm])
209 AM_CONDITIONAL(cpu_mips,    [test cpu-$cpu = cpu-mips])
210 AM_CONDITIONAL(cpu_ppc,     [test cpu-$cpu = cpu-ppc])
211 AM_CONDITIONAL(cpu_sparc,   [test cpu-$cpu = cpu-sparc])
212 AM_CONDITIONAL(cpu_x86,     [test cpu-$cpu = cpu-x86])
213 AM_CONDITIONAL(cpu_ia64,    [test cpu-$cpu = cpu-ia64])
214 AM_CONDITIONAL(cpu_hppa,    [test cpu-$cpu = cpu-hppa])
215 AM_CONDITIONAL(cpu_aarch64, [test cpu-$cpu = cpu-aarch64])
216 AM_CONDITIONAL(cpu_s390,    [test cpu-$cpu = cpu-s390])
217 AM_CONDITIONAL(cpu_alpha,   [test cpu-$cpu = cpu-alpha])
218 AM_CONDITIONAL(cpu_riscv,   [test cpu-$cpu = cpu-riscv])
219
220 # Test x87 if both, x87 and sse2 available
221 ac_cv_test_x86_x87=
222 # Test arm instruction set if thumb instruction set available
223 ac_cv_test_arm_arm=
224 # Test sofware float if vfp available and not using hard float abi
225 ac_cv_test_arm_swf=
226
227 save_CFLAGS=$CFLAGS
228 CFLAGS="$CFLAGS -I$PWD/include -D_GNU_SOURCE"
229 if test x$cpu = x; then
230     AC_MSG_ERROR([cpu $target_cpu not supported])
231 elif test $cpu = x86; then
232     AC_RUN_IFELSE([AC_LANG_SOURCE([[
233     #include <lightning.h>
234     int main(void) {
235         int                 ac, flags;
236         unsigned int        eax, ebx, ecx, edx;
237         if (__WORDSIZE == 64)
238             return 1;
239         __asm__ volatile ("pushfl;\n\t"
240                           "popl %0;\n\t"
241                           "movl \$0x240000, %1;\n\t"
242                           "xorl %0, %1;\n\t"
243                           "pushl %1;\n\t"
244                           "popfl;\n\t"
245                           "pushfl;\n\t"
246                           "popl %1;\n\t"
247                           "xorl %0, %1;\n\t"
248                           "pushl %0;\n\t"
249                           "popfl"
250                           : "=r" (flags), "=r" (ac));
251         if ((ac & (1 << 21)) == 0)
252             return 1;
253         __asm__ volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
254                           : "=a" (eax), "=r" (ebx),
255                           "=c" (ecx), "=d" (edx)
256                           : "0" (1));
257         return (edx & 1 << 26) ? 0 : 1;
258     }
259     ]])],[ac_cv_test_x86_x87=yes],[],[ac_cv_test_x86_x87=no])
260 elif test $cpu = arm; then
261     AC_RUN_IFELSE([AC_LANG_SOURCE([[
262     #include <stdio.h>
263     int main(void) {
264     #if defined(__linux__)
265         FILE    *fp;
266         char     buf[128];
267         if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
268             return 1;
269         while (fgets(buf, sizeof(buf), fp)) {
270             if (strncmp(buf, "Features\t:", 10) == 0 &&
271                 strstr(buf + 10, "thumb")) {
272                 fclose(fp);
273                 return 0;
274             }
275         }
276         fclose(fp);
277     #elif defined(__thumb2__)
278         return 0;
279     #endif
280         return 1;
281     }
282     ]])],[ac_cv_test_arm_arm=yes],[],[ac_cv_test_arm_arm=no])
283     AC_RUN_IFELSE([AC_LANG_SOURCE([[
284     #include <stdio.h>
285     int main(void) {
286     #if defined(__linux__)
287         FILE    *fp;
288         char     buf[128];
289     #  if !defined(__ARM_PCS_VFP)
290         if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
291             return 1;
292         while (fgets(buf, sizeof(buf), fp)) {
293             if (strncmp(buf, "Features\t:", 10) == 0 &&
294                 strstr(buf + 10, "vfp")) {
295                 fclose(fp);
296                 return 0;
297             }
298         }
299         fclose(fp);
300     #  endif
301     #endif
302         return 1;
303     }
304     ]])],[ac_cv_test_arm_swf=yes],[],[ac_cv_test_arm_swf=no])
305 elif test $cpu = ppc; then
306     if test "x$DISASSEMBLER" != "xno"; then
307         save_LIBS="$LIBS"
308         LIBS="$LIBS $SHLIB"
309         AC_CHECK_FUNCS(disassemble_init_for_target disassemble_init_powerpc)
310         LIBS="$save_LIBS"
311     fi
312 fi
313 CFLAGS=$save_CFLAGS
314
315 AM_CONDITIONAL(test_x86_x87, [test x$ac_cv_test_x86_x87 = xyes])
316 AM_CONDITIONAL(test_arm_arm, [test x$ac_cv_test_arm_arm = xyes])
317 AM_CONDITIONAL(test_arm_swf, [test x$ac_cv_test_arm_swf = xyes])
318
319 AM_CONDITIONAL(test_nodata, [test cpu-$cpu = cpu-mips -o cpu-$cpu = cpu-ppc -o cpu-$cpu = cpu-sparc -o cpu-$cpu = cpu-x86 -o cpu-$cpu = cpu-ia64 -o cpu-$cpu = cpu-hppa -o cpu-$cpu = cpu-s390 -o cpu-$cpu = cpu-alpha])
320
321 if test $cpu = arm; then
322      AC_CHECK_LIB(m, sqrtf, ,
323         [AC_MSG_ERROR([sqrtf required but not available])])
324 fi
325 AC_SUBST(cpu)
326
327 AC_SUBST([LIGHTNING_CFLAGS])
328
329 if test $ac_cv_header_stdint_h = yes; then
330     AC_SUBST(MAYBE_INCLUDE_STDINT_H, ["#include <stdint.h>"])
331 fi
332
333 AC_OUTPUT([Makefile
334            lightning.pc
335            gnulib-lib/Makefile
336            doc/Makefile
337            include/Makefile
338            include/lightning/Makefile
339            include/lightning.h
340            lib/Makefile
341            check/Makefile])