Skip to content

Commit

Permalink
Enable iconv extension (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Jan 21, 2025
1 parent 59d146f commit 9bd6086
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/php/libcrypto.3.dylib"
"${PHPDESKTOP_APP}/Contents/MacOS/libcrypto.3.dylib"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/php/libiconv.2.dylib"
"${PHPDESKTOP_APP}/Contents/MacOS/libiconv.2.dylib"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/php/libxml2.2.dylib"
"${PHPDESKTOP_APP}/Contents/MacOS/libxml2.2.dylib"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
1. Install PHP build dependencies. See https://www.php.net/manual/en/install.unix.source.php .
1. Best to disable Homebrew or similar package managers, so that dependencies are portable.
1. Download OpenSSL sources and extract it in the "phpdesktop/php/" directory. See https://github.com/openssl/openssl/releases .
1. Download libiconv sources and extract in php/ directory. See https://www.gnu.org/software/libiconv/ .
1. Download libxml2 official distribution tarball (tar.xz) and extract in php/ directory. See https://gitlab.gnome.org/GNOME/libxml2/-/releases .
1. Download sqlite sources and extract in php/ directory. See https://www.sqlite.org/download.html .
1. Download zlib 1.3.1 sources and extract in php/ directory. See https://github.com/madler/zlib/releases .
1. Download PHP sources and extract it in the "phpdesktop/php/" directory. See https://www.php.net/downloads.php .
1. RUn `buildopenssl.sh` script.
1. Run `buildiconv.sh` script.
1. Run `buildxml.sh`script.
1. Run `buildsqlite.sh` script.
1. Run `buildzlib.sh` script.
Expand Down
38 changes: 38 additions & 0 deletions buildiconv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Download sources from: https://www.gnu.org/software/libiconv/
# Then extract in php/ directory.

# Exit immediately if a command exits with a non-zero status.
set -e

# Print all executed commands to terminal.
set -x

clear && clear

root_dir=$(realpath $(dirname $0))
echo "root_dir=$root_dir"

if ! cd $root_dir/php/ ; then
echo "php/ directory doesn't exist"
exit 1
fi
rm -f libiconv.2.dylib

if ! cd $root_dir/php/libiconv-*/ ; then
echo "Can't find iconv directory"
exit 1
fi
iconv_dir=$(realpath $(pwd))
echo "Found iconv: ${iconv_dir}"

echo "Configure iconv..."
./configure \
--prefix=${iconv_dir}/dist-install \
--exec-prefix=${iconv_dir}/dist-install
echo "Build iconv..."
make install

cp ./dist-install/lib/libiconv.2.dylib ./../libiconv.2.dylib
install_name_tool -id libiconv.2.dylib ./../libiconv.2.dylib

echo "Done."
29 changes: 19 additions & 10 deletions buildphp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ fi
openssl_dir=$(realpath $(pwd))
echo "Found OpenSSL: ${openssl_dir}"

if ! cd $root_dir/php/libiconv-*/ ; then
echo "Can't find iconv directory"
exit 1
fi
iconv_dir=$(realpath $(pwd))
echo "Found iconv: ${iconv_dir}"

if ! cd $root_dir/php/libxml2-*/ ; then
echo "Can't find libxml2 directory"
exit 1
Expand Down Expand Up @@ -77,38 +84,40 @@ php_dir=$(realpath $(pwd))
echo "Found PHP: ${php_dir}"

echo "Configure PHP..."
cp $sqlite_dir/dist-install/lib/libsqlite3.dylib ./libsqlite3.dylib # To get around bug in conftest
export EXTRA_CFLAGS="-Wno-unused-command-line-argument -lresolv" # To get around bug: uresolved symbol "_res_9_dn_expand".
export OPENSSL_CFLAGS="-I${openssl_dir}/dist-install/include"
export OPENSSL_LIBS="-L${openssl_dir}/dist-install/lib -lcrypto -lssl"
export LIBXML_CFLAGS="-I${libxml2_dir}/dist-install/include"
export LIBXML_LIBS="-L${libxml2_dir}/dist-install-exec-prefix/lib -lxml2"
export LIBXML_LIBS="-L${libxml2_dir}/dist-install/lib -lxml2"
export SQLITE_CFLAGS="-I${sqlite_dir}/dist-install/include"
export SQLITE_LIBS="-L${sqlite_dir}/dist-install/lib -lsqlite3"
export ZLIB_CFLAGS="-I${zlib_dir}/dist-install/include"
export ZLIB_LIBS="-L${zlib_dir}/dist-install-exec-prefix/lib -lz"
./configure \
export ZLIB_LIBS="-L${zlib_dir}/dist-install/lib -lz"
./configure -v \
--prefix=${php_dir}/dist-install \
--exec-prefix=${php_dir}/dist-install-exec-prefix \
--exec-prefix=${php_dir}/dist-install \
--with-mysqli \
--with-openssl \
--without-iconv
--with-iconv="$iconv_dir/dist-install"
echo "Build PHP..."
make install

cp ./dist-install-exec-prefix/bin/php-cgi ./../php-cgi
cp ./dist-install/bin/php-cgi ./../php-cgi
cp $root_dir/php.ini $root_dir/php/php.ini

cd $root_dir/php/

install_name_tool -rpath $openssl_dir/dist-install/lib @loader_path/. php-cgi
install_name_tool -delete_rpath $libxml2_dir/dist-install-exec-prefix/lib php-cgi
install_name_tool -delete_rpath $libxml2_dir/dist-install/lib php-cgi
install_name_tool -delete_rpath $sqlite_dir/dist-install/lib php-cgi
install_name_tool -delete_rpath $zlib_dir/dist-install-exec-prefix/lib php-cgi
install_name_tool -delete_rpath $zlib_dir/dist-install/lib php-cgi

install_name_tool -change $openssl_dir/dist-install/lib/libcrypto.3.dylib libcrypto.3.dylib php-cgi
install_name_tool -change $openssl_dir/dist-install/lib/libssl.3.dylib libssl.3.dylib php-cgi
install_name_tool -change $libxml2_dir/dist-install-exec-prefix/lib/libxml2.2.dylib libxml2.2.dylib php-cgi
install_name_tool -change $iconv_dir/dist-install/lib/libiconv.2.dylib libiconv.2.dylib php-cgi
install_name_tool -change $libxml2_dir/dist-install/lib/libxml2.2.dylib libxml2.2.dylib php-cgi
install_name_tool -change $sqlite_dir/dist-install/lib/libsqlite3.dylib libsqlite3.dylib php-cgi
install_name_tool -change $zlib_dir/dist-install-exec-prefix/lib/libz.1.dylib libz.1.3.1.dylib php-cgi
install_name_tool -change $zlib_dir/dist-install/lib/libz.1.dylib libz.1.3.1.dylib php-cgi

echo "Done."
2 changes: 1 addition & 1 deletion buildsqlite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ echo "Configure sqlite..."
echo "Build sqlite..."
make install

cp ./dist-install/lib/libsqlite3.dylib ./../libsqlite3.dylib
cp ./dist-install/lib/libsqlite3.dylib.3.* ./../libsqlite3.dylib
install_name_tool -id libsqlite3.dylib ./../libsqlite3.dylib
install_name_tool -delete_rpath $sqlite_dir/dist-install/lib ./../libsqlite3.dylib

Expand Down
15 changes: 12 additions & 3 deletions buildxml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ if ! cd $root_dir/php/ ; then
fi
rm -f libxml2.2.dylib

if ! cd $root_dir/php/libiconv-*/ ; then
echo "Can't find iconv directory"
exit 1
fi
iconv_dir=$(realpath $(pwd))
echo "Found iconv: ${iconv_dir}"

if ! cd $root_dir/php/libxml2-*/ ; then
echo "Can't find libxml2 directory"
exit 1
Expand All @@ -28,12 +35,14 @@ echo "Found Libxml2: ${libxml2_dir}"
echo "Configure libxml2..."
./configure \
--prefix=${libxml2_dir}/dist-install \
--exec-prefix=${libxml2_dir}/dist-install-exec-prefix \
--without-python
--exec-prefix=${libxml2_dir}/dist-install \
--without-python \
--with-iconv="$iconv_dir/dist-install"
echo "Build libxml2..."
make install

cp ./dist-install-exec-prefix/lib/libxml2.2.dylib ./../libxml2.2.dylib
cp ./dist-install/lib/libxml2.2.dylib ./../libxml2.2.dylib
install_name_tool -id libxml2.2.dylib ./../libxml2.2.dylib
install_name_tool -change $iconv_dir/dist-install/lib/libiconv.2.dylib libiconv.2.dylib ./../libxml2.2.dylib

echo "Done."
4 changes: 2 additions & 2 deletions buildzlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ echo "Found zlib: ${zlib_dir}"
echo "Configure zlib..."
./configure \
--prefix=${zlib_dir}/dist-install \
--eprefix=${zlib_dir}/dist-install-exec-prefix
--eprefix=${zlib_dir}/dist-install
echo "Build zlib..."
make install

cp ./dist-install-exec-prefix/lib/libz.1.3.1.dylib ./../libz.1.3.1.dylib
cp ./dist-install/lib/libz.1.3.1.dylib ./../libz.1.3.1.dylib
install_name_tool -id libz.1.3.1.dylib ./../libz.1.3.1.dylib

echo "Done."

0 comments on commit 9bd6086

Please sign in to comment.