]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | Building CivetWeb |
2 | ========= | |
3 | ||
4 | This guide covers the build instructions for the stand-alone web server. | |
5 | See [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) for information on extending an existing C or C++ application. A brief overview of the source code files can be found in [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) as well. | |
6 | ||
7 | #### Where to get the source code? | |
8 | ||
9 | The latest version can be found at | |
10 | https://github.com/civetweb/civetweb | |
11 | ||
12 | Released versions can be found at | |
13 | https://github.com/civetweb/civetweb/releases | |
14 | ||
15 | ||
16 | Building for Windows | |
17 | --------- | |
18 | ||
19 | #### Using Visual Studio | |
20 | ||
21 | Open the *VS/civetweb.sln* in Visual Studio. | |
22 | To include SSL support, you may have to add an extra library for the cryptography support. You might wish to use yaSSL. However, it is GPL licensed or uses a commercial license. See [yaSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/yaSSL.md) for more information. | |
23 | Alternatively, you might wish to use OpenSSL. See [OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) for more information. | |
24 | ||
25 | #### Using MinGW-w64 or TDM-GCC | |
26 | In the start menu locate and run the "Run terminal" batch file. For TDM-GCC this is named "MinGW Command Prompt". | |
27 | Navigate to the civetweb sources directory and run: | |
28 | ``` | |
29 | mingw32-make CC=gcc | |
30 | ``` | |
31 | ||
32 | #### Using Qt Creator | |
33 | Open the Qt Designer project in the Qt folder | |
34 | ||
35 | #### Using CMake | |
36 | Except for the components in the `third_party` folder (e.g., Lua and Duktape), CivetWeb can also be built with CMake. | |
37 | CMake can be used for all supported operating systems. | |
38 | ||
39 | ||
40 | Building for Linux, BSD, and OSX | |
41 | --------- | |
42 | ||
43 | ## Using Make | |
44 | ||
45 | ``` | |
46 | make help | |
47 | ``` | |
48 | Get a list of all supported make option | |
49 | ||
50 | ``` | |
51 | make build | |
52 | ``` | |
53 | compile the code | |
54 | ||
55 | ``` | |
56 | make install | |
57 | ``` | |
58 | Install on the system, Linux only. | |
59 | ||
60 | ``` | |
61 | make lib WITH_CPP=1 WITH_IPV6=1 | |
62 | make clean slib WITH_CPP=1 WITH_LUA=1 WITH_WEBSOCKET=1 | |
63 | ``` | |
64 | Build the static and shared libraries. | |
65 | The *WITH_CPP* make option is to include the CivetServer class. | |
66 | The additional make options configure the library just as it would the application. | |
67 | ||
68 | The *slib* option should be done on a separate clean build as position | |
69 | independent code (PIC) is required for it. Trying to run it after | |
70 | building the static library or the server will result in a link error. | |
71 | ||
72 | ``` | |
73 | make clean | |
74 | ``` | |
75 | Clean up files generated during the build | |
76 | ||
77 | ## Setting build options | |
78 | ||
79 | Make options can be set on the command line with the make command like so. | |
80 | ``` | |
81 | make build WITH_LUA=1 | |
82 | ``` | |
83 | ||
84 | ||
11fdf7f2 TL |
85 | | Make Options | Description | |
86 | | ------------------------- | ----------------------------------------- | | |
87 | | WITH_LUA=1 | build with Lua support | | |
88 | | WITH_DUKTAPE=1 | build with server-side JavaScript support | | |
89 | | WITH_DEBUG=1 | build with GDB debug support | | |
90 | | WITH_IPV6=1 | with IPV6 support | | |
91 | | WITH_WEBSOCKET=1 | build with web socket support | | |
92 | | WITH_SERVER_STATS=1 | build with support for server statistics | | |
93 | | WITH_CPP=1 | build libraries with c++ classes | | |
94 | | CONFIG_FILE=file | use 'file' as the config file | | |
95 | | CONFIG_FILE2=file | use 'file' as the backup config file | | |
96 | | HTMLDIR=/path | place to install initial web pages | | |
97 | | DOCUMENT_ROOT=/path | HTMLDIR override, config option, install | | |
98 | | | nothing is installed here. | | |
99 | | PORTS=8080 | listening ports override when installing | | |
100 | | SSL_LIB=libssl.so.0 | use versioned SSL library | | |
101 | | CRYPTO_LIB=libcrypto.so.0 | system versioned CRYPTO library | | |
102 | | PREFIX=/usr/local | sets the install directory | | |
103 | | COPT='-DNO_SSL' | method to insert compile flags | | |
7c673cae FG |
104 | |
105 | Note that the WITH_* options used for *make* are not identical to the | |
106 | preprocessor defines in the source code - usually USE_* is used there. | |
107 | ||
11fdf7f2 TL |
108 | ## Changing PREFIX |
109 | ||
110 | To change the target destination pass the `PREFIX` option to the command `make install` (not `make build`). Example usage: | |
111 | ||
112 | ``` | |
113 | $ make build | |
114 | $ make -n install PREFIX=/opt/civetweb | |
115 | ``` | |
116 | Note: The `-n` corresponds to the `--dry-run` option (it does not make any changes): You can see where `make install` would install. Example output of the above command: | |
117 | ||
118 | ``` | |
119 | $ make -n install PREFIX=/opt/civetweb | |
120 | install -d -m 755 "/opt/civetweb/share/doc/civetweb" | |
121 | install -m 644 resources/itworks.html /opt/civetweb/share/doc/civetweb/index.html | |
122 | install -m 644 resources/civetweb_64x64.png /opt/civetweb/share/doc/civetweb/ | |
123 | install -d -m 755 "/opt/civetweb/etc" | |
124 | install -m 644 resources/civetweb.conf "/opt/civetweb/etc/" | |
125 | sed -i 's#^document_root.*$#document_root /opt/civetweb/share/doc/civetweb#' "/opt/civetweb/etc/civetweb.conf" | |
126 | sed -i 's#^listening_ports.*$#listening_ports 8080#' "/opt/civetweb/etc/civetweb.conf" | |
127 | install -d -m 755 "/opt/civetweb/share/doc/civetweb" | |
128 | install -m 644 *.md "/opt/civetweb/share/doc/civetweb" | |
129 | install -d -m 755 "/opt/civetweb/bin" | |
130 | install -m 755 civetweb "/opt/civetweb/bin/" | |
131 | ``` | |
132 | ||
133 | If the output looks good: Just remove the `-n` option to actually install the software on your system. | |
134 | ||
7c673cae FG |
135 | ## Setting compile flags |
136 | ||
137 | Compile flags can be set using the *COPT* make option like so. | |
138 | ``` | |
139 | make build COPT="-DNDEBUG -DNO_CGI" | |
140 | ``` | |
141 | ||
142 | | Compile Flags | Description | | |
143 | | ------------------------- | ------------------------------------ | | |
144 | | NDEBUG | strip off all debug code | | |
145 | | DEBUG | build debug version (very noisy) | | |
146 | | NO_CGI | disable CGI support | | |
147 | | NO_CACHING | disable caching functionality | | |
148 | | NO_SSL | disable SSL functionality | | |
149 | | NO_SSL_DL | link against system libssl library | | |
150 | | NO_FILES | do not serve files from a directory | | |
151 | | SQLITE_DISABLE_LFS | disables large files (Lua only) | | |
152 | | SSL_ALREADY_INITIALIZED | do not initialize libcrypto | | |
153 | ||
154 | ## Cross Compiling | |
155 | ||
156 | Take total control with *CC*, *COPT* and *TARGET_OS* as make options. | |
157 | TARGET_OS is used to determine some compile details as will as code function. | |
158 | TARGET_OS values should be be one found in *resources/Makefile.in-os*. | |
159 | ||
160 | ``` | |
161 | make CC=arm-none-linux-gnueabi-gcc COPT="-march=armv7-a -mfpu=vfp -mfloat-abi=softfp" TARGET_OS=FROG | |
162 | ``` | |
163 | ||
164 | ## Cocoa DMG Packaging (OSX Only) | |
165 | ||
166 | Use the alternate *Makefile.osx* to do the build. The entire build has | |
167 | to be done using *Makefile.osx* because additional compile and link options | |
168 | are required. This Makefile has all the same options as the other one plus | |
169 | one additional *package* rule. | |
170 | ||
171 | ``` | |
172 | make -f Makefile.osx package | |
173 | ``` | |
174 | ||
175 | Building with Buildroot | |
176 | --------- | |
177 | ||
178 | [Buildroot](http://buildroot.uclibc.org/) is a tool for creating cross compiled file systems. Including Civetweb in buildroot is fairly easy. There is even support for various build options. | |
179 | ||
180 | 1. First, check if it already there. | |
181 | - In buildroot, make menuconfig | |
182 | - Package Selection for the target ---> | |
183 | - Networking applications ---> | |
184 | - civetweb | |
185 | 2. If not there, just add it | |
186 | - copy *Config.in* and *civetweb.mk* from Civetweb's *contrib/buildroot/* to Buildroot's *package/civetweb/* directory. | |
187 | - In Buildroot's *package/Config.in, insert the following line in were you will know how to find it in the menu. | |
188 | > ``` source "package/civetweb/Config.in" ``` | |
189 | ||
190 | ||
191 | Building on Android | |
192 | --------- | |
193 | ||
11fdf7f2 TL |
194 | This is a small guide to help you run civetweb on Android, originally |
195 | tested on the HTC Wildfire. | |
7c673cae FG |
196 | Note: You do not need root access to run civetweb on Android. |
197 | ||
198 | - Download the source from the Downloads page. | |
199 | - Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html) | |
200 | - Run `/path-to-ndk/ndk-build -C /path-to-civetweb/resources` | |
201 | That should generate civetweb/lib/armeabi/civetweb | |
202 | - Using the adb tool (you need to have Android SDK installed for that), | |
203 | push the generated civetweb binary to `/data/local` folder on device. | |
204 | - From adb shell, navigate to `/data/local` and execute `./civetweb`. | |
205 | - To test if the server is running fine, visit your web-browser and | |
206 | navigate to `http://127.0.0.1:8080` You should see the `Index of /` page. | |
207 | ||
7c673cae FG |
208 | |
209 | Notes: | |
210 | ||
211 | - `jni` stands for Java Native Interface. Read up on Android NDK if you want | |
212 | to know how to interact with the native C functions of civetweb in Android | |
213 | Java applications. | |
11fdf7f2 | 214 | |
7c673cae FG |
215 | |
216 |