close: make close notification go through writable
[platform/upstream/libwebsockets.git] / README.build.md
index 4055ecf..dd3494a 100644 (file)
@@ -2,8 +2,7 @@ Notes about building lws
 ========================
 
 
-Introduction to CMake
----------------------
+@section cm Introduction to CMake
 
 CMake is a multi-platform build tool that can generate build files for many
 different target platforms. See more info at http://www.cmake.org
@@ -14,7 +13,7 @@ create elaborate clean scripts to get a clean source tree, instead you
 simply remove your build directory.
 
 Libwebsockets has been tested to build successfully on the following platforms
-with SSL support (both OpenSSL/wolfSSL):
+with SSL support (for OpenSSL/wolfSSL/BoringSSL):
 
 - Windows (Visual Studio)
 - Windows (MinGW)
@@ -22,8 +21,8 @@ with SSL support (both OpenSSL/wolfSSL):
 - OSX
 - NetBSD
 
-Building the library and test apps
-----------------------------------
+
+@section build1 Building the library and test apps
 
 The project settings used by CMake to generate the platform specific build
 files is called [CMakeLists.txt](CMakeLists.txt). CMake then uses one of its "Generators" to
@@ -33,8 +32,8 @@ the available generators for your platform, simply run the "cmake" command.
 Note that by default OpenSSL will be linked, if you don't want SSL support
 see below on how to toggle compile options.
 
-Building on Unix:
------------------
+
+@section bu Building on Unix:
 
 1. Install CMake 2.8 or greater: http://cmake.org/cmake/resources/software.html
    (Most Unix distributions comes with a packaged version also)
@@ -94,6 +93,14 @@ To get it to build on latest openssl (2016-04-10) it needed this approach
        cmake .. -DLWS_WITH_HTTP2=1 -DLWS_OPENSSL_INCLUDE_DIRS=/usr/local/include/openssl -DLWS_OPENSSL_LIBRARIES="/usr/local/lib64/libssl.so;/usr/local/lib64/libcrypto.so"
 ```
 
+Mac users have reported
+
+```
+ $ export OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2k; cmake ..; make -j4
+```
+
+worked for them when using "homebrew" OpenSSL
+
 **NOTE5**:
 To build with debug info and _DEBUG for lower priority debug messages
 compiled in, use
@@ -101,15 +108,42 @@ compiled in, use
        $ cmake .. -DCMAKE_BUILD_TYPE=DEBUG
 ```
 
-Quirk of cmake
---------------
+**NOTE6**
+To build on Solaris the linker needs to be informed to use lib socket
+and libnsl, and only builds in 64bit mode.
+
+```bash
+       $ cmake .. -DCMAKE_C_FLAGS=-m64 -DCMAKE_EXE_LINKER_FLAGS="-lsocket -lnsl"
+```
+
+4. Finally you can build using the generated Makefile:
+
+```bash
+       $ make
+ ```
+
+@section lcap Linux Capabilities
+
+On Linux, lws now lets you retain selected root capabilities when dropping
+privileges.  If libcap-dev or similar package is installed providing
+sys/capabilities.h, and libcap or similar package is installed providing
+libcap.so, CMake will enable the capability features.
+
+The context creation info struct .caps[] and .count_caps members can then
+be set by user code to enable selected root capabilities to survive the
+transition to running under an unprivileged user.
+
+@section cmq Quirk of cmake
 
 When changing cmake options, for some reason the only way to get it to see the
 changes sometimes is delete the contents of your build directory and do the
 cmake from scratch.
 
-Building on Windows (Visual Studio)
------------------------------------
+deleting build/CMakeCache.txt may be enough.
+
+
+@section cmw Building on Windows (Visual Studio)
+
 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
 
 2. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
@@ -147,15 +181,15 @@ Building on Windows (Visual Studio)
 6. If you're using libuv, you must make sure to compile libuv with the same multithread-dll / Mtd attributes as libwebsockets itself
 
 
-Building on Windows (MinGW)
----------------------------
+@section cmwmgw Building on Windows (MinGW)
+
 1. Install MinGW: http://sourceforge.net/projects/mingw/files
 
    (**NOTE**: Preferably in the default location C:\MinGW)
 
 2. Fix up MinGW headers
 
-   a) Add the following lines to C:\MinGW\include\winsock2.h:
+   a) If still necessary, sdd the following lines to C:\MinGW\include\winsock2.h:
 ```
        #if(_WIN32_WINNT >= 0x0600)
 
@@ -171,9 +205,16 @@ Building on Windows (MinGW)
 
        #endif // (_WIN32_WINNT >= 0x0600)
 ```
+
+       Update crtdefs.h line 47 to say:
+
+```
+       typedef __int64 ssize_t;
+```
+
    b) Create C:\MinGW\include\mstcpip.h and copy and paste the content from following link into it:
-    
-   http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html
+
+   https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/mstcpip.h
 
 3. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
 
@@ -210,81 +251,49 @@ Building on Windows (MinGW)
        $ make install
 ```
 
-Setting compile options
------------------------
-
-To set compile time flags you can either use one of the CMake gui applications
-or do it via command line.
-
-Command line
-------------
-To list avaialable options (ommit the H if you don't want the help text):
-
-       cmake -LH ..
-
-Then to set an option and build (for example turn off SSL support):
-
-       cmake -DLWS_WITH_SSL=0 ..
-or
-       cmake -DLWS_WITH_SSL:BOOL=OFF ..
-
-Building on mbed3
------------------
-MBED3 is a non-posix embedded OS targeted on Cortex M class chips.
-
-https://www.mbed.com/
+@section optee Building for OP-TEE
 
-It's quite unlike any other Posixy platform since the OS is linked statically
-in with lws to form one binary.
+OP-TEE is a "Secure World" Trusted Execution Environment.
 
-At the minute server-only is supported and due to bugs in mbed3 network support,
-the port is of alpha quality.  However it can serve the test html, favicon.ico
-and logo png and may be able to make ws connections.  The binary for that
-including the OS, test app, lws and all the assets is only 117KB.
+Although lws is only part of the necessary picture to have an https-enabled
+TA, it does support OP-TEE as a platform and if you provide the other
+pieces, does work very well.
 
-0) Today mbed3 only properly works on FRDM K64F $35 Freescale Dev Board with
-1MB Flash, 256KB SRAM and Ethernet.
+Select it in cmake with `-DLWS_PLAT_OPTEE=1`
 
-http://www.freescale.com/products/arm-processors/kinetis-cortex-m/k-series/k6x-ethernet-mcus/freescale-freedom-development-platform-for-kinetis-k64-k63-and-k24-mcus:FRDM-K64F
 
-1) Get a working mbed3 environment with arm-none-eabi-cs toolchain
-(available in Fedora, Ubuntu and other distros)
+@section cmco Setting compile options
 
-2) Confirm you can build things using yotta by following the getting started guide here
-
-https://docs.mbed.com/docs/getting-started-mbed-os/en/latest/
-
-3)
-
-git clone https://github.com/warmcat/lws-test-server
-
-and cd into it
+To set compile time flags you can either use one of the CMake gui applications
+or do it via the command line.
 
-4) mkdir -p yotta_modules ; cd yotta_modules
+@subsection cmcocl Command line
 
-5) git clone https://github.com/warmcat/libwebsockets ; mv libwebsockets websockets ; cd ..
+To list available options (omit the H if you don't want the help text):
 
-6) yotta target frdm-k64f-gcc
+       cmake -LH ..
 
-7) yotta install
+Then to set an option and build (for example turn off SSL support):
 
-8) yotta build
+       cmake -DLWS_WITH_SSL=0 ..
+or
+       cmake -DLWS_WITH_SSL:BOOL=OFF ..
 
+@subsection cmcoug Unix GUI
 
-Unix GUI
---------
 If you have a curses-enabled build you simply type:
 (not all packages include this, my debian install does not for example).
 
        ccmake
 
-Windows GUI
------------
+@subsection cmcowg Windows GUI
+
 On windows CMake comes with a gui application:
        Start -> Programs -> CMake -> CMake (cmake-gui)
 
-wolfSSL/CyaSSL replacement for OpenSSL
---------------------------------------
+
+@section wolf wolfSSL/CyaSSL replacement for OpenSSL
+
 wolfSSL/CyaSSL is a lightweight SSL library targeted at embedded systems:
 https://www.wolfssl.com/wolfSSL/Products-wolfssl.html
 
@@ -294,8 +303,8 @@ much link to it instead of OpenSSL, giving a much smaller footprint.
 **NOTE**: wolfssl needs to be compiled using the `--enable-opensslextra` flag for
 this to work.
 
-Compiling libwebsockets with wolfSSL
-------------------------------------
+@section wolf1 Compiling libwebsockets with wolfSSL
+
 ```
        cmake .. -DLWS_USE_WOLFSSL=1 \
                 -DLWS_WOLFSSL_INCLUDE_DIRS=/path/to/wolfssl \
@@ -304,8 +313,8 @@ Compiling libwebsockets with wolfSSL
 
 **NOTE**: On windows use the .lib file extension for `LWS_WOLFSSL_LIBRARIES` instead.
 
-Compiling libwebsockets with CyaSSL
------------------------------------
+@section cya Compiling libwebsockets with CyaSSL
+
 ```
        cmake .. -DLWS_USE_CYASSL=1 \
                 -DLWS_CYASSL_INCLUDE_DIRS=/path/to/cyassl \
@@ -314,22 +323,28 @@ Compiling libwebsockets with CyaSSL
 
 **NOTE**: On windows use the .lib file extension for `LWS_CYASSL_LIBRARIES` instead.
 
-Compiling libwebsockets with PolarSSL
--------------------------------------
+@section esp32 Building for ESP32
+
+Step 1, get ESP-IDF with lws integrated as a component
 
-Caution... at some point PolarSSL became MbedTLS.  But it did not happen all at once.
-The name changed first then at mbedTLS 2.0 the apis changed.  So eg in Fedora 22,
-there is an "mbedtls" package which is actually using polarssl for the include dir
-and polarssl apis... this should be treated as polarssl then.
+```
+    $ git clone --int --recursive https://github.com/lws-team/lws-esp-idf
+```
+
+Step 2: Get Application including the test plugins
 
-Example config for this case is
 ```
-cmake .. -DLWS_USE_POLARSSL=1 -DLWS_POLARSSL_LIBRARIES=/usr/lib64/libmbedtls.so \
-        -DLWS_POLARSSL_INCLUDE_DIRS=/usr/include/polarssl/
+    $ git clone https://github.com/lws-team/lws-esp32
 ```
 
-Building plugins outside of lws itself
---------------------------------------
+Set your IDF_PATH to point to the esp-idf you downloaded in 1)
+
+There's docs for how to build the lws-esp32 test app and reproduce it in the README.md here
+
+https://github.com/lws-team/lws-esp32/blob/master/README.md
+
+
+@section extplugins Building plugins outside of lws itself
 
 The directory ./plugin-standalone/ shows how easy it is to create plugins
 outside of lws itself.  First build lws itself with -DLWS_WITH_PLUGINS,
@@ -361,8 +376,7 @@ additionally, discovered plugins are not enabled automatically for security
 reasons.  You do this using info->pvo or for lwsws, in the JSON config.
 
 
-Reproducing HTTP2.0 tests
--------------------------
+@section http2rp Reproducing HTTP2.0 tests
 
 You must have built and be running lws against a version of openssl that has
 ALPN / NPN.  Most distros still have older versions.  You'll know it's right by
@@ -383,8 +397,8 @@ For SSL / ALPN HTTP2.0 upgrade
        $ nghttp -nvas https://localhost:7681/test.html
 ```
 
-Cross compiling
----------------
+@section cross Cross compiling
+
 To enable cross-compiling **libwebsockets** using CMake you need to create
 a "Toolchain file" that you supply to CMake when generating your build files.
 CMake will then use the cross compilers and build paths specified in this file
@@ -397,7 +411,7 @@ The commandline to configure for cross with this would look like
 ```
        $ cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr \
                 -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake \
-                -DWITHOUT_EXTENSIONS=1 -DWITH_SSL=0
+                -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_SSL=0
 ```
 The example shows how to build with no external cross lib dependencies, you
 need to provide the cross libraries otherwise.
@@ -408,8 +422,7 @@ need to provide the cross libraries otherwise.
 Additional information on cross compilation with CMake:
        http://www.vtk.org/Wiki/CMake_Cross_Compiling
 
-Memory efficiency
------------------
+@section mem Memory efficiency
 
 Embedded server-only configuration without extensions (ie, no compression
 on websocket connections), but with full v13 websocket features and http