Search code examples
phpmacoslinker

What's the folder /BinaryCache/ on MacOSX (while compiling php)


If I look at the PHP configuration options on the stock PHP, I see that libpng, libjpeg and libfreetype are enabled with some magic options:

'--with-freetype-dir=/BinaryCache/apache_mod_php/apache_mod_php-79.1~2/Root/usr/local'
'--with-jpeg-dir=/BinaryCache/apache_mod_php/apache_mod_php-79.1~2/Root/usr/local'
'--with-png-dir=/BinaryCache/apache_mod_php/apache_mod_php-79.1~2/Root/usr/local'

They point to a weird folder /BinaryCache/ and I have no clue how the fixed this.

I'm trying to re-compile php on MacOSX (php5.4, no I don't want to use Mamp), and I don't want to ship custom libraries such as freetype, jpeg and png. Ideally those libs get statically linked to the binary, and the more 'common' libraries placed in /usr/lib are dynamically linked.

For some reason it doesn't work. Even with './configure --enable-static' or './configure --enable-static=yes' it always produces a binary that's linked with my custom libs. It might be related to the following message I get EVERY time:

checking if cc static flag -static works... no

Otool gives me the following output:

otool -L sapi/cli/php
sapi/cli/php:
/Users/nicolas/Documents/git/php/staticlib/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.2.0)
/Users/nicolas/Documents/git/php/staticlib/lib/libfreetype.6.dylib (compatibility version 17.0.0, current version 17.2.0)
/Users/nicolas/Documents/git/php/staticlib/lib/libpng16.16.dylib (compatibility version 23.0.0, current version 23.0.0)
/Users/nicolas/Documents/git/php/staticlib/lib/libjpeg.9.dylib (compatibility version 10.0.0, current version 10.0.0)

Any advice? How do I get to the /BinaryCache dir and what does it do?

Thanks in advance, Nicolas


Solution

  • So, I found out a possible way, but I'm not sure if this is how they did it.

    I ended up in patching the Makefile, not to use the dynamic linker for those libraries, but to link to their static .a files instead. I accomplished this with a simple SED command:

    sed -e '/^EXTRA_LIBS =/ s/ -lpng//' \
        -e '/^EXTRA_LIBS = / s/ -ljpeg//' \
        -e '/^EXTRA_LIBS = / s/ -lintl//' \
        -e '/^EXTRA_LIBS = / s/ -lfreetype//' \
        -e "/^EXTRA_LDFLAGS =/ s/.*/EXTRA_LDFLAGS = \$(shell find ..\/staticlib\/lib -iname '*.a' -type f) -framework CoreFoundation/" \
        -e "/^EXTRA_LDFLAGS_PROGRAM =/ s/.*/EXTRA_LDFLAGS_PROGRAM = \$(shell find ..\/staticlib\/lib -iname '*.a' -type f) -framework CoreFoundation/" \
        $phpname/Makefile >$phpname/Makefile.edit
    
    mv -f $phpname/Makefile.edit $phpname/Makefile
    

    While the ./configure script has done it's job by detecting and activating the libraries, we just tell the linker to omit the -lpng, -ljpeg, -lintl and -lfreetype flags, and instead link to the *.a files of those libraries (I've built them in the ../staticlib folder). The find command's output is:

    staticlib/lib/libasprintf.a
    staticlib/lib/libfreetype.a
    staticlib/lib/libgettextpo.a
    staticlib/lib/libintl.a
    staticlib/lib/libjpeg.a
    staticlib/lib/libpng16.a
    

    I ended up with a binary that's not dynamically linked anymore to the dylibs in /Users/nicolas/Documents/git/php/staticlib/lib/, and is now portable on the same version of MacOSX.

    PM me if you want the build script.

    Best, Nicolas