Recompilingporting THTTPd

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.

Update 2014/06/01: 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. (Flex v2.6.4 doesn't create any problem.)

Update 2012/06/21: By default, the maximum size of the data exchanged between PHP and THTTPd is 4,000 bytes... which is way to small to exchange Web pages generated by a Wiki . So, you may want to change the value of the constant SAPI_POST_BLOCK_SIZE in main/SAPI.h from 4000 to 65355 to 131071...

Update 2022/03/25: The new 32 bits version of Cygwin, v3.3.4 (0.341/5/3), comes with Flex v2.6.4, which doesn't have this problem .

 

Download

You must download the source code of THTTPd v2.21b + PHP v4.2.3. This archives includes the binaries obtained by following the steps below. It also 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:

> m68k-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

  1. (FYTD) Install FLex/Bison in Cygwin if they are not already present.
  2. (FYTD) Download and install libcrypt.a from the port of crypt on Aminet, typically in /usr/local/amiga/m68k-amigaos/lib/libcrypt.a.
  3. (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.
  4. (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...
  5. (ADFY) Recall that the compilation chain divides into several steps:
  6. configure.ac --.   .------> autoconf* -----> configure
                   +---+
    [aclocal.m4] --+   `---.
    [acsite.m4] ---'       |
                           +--> [autoheader*] -> [config.h.in]
    [acconfig.h] ----.     |
                     +-----'
    [config.h.top] --+
    [config.h.bot] --'
    
  7. Thus, to generate configure, you must have autoconf v2.13 and use the following command:
  8. 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-2.13
  9. 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:
  10. php-4.2.3> autoheader-2.13
    

    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.

  11. (FYTD) To configure the compilation of PHP, in particular to announce the building for thttpd, use the following command:
  12. 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! 

  13. (FYTD, O) Make sure that libtool contains the following lines:
  14. # 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"
  15. (FYTD) For some unknown reasons, the _eprintf function is declared and used in assert.h but is missing from libgcc.a, compare:
  16. 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));
    */
    
  17.  (ADFY) Add the following function to sapi/cli/getopt.c:
  18. void
    __eprintf (
         const char *format,
         const char *file,
         int line,
         const char *expression)
    {
      (void) fprintf(stderr, format, file, line, expression);
      abort();
      /*NOTREACHED*/
    } 
  19. (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.
  20. asinh  ->  sinh
    acosh  ->  cosh
    ...
    
  21. (FYTD) To obtain the PHP library object ./.libs/libraryphp4.a and the command-line interpreter, use the following command:
  22. 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
    
  23. Do not worry about the warnings, among others:
  24. libtool: link: warning: undefined symbols not allowed in i686-pc-cygwin shared libraries
  25. (FYTD) The CLI will be sapi/cli/php.exe. Test the CLI using (for example) WinUAE by typing in a Shell:
  26. 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

  1. (ADFY) Apply the patch 22 (P22) that is supposed to fix problem when passing big files through thttpd, use the following command:
  2. thttpd-2.21b> patch -Nbp2 --verbose < thttpd-2.21b-p22.patch
  3. (FYTD) To configure thttpd, use the following command:
  4. 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!

  5. (ADFY) Change the php_makefile to link with the appropriate PHP and Amiga libraries:
  6. 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
    
  7. (ADFY) Add the following function to extras/htpasswd.c:
  8. 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;
            }
        }
    }
    
  9. (FYTD) To compile thttpd, use the following command:
  10. 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
    
  11.  (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;
  • TUMO.

 


The last three changes:

Tygre - 2022-03-28 08:07:08 am  |  Tygre - 2022-03-27 03:08:28 pm  |  Tygre - 2022-03-27 03:02:44 pm