Recompilingporting THTTPd / 2015-05-11 23:06:40

Here are the steps to recompile/port THTTPd v2.21b + PHP v4.2.3. These steps are proven: you are reading this page served by the very THTTPd that you will obtain at the end . These steps assume that you have installed GCC v3.4.0 for cross-compilation on your Windows/Cygwin PC and the Geek Gadgets on your Amiga, for testing PHP.

Warning: If you updated to Cywin v1.7, it is possible that your version of Flex is now 2.5.3X (try flex --version), in that case, you cannot compile the PHP parser and must install Flex v2.5.4, as explained on the PHP Web site.

 

Download

 

You can download the source code of THTTPd v2.21b + PHP v4.2.3, including also the binaries obtained by following the steps below, here:

THTTPd v2.21b + PHP v4.2.3.lha

This archive contains all you need to run and re-compile these versions of THTTPd and PHP, including the steps below and a file listing the differences between the content of this archive and the original source code of THTTPd and PHP available on Aminet. If you find anything amiss, please let me know!

 

Compilation

 

In the following, I use these acronyms:

  • FYTD: For you to do;
  • ADFY: Already done for you;
  • O: Optional.

 

Notice that when I type:

> m68-amigaos-gcc -v

I obtain:

Reading specs from /usr/local/amiga/lib/gcc/m68k-amigaos/3.4.0/specs
Configured with: ../gcc-3.4.0/configure 
    --prefix=/usr/local/amiga 
    --target=m68k-amigaos 
    --enable-eptions 
    --disable-shared 
    --disable-libstdcxx-pch
Thread model: single
gcc version 3.4.0

 

PHP

(FYTD) Install FLex/Bison in Cygwin if they are not already present.

 

(FYTD) Download and install libcrypt.a from the port of crypt on Aminet, typically in /usr/local/amiga/m68k-amigaos/lib/libcrypt.a.

 

(ADFY) If your are cross-compiling from Cygwin to AmigaOS, then configure will always consider that sprintf is not broken. I found that, on my configuration, sprintf is broken so I changed
the result returned in case of cross-compiling in aclocal.m4 and zend/acinclude.m4.

 

(ADFY) Related to the broken sprintf, PHP, and in particular its Zend module, used to call sprintf instead of zend_sprintf, which handles correctly variadic parameters. I replaced these calls with appropriate calls to zend_sprintf to prevent hits in Enforcer and memory corruptions resulting in Guru meditations...

 

(ADFY) Recall that the compilation chain divides into several steps:

configure.ac --.   .------> autoconf* -----> configure
               +---+
[aclocal.m4] --+   `---.
[acsite.m4] ---'       |
                       +--> [autoheader*] -> [config.h.in]
[acconfig.h] ----.     |
                 +-----'
[config.h.top] --+
[config.h.bot] --'

  

Thus, to generate configure, you must have autoconf v2.13 and use the following command:

php-4.2.3> export WANT_AUTOCONF=2.1

to make sure that autoconf v2.13 is used and then:

php-4.2.3> autoconf    

which uses the .m4 files, in particular the aclocal.m4 file. You must use autoconf v2.13 because of several reasons: 1, 2, and 3 and then use the following command:

php-4.2.3> autoheader

which generates the appropriate .h.in files, in particular main/php_config.h.in, which will in turn be used when calling configure (below) to generate the appropriate header files.

 

(FYTD) To configure the compilation of PHP, in particular to announce the building for thttpd, use the following command:

php-4.2.3> export CFLAGS="-m68020 -g"
php-4.2.3> AR=/usr/local/amiga/bin/m68k-amigaos-ar.exe 
    CC=/usr/local/amiga/bin/m68k-amigaos-gcc.exe 
    LD=/usr/local/amiga/bin/m68k-amigaos-ld.exe 
    NM=/usr/local/amiga/bin/m68k-amigaos-nm.exe 
    RANLIB=/usr/local/amiga/bin/m68k-amigaos-ranlib.exe
    ./configure 
    --with-thttpd=../thttpd-2.21b --disable-shared --disable-xml 
    --enable-cli --without-pear --without-mysql 
    --with-config-file-path="/THTTPd/"

This command will create various .h files and makefile required to compile PHP. They assume that the PHP configuration file php.ini is located in /THTTPd/ (meaning THTTPd: in AmigaOS term). You could use --enable-debug but this option could yield memory errors because of the broken sprintf use to output debug information. The parameters to GCC must be carefully set. The choice of the processor, e.g., -m68020, may lead to an implicit assumption on the presence of a FPU!

 

(FYTD, O) Make sure that libtool contains the following lines:

# The archiver.
AR="/usr/local/amiga/bin/m68k-amigaos-ar.exe"
...
# The default C compiler.
CC="/usr/local/amiga/bin/m68k-amigaos-gcc.exe"
...
# The linker used to build libraries.
LD="/usr/local/amiga/bin/m68k-amigaos-ld.exe"
...
# A BSD-compatible nm program.
NM="/usr/local/amiga/bin/m68k-amigaos-nm.exe -B"
...
RANLIB="/usr/local/amiga/bin/m68k-amigaos-ranlib.exe"

 

(FYTD) For some unknown reasons, the _eprintf function is declared and used in assert.h but is missing from libgcc.a, compare:

nm /usr/local/amiga/lib/gcc/m68k-amigaos/3.4.0/libgcc.a

with:

nm /usr/local/amiga/lib/gcc-lib/m68k-amigaos/2.95.3/libgcc.a

Therefore, you must add this function in sapi/cli/getopt.c (see next step) but also remove its declaration from assert.h, else you will get an error stating that the function is already declared. You must modify the file:

/usr/local/amiga/m68k-amigaos/include/assert.h

to comment lines 30 and 31, from:

extern void __eprintf (const char *, const char *, unsigned, const char *)
    __attribute__ ((noreturn));

to:

/*
extern void __eprintf (const char *, const char *, unsigned, const char *)
    __attribute__ ((noreturn));
*/

 

(ADFY) Add the following function to sapi/cli/getopt.c:

void
__eprintf (
     const char *format,
     const char *file,
     int line,
     const char *expression)
{
  (void) fprintf(stderr, format, file, line, expression);
  abort();
  /*NOTREACHED*/
} 

 

(ADFY) Make sure that the following mathematical functions in ext/standard/math.c compile. A solution is to replace them by something silly but that compiles.

asinh  ->  sinh
acosh  ->  cosh
...

 

(FYTD) To obtain the PHP library object ./.libs/libraryphp4.a and the command-line interpreter, use the following command:

php-4.2.3> make AR=/usr/local/amiga/bin/m68k-amigaos-ar.exe 
    CC=/usr/local/amiga/bin/m68k-amigaos-gcc.exe 
    LD=/usr/local/amiga/bin/m68k-amigaos-ld.exe 
    NM=/usr/local/amiga/bin/m68k-amigaos-nm.exe 
    RANLIB=/usr/local/amiga/bin/m68k-amigaos-ranlib.exe

Do not worry about the warnings, among others:

libtool: link: warning: undefined symbols not allowed in i686-pc-cygwin shared libraries

 

(FYTD) The CLI will be sapi/cli/php.exe. Test the CLI using (for example) WinUAE by typing in a Shell:

php-4.2.3> php sapi/cli/php_info.php

Test extensively the CLI using (again for example) WinUAE by typing in a Shell:

php-4.2.3> php -d php.ini-dist run-tests.php

Some tests cannot pass:
    OO Bug Test (Bug #7515) (029.phpt) ... failed

 

THTTPd

(ADFY) Apply the patch 22 (P22) that is supposed to fix problem when passing big files through thttpd, use the following command:

thttpd-2.21b> patch -Nbp2 --verbose < thttpd-2.21b-p22.patch

 

(FYTD) To configure thttpd, use the following command:

thttpd-2.21b> export CFLAGS="-m68020 -g"
thttpd-2.21b> AR=/usr/local/amiga/bin/m68k-amigaos-ar.exe
    CC=/usr/local/amiga/bin/m68k-amigaos-gcc.exe
    LD=/usr/local/amiga/bin/m68k-amigaos-ld.exe
    NM=/usr/local/amiga/bin/m68k-amigaos-nm.exe
    RANLIB=/usr/local/amiga/bin/m68k-amigaos-ranlib.exe
    ./configure

The parameters to GCC must be carefully set. The choice of the processor, e.g., -m68020, may lead to an implicit assumption on the presence of a FPU!

 

(ADFY) Change the php_makefile to link with the appropriate PHP and Amiga libraries:

PHP_LIBS = -L. \
    -L../php-4.2.3/.libs/ \
    -lphp4 -lphp4cli \
    -L/usr/local/amiga/m68k-amigaos/lib/ \
    -lamiga -lc \
    -L/usr/local/amiga/m68k-amigaos/lib/libnix \
    -lstubs -lnix -lcrypt -lm
PHP_LDFLAGS =
PHP_CFLAGS = -I. \
    -I../php-4.2.3/ \
    -I../php-4.2.3/main \
    -I../php-4.2.3 \
    -I../thttpd-2.21b \
    -I../php-4.2.3/Zend \
    -I../php-4.2.3/ext/xml/expat \
    -I../php-4.2.3/TSRM \
    -g -O2 -I../php-4.2.3/TSRM

 

(ADFY) Add the following function to extras/htpasswd.c:

static int getline(char *s, int n, FILE *f) {
    register int i=0;
    while(1) {
        s[i] = (char)fgetc(f);
        if(s[i] == CR)
            s[i] = fgetc(f);
        if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
            s[i] = '\0';
                return (feof(f) ? 1 : 0);
            }
            ++i;
        }
    }
}

 

(FYTD) To compile thttpd, use the following command:

thttpd-2.21b> make AR=/usr/local/amiga/bin/m68k-amigaos-ar.exe
    CC=/usr/local/amiga/bin/m68k-amigaos-gcc.exe
    LD=/usr/local/amiga/bin/m68k-amigaos-ld.exe
    NM=/usr/local/amiga/bin/m68k-amigaos-nm.exe
    RANLIB=/usr/local/amiga/bin/m68k-amigaos-ranlib.exe

 

(ADFY) To run THTTPd and use PHP within the Web server, the PHP directive register_argc_argv must be set to Off, else it causes phpinfo() to timeout after max_execution_time.

 

Acknowledgments

 

This recompiling/porting would not have been possible without the help of many people, including but not limited to!

  • ACME Labs.;

  • Joachim Birging;

  • Leffmann;
  • LouiSe;
  • Matthey;
  • NovaCoder;
  • Toni Wilen;
  • Trumo.