The Semi-Official Guide to Porting Apache ------------- Introduction: ------------- Apache has been ported to a wide variety of platforms, from multiple UNIX varients to OS/2. Nonetheless, there are most likely a few platforms out there that currently are not "officially" supported under Apache. Porting Apache to these platforms can be quite simple depending on the "genericness" of the OS. This doc will provide some basic guidelines to help the potential porter. ------------- Requirements: ------------- One of the basic requirements for a potential Apache platform is a robust TCP/IP implementation. Just about any UNIX out there nowadays, even some ancient ones, have a TCP/IP stack that will work. In particular, the UNIX should provide for sockets and the basic controlling functions for them (like accept(), bind(), etc). The source for Apache is written in ANSI-C, so an ANSI-C compiler is required. However, Apache does not use or require ANSI-only functions or options (eg: the "%n" parameter in the scanf() family); the source basically uses ANSI function prototyping but no other specific ANSIisms. Thus, an ANSI-to-K&R filter _may_ work, although as far as I know it has not yet been tried. If you attempt this, let the Apache team know (mailto: new-httpd@hyperreal.com). ------------------- The Starting Point: ------------------- The first thing to look at is the output of the ./helpers/GuessOS script. This is a simple script that attempts to determine the platform and OS you are running on. The output of this script is used by Configure to set some basic compilation parameters. The output of ./helpers/GuessOS was designed to be GNUconfig.guess compatible (from GNU/autoconf). The format of the output string is: machine-vendor-OS This string is returned to the main Configure script as the shell variable $PLAT. If Configure is not "aware" of that platform (or cannot correctly parse it), it will complain and die. ---------------------- Configure cannot Grok: ---------------------- If this happens to you, then it means that Configure doesn't know how to configure and compile Apache for your OS. The first course of action is the easiest: Look in Configure and see if there are any OSs which is similar to yours. For example, let's say that your OS is similar to HP-UX, but that GuessOS returns "foobar-intel-hubble". You would then edit Configure as follows: *-hp-hpux*|*-*-hubble) OS='HP-UX' CFLAGS="$CFLAGS -DHPUX" ;; The '|*-*-hubble' was added to the switch statement for HP-UX. Another fix may involve editing the GuessOS helper script. Let's say, for example, that your system is SysV4-based, but that GuessOS does not return that info. You could then add a switch to the script that does something like: *WeirdSystem*) echo "${MACHINE}-whatever-sysv4"; exit 0 ;; In this case, we force GuessOS to return a string that includes the "sysv4" cookie for Configure to recognize. Unfortunately, unless you are running a very generic BSD or SysV system, no "supported" OS will be close enough in all aspects to allow for a clear (and possibly workable) build of Apache. If this is the case, you will need to port Apache to your OS. ------------------- Porting for Apache: ------------------- When all else fails, it's time to hack some code. The source itself is generic enough that most ports are incredibly easy. No matter what, however, there are 2 source files that need to be updated for the port: Configure conf.h Configure: ========== Configure concerns itself with determining the OS-type for the build and setting up a few Makefile variables for the build. The most important is 'OS' and 'CFLAGS'. For example, when Configure determines a build for A/UX, it runs the following lines: case "$PLAT" in *-apple-aux3*) OS='A/UX 3.1.x' CFLAGS="$CFLAGS -DAUX -D_POSIX_SOURCE" LIBS="$LIBS -lposix -lbsd" LDFLAGS="$LDFLAGS -s" DEF_WANTHSREGEX=no ;; The 'OS' variable is used to define the system Apache is being built for. You will also note that 'CFLAGS' defines "-DAUX". In this case, 'AUX' is a magic cookie used by the Apache code (mainly conf.h [see below]) to handle OS-specific code. Each code that has and requires such OS-specific code will require a unique "system cookie" defined in 'CFLAGS'. You will also note that Configure also goes ahead and predefines the LIBS and LDFLAGS Makefile variables (DEF_WANTHSREGEX is explained below). conf.h: ======= The Apache code, specifically in conf.h, uses a variety of #defines to control how the code is compiled and what options are available for each supported OS. One of the hardest parts about the porting process is determining which of the following are applicable for your system and setup. This time using the example of AIX, we see: #elif defined(AIX) #undef HAVE_GMTOFF #undef NO_KILLPG #undef NO_SETSID #define HAVE_SYS_SELECT_H #define JMP_BUF sigjmp_buf #define HAVE_MMAP typedef int rlim_t; The above lines describe which functions, capabilities and specifics are required for Apache to build and run under IBM AIX (the #undefs are not strictly required, but are a Good Idea anyway). The following several lines provide a list and short description of these #defines. By correcting #defining the ones you need in conf.h (wrapped by the above mentioned "system cookie"), you can fine tune the build for your OS. -- NEED_*: If the particular OS doesn't supply the specified function, we use the Apache-supplied version (in util.c). NEED_STRERROR: NEED_STRDUP: NEED_STRCASECMP: NEED_STRNCASECMP: NEED_INITGROUPS: NEED_WAITPID: NEED_STRERROR: -- HAVE_*: Does this OS have/support this capability? HAVE_GMTOFF: Define if the OS's tm struct has the tm_gmtoff element HAVE_RESOURCE: Define if the OS supports the getrlimit()/setrlimit() functions HAVE_MMAP: Define if the OS supports the BSD mmap() call. This is used by various OSs to allow the scoreboard file to be held in shared mmapped-memory instead of a real file. HAVE_SHMGET: Define if the OS has the SysV-based shmget() family of shared-memory functions. Used to allow the scoreboard to live in a shared-memory slot instead of a real file. HAVE_CRYPT_H: Define if the OS has the header file. HAVE_SYS_SELECT_H: Define if the OS has the header file. HAVE_SYS_RESOURCE_H: Define if the OS has and supports the getrlimit/setrlimit family. Apache uses this to determine if RLIMIT_CPU|VMEM|DATA|RLIMIT is found and used. HAVE_SNPRINTF: Apache makes extensive use of the snprintf() function. many platforms do not provide this function. If your platform does provide it _and_ it's reliable (most are not) then define this to use the OS version. Otherwise, Apache will use it's own. -- USE_*: These #defines are used for functions and ability that aren't exactly required but should be used. USE_FCNTL_SERIALIZED_ACCEPT: Define if the OS requires a mutex "lock" around the socket accept() call. Use fcntl() locking. USE_FLOCK_SERIALIZED_ACCEPT: Define if the OS requires a mutex "lock" around the socket accept() call. Use flock() locking (fcntl() is expensive on some OSs, esp. when using NFS). USE_LONGJMP: use the longjmp() call instead of siglongjmp() (as well as setjmp() instead of sigsetjmp()) -- NO_*: These are defined if the OS does NOT have the specified function or if we should not use it. NO_UNISTD_H: NO_KILLPG: NO_SETSID: NO_USE_SIGACTION: Do not use the sigaction() call, even if we have it. NO_LINGCLOSE: Do not use Apache's soft, "lingering" close feature to terminate connections. NO_SLACK: Do not use the "slack" fd feature which requires a working fcntl F_DUPFD. NO_GETTIMEOFDAY: OS does not have the gettimeofday() function (which is BSDish). This assumes it has times() instead. -- MISC #DEFINES: Various other #defines used in the code. JMP_BUF: The variable-type for siglongjmp() or longjmp() call. MOVEBREAK: Amount to move sbrk() breakpoint, if required, before attaching shared-memory segment. NET_SIZE_T: Some functions such as accept(), getsockname(), getpeername() take an int *len on some architectures and a size_t *len on others. If left undefined apache will default it to int. ----------- Conclusion: ----------- The above hints, and a good understanding of your OS and Apache, will go a LONG way in helping you get Apache built and running on your OS. If you have a port, PLEASE send Email to 'new-httpd@hyperreal.com' with the patches so that we may add them to the official version. If you hit a rough spot in the porting process, you can also try sending Email to that address as well and, if you are lucky, someone will respond. Another good source is the 'comp.infosystems.www.servers.unix' Usenet group as well. Good luck and happy porting!