summaryrefslogtreecommitdiff
path: root/src/PORTING
blob: 2aaea03487a1479660754f986c1ed52f94eafa84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
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 <crypt.h> header file.

    HAVE_SYS_SELECT_H:
      Define if the OS has the <sys/select.h> 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.

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