change context creation params to struct
[profile/ivi/libwebsockets.git] / README.build
1 Introduction
2 ------------
3 Libwebsockets can be built using two different build systems
4 autoconf or CMake. autoconf only works on Unix systems, or mingw/cygwin
5 on Windows. CMake works differently and can generate platform specific
6 project files for most popular IDEs and build systems.
7
8 ################################### Autoconf ###################################
9
10 Building the library and test apps
11 ----------------------------------
12
13 You need to regenerate the autotools and libtoolize stuff for your system
14
15 $ ./autogen.sh
16
17
18 ------Fedora x86_64
19
20  ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
21
22 ------Apple
23
24 Christopher Baker reported that this is needed
25 (and I was told separately enabling openssl makes trouble somehow)
26
27 ./configure CC="gcc -arch i386 -arch x86_64" CXX="g++ -arch i386 -arch
28 x86_64" CPP="gcc -E" CXXCPP="g++ -E" --enable-nofork
29
30 ------mingw
31
32 I did the following to get working build, ping test is disabled when
33 building this way
34
35 1) install mingw64_w32 compiler packages from Fedora
36 2) additionally install mingw64-zlib package
37 3) ./configure --prefix=/usr --enable-mingw --host=x86_64-w64-mingw32
38 4) make
39
40 ------MIPS cross-build using OpenWRT
41
42  ./configure --prefix=/usr --without-extensions --host mips-openwrt-linux
43
44 I did not try building the extensions since they need cross-zlib, but it
45 should also be workable.
46
47 ------Other uClibc
48
49 you may need --enable-builtin-getifaddrs if your toolchain
50 doesn't have it - openWRT uclibc has it so you don't need this option.
51
52 ------ARM cross-build
53
54 ./configure --prefix=/usr --host=arm-linux-gnueabi --without-client --without-extensions
55
56 you can build cross with client and extensions perfectly well, but
57 apart from the size shrink this has the nice characteristic that no
58 non-toolchain libraries are needed to build it.
59
60
61 otherwise if /usr/local/... and /usr/local/lib are OK then...
62
63 $ ./configure
64 $ make clean
65 $ make && sudo make install
66 $ libwebsockets-test-server
67
68 should be enough to get a test server listening on port 7861.
69
70
71 Configure script options
72 ------------------------
73
74 There are several other possible configure options
75
76 --enable-openssl        Builds in the SSL support
77
78 --with-cyassl           Use cyassl instead of OpenSSL... you will need CyaSSL
79                         to have been configured with --enable-opensslExtra
80 \                       when it was built.
81
82 --enable-libcrypto      by default libwebsockets uses its own
83                         built-in md5 and sha-1 implementation for
84                         simplicity.  However the libcrypto ones
85                         may be faster, and in a distro context it
86                         may be highly desirable to use a common
87                         library implementation for ease of security
88                         upgrades.  Give this configure option
89                         to disable the built-in ones and force use
90                         of the libcrypto (part of openssl) ones.
91
92 --with-client-cert-dir=dir   tells the client ssl support where to
93                              look for trust certificates to validate
94                              the remote certificate against.
95
96 --enable-noping         Don't try to build the ping test app
97                         It needs some unixy environment that
98                         may choke in other build contexts, this
99                         lets you cleanly stop it being built
100                         
101 --enable-builtin-getifaddrs  if your libc lacks getifaddrs, you can build an
102                         implementation into the library.  By default your libc
103                         one is used.
104
105 --without-testapps      Just build the library not the test apps
106
107 --without-client        Don't build the client part of the library nor the
108                         test apps that need the client part.  Useful to
109                         minimize library footprint for embedded server-only
110                         case
111
112 --without-server        Don't build the server part of the library nor the
113                         test apps that need the server part.  Useful to
114                         minimize library footprint for embedded client-only
115                         case
116
117 --without-daemonize     Don't build daemonize.c / lws_daemonize
118
119 --disable-debug         Remove all debug logging below lwsl_notice in severity
120                         from the code -- it's not just defeated from logging
121                         but removed from compilation
122
123 --without-extensions    Remove all code and data around protocol extensions.
124                         This reduces the code footprint considerably but
125                         you will lose extension features like compression.
126                         However that may be irrelevant for embedded use and
127                         the code / data size / speed improvements may be
128                         critical.
129
130 --with-latency          Builds the latency-tracking code into the library...
131                         this slows your library down a bit but is very useful
132                         to find the cause of unexpected latencies occurring
133                         inside the library.  See README.test-apps for more
134                         info
135
136
137 Externally configurable important constants
138 -------------------------------------------
139
140 You can control these from configure by just setting them as commandline
141 args throgh CFLAGS, eg
142
143 ./configure CFLAGS="-DLWS_MAX_ZLIB_CONN_BUFFER=8192"
144
145
146 They all have reasonable defaults usable for all use-cases except resource-
147 constrained, so you only need to take care about them if you want to tune them
148 to the amount of memory available.
149
150  - LWS_MAX_HEADER_NAME_LENGTH default 64: max characters in an HTTP header
151 name that libwebsockets can cope with
152
153  - LWS_MAX_HEADER_LEN default 4096: largest HTTP header value string length
154 libwebsockets can cope with
155
156  - LWS_INITIAL_HDR_ALLOC default 256: amount of memory to allocate initially,
157 tradeoff between taking too much and needless realloc
158
159  - LWS_ADDITIONAL_HDR_ALLOC default 64: how much to additionally realloc if
160 the header value string keeps coming
161
162  - LWS_MAX_PROTOCOLS default 10: largest amount of different protocols the
163 server can serve
164
165  - LWS_MAX_EXTENSIONS_ACTIVE default 10: largest amount of extensions we can
166 choose to have active on one connection
167
168  - SPEC_LATEST_SUPPORTED default 13: only change if you want to remove support
169 for later protocol versions... unlikely
170
171  - AWAITING_TIMEOUT default 5: after this many seconds without a response, the
172 server will hang up on the client
173
174  - CIPHERS_LIST_STRING default "DEFAULT": SSL Cipher selection.  It's advisable
175 to tweak the ciphers allowed to be negotiated on secure connections for
176 performance reasons, otherwise a slow algorithm may be selected by the two
177 endpoints and the server could expend most of its time just encrypting and
178 decrypting data, severely limiting the amount of messages it will be able to
179 handle per second.  For example::
180
181     "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
182
183  - SYSTEM_RANDOM_FILEPATH default "/dev/urandom": if your random device differs
184 you can set it here
185
186  - LWS_MAX_ZLIB_CONN_BUFFER  maximum size a compression buffer is allowed to
187 grow to before closing the connection.  Some limit is needed or any connecton
188 can exhaust all server memory by sending it 4G buffers full of zeros which the
189 server is expect to expand atomically.  Default is 64KBytes.
190
191  - LWS_SOMAXCONN  maximum number of pending connect requests the listening
192 socket can cope with.  Default is SOMAXCONN.  If you need to use synthetic
193 tests that just spam hundreds of connect requests at once without dropping
194 any, you can try messing with these as well as ulimit (see later)
195 (courtesy Edwin van der Oetelaar)
196
197 echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range
198 echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle
199 echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse
200 echo "10" > /proc/sys/net/ipv4/tcp_fin_timeout
201 echo "65536" > /proc/sys/net/core/somaxconn
202 echo "65536" > /proc/sys/net/ipv4/tcp_max_syn_backlog
203 echo "262144" > /proc/sys/net/netfilter/nf_conntrack_max
204
205
206 Memory efficiency
207 -----------------
208
209 Update at 35f332bb46464feb87eb
210
211 Embedded server-only configuration without extensions (ie, no compression
212 on websocket connections), but with full v13 websocket features and http
213 server, built on ARM Cortex-A9:
214
215 ./configure --without-client --without-extensions --disable-debug --enable-nofork --without-daemonize
216
217 .text   .rodata .data   .bss
218 11476   2664    288     4
219
220 Context Creation, 1024 fd limit[2]: 12288 (12 bytes per fd)
221 Per-connection [3]: 4400 bytes
222
223
224 This shows the impact of the major configuration with/without options at
225 13ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES.
226
227 These are accounting for static allocations from the library elf, there are
228 additional dynamic allocations via malloc
229
230 Static allocations, ARM9
231                                 .text   .rodata .data   .bss
232  All (no without)               35024   9940    336     4104
233  without client                 25684   7144    336     4104
234  without client, exts           21652   6288    288     4104
235  without client, exts, debug[1] 19756   3768    288     4104
236  without server                 30304   8160    336     4104
237  without server, exts           25382   7204    288     4104
238  without server, exts, debug[1] 23712   4256    288     4104
239
240 Dynamic allocations: ARM9 (32 bit)
241
242  Context Creation, 1024 fd limit[2] in ulimit:  12288  (12 bytes per fd)
243  Per-connection (excluding headers[3]):          8740
244
245 Dynamic allocations: x86_64 (64 bit)
246
247  Context Creation, 1024 fd limit[2] in ulimit:  16384  (16 bytes per fd)
248  Per-connection (excluding headers[3]):          9224
249
250 [1] --disable-debug only removes messages below lwsl_notice.  Since that is
251 the default logging level the impact is not noticable, error, warn and notice
252 logs are all still there.
253
254 [2] 1024 fd per process is the default limit (set by ulimit) in at least Fedora
255 and Ubuntu.
256
257 [3] known headers are retained via additional mallocs for the lifetime of the
258 connection
259
260
261 #################################### CMake ####################################
262
263 CMake is a multi-platform build tool that can generate build files for many
264 different target platforms. See more info at http://www.cmake.org
265
266 CMake also allows/recommends you to do "out of source"-builds, that is, 
267 the build files are separated from your sources, so there is no need to 
268 create elaborate clean scripts to get a clean source tree, instead you 
269 simply remove your build directory.
270
271 Libwebsockets has been tested to build successfully on the following platforms
272 with SSL support (both OpenSSL/CyaSSL):
273
274 - Windows
275 - Linux (x86 and ARM)
276 - OSX
277 - NetBSD
278
279 Building the library and test apps
280 ----------------------------------
281
282 The project settings used by CMake to generate the platform specific build
283 files is called CMakeLists.txt. CMake then uses one of its "Generators" to
284 output a Visual Studio project or Make file for instance. To see a list of
285 the available generators for your platform, simply run the "cmake" command.
286
287 Note that by default OpenSSL will be linked, if you don't want SSL support
288 see below on how to toggle compile options.
289
290 Building on Unix:
291 -----------------
292
293 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
294    (Most Unix distributions comes with a packaged version also)
295
296 2. Install OpenSSL.
297
298 3. Generate the build files (default is Make files):
299
300         cd /path/to/src
301         mkdir build
302         cd build
303         cmake ..
304
305         (NOTE: The build/ directory can have any name and be located anywhere
306          on your filesystem, and that the argument ".." given to cmake is simply
307          the source directory of libwebsockets containing the CMakeLists.txt project
308          file. All examples in this file assumes you use "..")
309
310 4. Finally you can build using the generated Makefile:
311
312         make
313
314 Building on Windows (Visual Studio)
315 -----------------------------------
316 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
317
318 2. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
319    (Preferably in the default location to make it easier for CMake to find them)
320
321 3. Generate the Visual studio project by opening the Visual Studio cmd prompt:
322
323    cd <path to src>
324    md build
325    cd build
326    cmake -G "Visual Studio 10" ..
327
328    (NOTE: There is also a cmake-gui available on Windows if you prefer that)
329
330 4. Now you should have a generated Visual Studio Solution in  your
331    <path to src>/build directory, which can be used to build.
332
333 Setting compile options
334 -----------------------
335
336 To set compile time flags you can either use one of the CMake gui applications
337 or do it via command line.
338
339 Command line
340 ------------
341 To list avaialable options (ommit the H if you don't want the help text):
342
343         cmake -LH ..
344
345 Then to set an option and build (for example turn off SSL support):
346
347         cmake -DWITH_SSL=0 ..
348 or
349         cmake -DWITH_SSL:BOOL=OFF ..
350
351 Unix GUI
352 --------
353 If you have a curses enabled build you simply type:
354 (not all packages include this, my debian install does not for example).
355         
356         ccmake
357
358 Windows GUI
359 -----------
360 On windows CMake comes with a gui application:
361         Start -> Programs -> CMake -> CMake (cmake-gui)
362
363 CyaSSL replacement for OpenSSL
364 ------------------------------
365 CyaSSL is a lightweight SSL library targeted at embedded system:
366 http://www.yassl.com/yaSSL/Products-cyassl.html
367
368 It contains a OpenSSL compatability layer which makes it possible to pretty
369 much link to it instead of OpenSSL, giving a much smaller footprint.
370
371 NOTE: At the time of writing this the current release of CyaSSL contains a 
372 crash bug due to some APIs libwebsocket uses. To be able to use this you will
373 need to use the current HEAD in their official repository:
374         https://github.com/cyassl/cyassl
375
376 NOTE: cyassl needs to be compiled using the --enable-opensslExtra flag for
377 this to work.
378
379 Compiling libwebsockets with CyaSSL
380 -----------------------------------
381
382 cmake -DUSE_CYASSL=1 
383           -DCYASSL_INCLUDE_DIRS=/path/to/cyassl 
384           -DCYASSL_LIB=/path/to/cyassl/cyassl.a ..
385
386 NOTE: On windows use the .lib file extension for CYASSL_LIB instead.
387
388 Cross compiling
389 ---------------
390 To enable cross compiling libwebsockets using CMake you need to create
391 a "Toolchain file" that you supply to CMake when generating your build files.
392 CMake will then use the cross compilers and build paths specified in this file
393 to look for dependencies and such.
394
395 Below is an example of how one of these files might look like:
396
397         #
398         # CMake Toolchain file for crosscompiling on ARM.
399         #
400         # This can be used when running cmake in the following way:
401         #  cd build/
402         #  cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/this/file/TC_arm-linux-gcc.cmake
403         #
404
405         set(CROSS_PATH /path/to/cross_environment/uClibc)
406
407         # Target operating system name.
408         set(CMAKE_SYSTEM_NAME Linux)
409
410         # Name of C compiler.
411         set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-linux-uclibc-gcc")
412         set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-linux-uclibc-g++")
413
414         # Where to look for the target environment. (More paths can be added here)
415         set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}")
416
417         # Adjust the default behavior of the FIND_XXX() commands:
418         # search programs in the host environment only.
419         set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
420
421         # Search headers and libraries in the target environment only.
422         set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
423         set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
424
425 Additional information on cross compilation with CMake:
426         http://www.vtk.org/Wiki/CMake_Cross_Compiling