Skip to content

Commit f1ad919

Browse files
committed
Better support for cross-compilation
1 parent 0236bbc commit f1ad919

File tree

6 files changed

+106
-40
lines changed

6 files changed

+106
-40
lines changed

Zend/Zend.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ int main()
276276
], [], [
277277
dnl Cross compilation needs something here.
278278
LIBZEND_MM_ALIGN=8
279+
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, 8, [ ])
280+
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, 3, [ ])
279281
])
280282
281283
AC_MSG_RESULT(done)

build/php.m4

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,15 @@ int main() {
14771477
], [
14781478
cookie_io_functions_use_off64_t=no
14791479
], [
1480-
cookie_io_functions_use_off64_t=no
1480+
dnl Cross compilation.
1481+
case $host_alias in
1482+
*linux*)
1483+
cookie_io_functions_use_off64_t=yes
1484+
;;
1485+
*)
1486+
cookie_io_functions_use_off64_t=no
1487+
;;
1488+
esac
14811489
])
14821490
14831491
else
@@ -1582,7 +1590,10 @@ AC_DEFUN([PHP_CHECK_FUNC_LIB],[
15821590
if test "$found" = "yes"; then
15831591
ac_libs=$LIBS
15841592
LIBS="$LIBS -l$2"
1585-
AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[found=no])
1593+
AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[
1594+
dnl Cross compilation.
1595+
found=yes
1596+
])
15861597
LIBS=$ac_libs
15871598
fi
15881599
@@ -2298,7 +2309,14 @@ int main()
22982309
],[
22992310
ac_cv_write_stdout=no
23002311
],[
2301-
ac_cv_write_stdout=no
2312+
case $host_alias in
2313+
*linux*)
2314+
ac_cv_write_stdout=yes
2315+
;;
2316+
*)
2317+
ac_cv_write_stdout=no
2318+
;;
2319+
esac
23022320
])
23032321
])
23042322
if test "$ac_cv_write_stdout" = "yes"; then

configure.ac

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ AC_PROG_CPP
133133
AC_USE_SYSTEM_EXTENSIONS
134134
AC_PROG_LN_S
135135

136+
if test "$cross_compiling" = yes ; then
137+
AC_MSG_CHECKING(for native build C compiler)
138+
AC_CHECK_PROGS(BUILD_CC, [gcc clang c99 c89 cc cl],none)
139+
AC_MSG_RESULT($BUILD_CC)
140+
else
141+
BUILD_CC=$CC
142+
fi
143+
136144
dnl Support systems with system libraries in e.g. /usr/lib64.
137145
PHP_ARG_WITH([libdir],
138146
[for system library directory],
@@ -645,7 +653,17 @@ int main(void) {
645653
freeaddrinfo(ai);
646654
return 0;
647655
}
648-
]])],[ac_cv_func_getaddrinfo=yes], [ac_cv_func_getaddrinfo=no], [ac_cv_func_getaddrinfo=no])],
656+
]])],[ac_cv_func_getaddrinfo=yes], [ac_cv_func_getaddrinfo=no], [
657+
dnl Cross compilation.
658+
case $host_alias in
659+
*linux*)
660+
ac_cv_func_getaddrinfo=yes
661+
;;
662+
*)
663+
ac_cv_func_getaddrinfo=no
664+
;;
665+
esac
666+
])],
649667
[ac_cv_func_getaddrinfo=no])])
650668
if test "$ac_cv_func_getaddrinfo" = yes; then
651669
AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function])
@@ -674,7 +692,19 @@ int main(void) {
674692
end:
675693
return 0;
676694
}
677-
]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no], [ac_cv__asm_goto=no])])
695+
]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no], [
696+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
697+
int main(void) {
698+
#if defined(__x86_64__) || defined(__i386__)
699+
__asm__ goto("jmp %l0\n" :::: end);
700+
#elif defined(__aarch64__)
701+
__asm__ goto("b %l0\n" :::: end);
702+
#endif
703+
end:
704+
return 0;
705+
}
706+
]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no])
707+
])])
678708

679709
if test "$ac_cv__asm_goto" = yes; then
680710
AC_DEFINE(HAVE_ASM_GOTO,1,[Define if asm goto support])
@@ -1334,6 +1364,7 @@ PHP_SUBST(sysconfdir)
13341364

13351365
PHP_SUBST(EXEEXT)
13361366
PHP_SUBST(CC)
1367+
PHP_SUBST(BUILD_CC)
13371368
PHP_SUBST(CFLAGS)
13381369
PHP_SUBST(CFLAGS_CLEAN)
13391370
PHP_SUBST(CPP)

ext/opcache/config.m4

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if test "$PHP_OPCACHE" != "no"; then
2929

3030
if test "$PHP_OPCACHE_JIT" = "yes"; then
3131
case $host_cpu in
32-
x86*)
32+
i[34567]86*|x86*)
3333
;;
3434
*)
3535
AC_MSG_WARN([JIT not supported by host architecture])
@@ -43,28 +43,26 @@ if test "$PHP_OPCACHE" != "no"; then
4343
ZEND_JIT_SRC="jit/zend_jit.c jit/zend_jit_vm_helpers.c"
4444

4545
dnl Find out which ABI we are using.
46-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
47-
int main(void) {
48-
return sizeof(void*) == 4;
49-
}
50-
]])],[
51-
ac_cv_32bit_build=no
52-
],[
53-
ac_cv_32bit_build=yes
54-
],[
55-
ac_cv_32bit_build=no
56-
])
57-
58-
if test "$ac_cv_32bit_build" = "no"; then
59-
case $host_alias in
60-
*x86_64-*-darwin*)
61-
DASM_FLAGS="-D X64APPLE=1 -D X64=1"
46+
case $host_alias in
47+
x86_64-*-darwin*)
48+
DASM_FLAGS="-D X64APPLE=1 -D X64=1"
49+
DASM_ARCH="x86"
6250
;;
63-
*x86_64*)
64-
DASM_FLAGS="-D X64=1"
51+
x86_64*)
52+
DASM_FLAGS="-D X64=1"
53+
DASM_ARCH="x86"
6554
;;
66-
esac
67-
fi
55+
i[34567]86*)
56+
DASM_ARCH="x86"
57+
;;
58+
x86*)
59+
DASM_ARCH="x86"
60+
;;
61+
aarch64*)
62+
DASM_FLAGS="-D ARM64=1"
63+
DASM_ARCH="arm64"
64+
;;
65+
esac
6866

6967
if test "$PHP_THREAD_SAFETY" = "yes"; then
7068
DASM_FLAGS="$DASM_FLAGS -D ZTS=1"
@@ -173,9 +171,10 @@ int main() {
173171
}
174172
return 0;
175173
}
176-
]])],[dnl
174+
]])],[have_shm_ipc=yes],[have_shm_ipc=no],[have_shm_ipc=no])
175+
if test "$have_shm_ipc" = "yes"; then
177176
AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
178-
have_shm_ipc=yes],[have_shm_ipc=no],[have_shm_ipc=no])
177+
fi
179178
AC_MSG_RESULT([$have_shm_ipc])
180179

181180
AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
@@ -225,9 +224,19 @@ int main() {
225224
}
226225
return 0;
227226
}
228-
]])],[dnl
227+
]])],[have_shm_mmap_anon=yes],[have_shm_mmap_anon=no],[
228+
case $host_alias in
229+
*linux*)
230+
have_shm_mmap_anon=yes
231+
;;
232+
*)
233+
have_shm_mmap_anon=no
234+
;;
235+
esac
236+
])
237+
if test "$have_shm_mmap_anon" = "yes"; then
229238
AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
230-
have_shm_mmap_anon=yes],[have_shm_mmap_anon=no],[have_shm_mmap_anon=no])
239+
fi
231240
AC_MSG_RESULT([$have_shm_mmap_anon])
232241

233242
PHP_CHECK_FUNC_LIB(shm_open, rt, root)
@@ -295,16 +304,12 @@ int main() {
295304
}
296305
return 0;
297306
}
298-
]])],[dnl
307+
]])],[have_shm_mmap_posix=yes],[have_shm_mmap_posix=no],[have_shm_mmap_posix=no])
308+
if test "$have_shm_mmap_posix" = "yes"; then
299309
AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support])
300-
AC_MSG_RESULT([yes])
301-
have_shm_mmap_posix=yes
302310
PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)])
303-
],[
304-
AC_MSG_RESULT([no])
305-
],[
306-
AC_MSG_RESULT([no])
307-
])
311+
fi
312+
AC_MSG_RESULT([$have_shm_mmap_posix])
308313

309314
PHP_NEW_EXTENSION(opcache,
310315
ZendAccelerator.c \

ext/opcache/jit/Makefile.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
$(builddir)/minilua: $(srcdir)/jit/dynasm/minilua.c
3-
$(CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@
3+
$(BUILD_CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@
44

55
$(builddir)/jit/zend_jit_x86.c: $(srcdir)/jit/zend_jit_x86.dasc $(srcdir)/jit/dynasm/*.lua $(builddir)/minilua
66
$(builddir)/minilua $(srcdir)/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(srcdir)/jit/zend_jit_x86.dasc

ext/standard/config.m4

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,17 @@ if test "$ac_cv_attribute_aligned" = "yes"; then
295295
AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
296296
fi
297297

298-
AC_FUNC_FNMATCH
298+
if test "$cross_compiling" = yes ; then
299+
case $host_alias in
300+
*linux*)
301+
AC_DEFINE([HAVE_FNMATCH], 1,
302+
[Define to 1 if your system has a working POSIX `fnmatch'
303+
function.])
304+
;;
305+
esac
306+
else
307+
AC_FUNC_FNMATCH
308+
fi
299309

300310
dnl
301311
dnl Check if there is a support means of creating a new process and defining

0 commit comments

Comments
 (0)