This document describes how to build a completely self-contained, statically linked "althttpd" binary for Linux (or similar unix-like operating systems).
What You Need
- The
althttpd.c
source code file from this website. - A tarball of the latest OpenSSL release.
- The usual unix build tools, "make", "gcc", and friends.
- The OpenSSL build requires Perl.
Build Steps
- Compiling a static OpenSSL library.
- Unpack the OpenSSL tarball. Rename the top-level directory to "openssl".
- CD into the openssl directory.
- Run these commands:
./config no-ssl3 no-weak-ssl-ciphers no-shared no-threads no-tls-deprecated-ec --openssldir=/usr/lib/ssl make CFLAGS=-Os
- Fix a cup of tea while OpenSSL builds.... Note that the
no-tls-deprecated-ec
option is only available with OpenSSL-3.5.0 and later, so omit that option for earlier versions.
- Compiling
althttpd
- CD back up into the top-level directory where the
althttpd.c
source file lives. - Run:
make VERSION.h gcc -I./openssl/include -Os -Wall -Wextra -DENABLE_TLS \ -o althttpd althttpd.c -L./openssl -lssl -lcrypto -ldl
- The commands in the previous bullet builds a binary that is statically linked against OpenSSL, but is still dynamically linked against system libraries.
- To make the binary completely static, add the
-static
option. This might be necessary, for example, when compiling on one flavor of Linux (ex: Ubuntu) for use on a different distro (ex: Alpine). - The "make VERSION.h" step above constructs a generated file named "VERSION.h" that contains the specific version number of althttpd that you are building.
- CD back up into the top-level directory where the
Using The Binary
The above is all you need to do. After compiling, simply move the resulting binary into the /usr/bin directory of your server.