diff options
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | examples/static-linking-with-musl.md | 77 |
2 files changed, 81 insertions, 4 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | PREFIX=/usr/local | 1 | PREFIX?=/usr/local |
| 2 | PREFIX_MAN=$(PREFIX)/man | 2 | PREFIX_MAN=$(PREFIX)/man |
| 3 | CFLAGS?=-g -Wall -Wextra -pedantic | 3 | CFLAGS?=-g -Wall -Wextra -pedantic |
| 4 | 4 | ||
| @@ -6,16 +6,16 @@ all: snac | |||
| 6 | 6 | ||
| 7 | snac: snac.o main.o data.o http.o httpd.o webfinger.o \ | 7 | snac: snac.o main.o data.o http.o httpd.o webfinger.o \ |
| 8 | activitypub.o html.o utils.o format.o upgrade.o mastoapi.o | 8 | activitypub.o html.o utils.o format.o upgrade.o mastoapi.o |
| 9 | $(CC) $(CFLAGS) -L/usr/local/lib *.o -lcurl -lcrypto $(LDFLAGS) -pthread -o $@ | 9 | $(CC) $(CFLAGS) -L$(PREFIX)/lib *.o -lcurl -lcrypto $(LDFLAGS) -pthread -o $@ |
| 10 | 10 | ||
| 11 | .c.o: | 11 | .c.o: |
| 12 | $(CC) $(CFLAGS) $(CPPFLAGS) -I/usr/local/include -c $< | 12 | $(CC) $(CFLAGS) $(CPPFLAGS) -I$(PREFIX)/include -c $< |
| 13 | 13 | ||
| 14 | clean: | 14 | clean: |
| 15 | rm -rf *.o *.core snac makefile.depend | 15 | rm -rf *.o *.core snac makefile.depend |
| 16 | 16 | ||
| 17 | dep: | 17 | dep: |
| 18 | $(CC) -I/usr/local/include -MM *.c > makefile.depend | 18 | $(CC) -I$(PREFIX)/include -MM *.c > makefile.depend |
| 19 | 19 | ||
| 20 | install: | 20 | install: |
| 21 | mkdir -p -m 755 $(PREFIX)/bin | 21 | mkdir -p -m 755 $(PREFIX)/bin |
diff --git a/examples/static-linking-with-musl.md b/examples/static-linking-with-musl.md new file mode 100644 index 0000000..b14132c --- /dev/null +++ b/examples/static-linking-with-musl.md | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | # How to build a statically linked Snac with musl | ||
| 2 | |||
| 3 | Prepare the environment | ||
| 4 | ``` | ||
| 5 | mkdir build | ||
| 6 | cd build | ||
| 7 | export BUILD_TARGET=$PWD | ||
| 8 | export CC="musl-gcc" | ||
| 9 | ``` | ||
| 10 | |||
| 11 | Download and build latest zlib | ||
| 12 | ``` | ||
| 13 | wget http://zlib.net/current/zlib.tar.gz | ||
| 14 | tar xvf zlib.tar.gz | ||
| 15 | cd zlib-1.3.1/ | ||
| 16 | ./configure --prefix=$BUILD_TARGET --static | ||
| 17 | make | ||
| 18 | make install | ||
| 19 | cd .. | ||
| 20 | ``` | ||
| 21 | |||
| 22 | Download and build latest openssl | ||
| 23 | ``` | ||
| 24 | wget https://github.com/openssl/openssl/releases/download/openssl-3.4.0/openssl-3.4.0.tar.gz | ||
| 25 | tar xvf openssl-3.4.0.tar.gz | ||
| 26 | cd openssl-3.4.0 | ||
| 27 | CC="musl-gcc -fPIE -pie -static -idirafter /usr/include/ -idirafter /usr/include/x86_64-linux-gnu/" \ | ||
| 28 | ./Configure no-shared no-async --prefix=$BUILD_TARGET --openssldir=$BUILD_TARGET/ssl linux-x86_64 | ||
| 29 | make depend | ||
| 30 | make | ||
| 31 | make install | ||
| 32 | cd .. | ||
| 33 | ``` | ||
| 34 | |||
| 35 | Download and build latest curl | ||
| 36 | ``` | ||
| 37 | wget https://curl.se/download/curl-7.88.1.tar.gz | ||
| 38 | tar xvf curl-7.88.1.tar.gz | ||
| 39 | cd curl-7.88.1 | ||
| 40 | ./configure --disable-shared --enable-static --disable-silent-rules \ | ||
| 41 | --disable-debug --disable-warnings --disable-werror \ | ||
| 42 | --disable-curldebug --disable-symbol-hiding --disable-ares \ | ||
| 43 | --disable-rt --disable-ech --disable-dependency-tracking \ | ||
| 44 | --disable-libtool-lock --enable-http --disable-ftp \ | ||
| 45 | --disable-file --disable-ldap --disable-ldaps \ | ||
| 46 | --disable-rtsp --disable-proxy --disable-dict \ | ||
| 47 | --disable-telnet --disable-tftp --disable-pop3 \ | ||
| 48 | --disable-imap --disable-smb --disable-smtp --disable-gopher \ | ||
| 49 | --disable-mqtt --disable-manual --disable-libcurl-option --disable-ipv6 \ | ||
| 50 | --disable-openssl-auto-load-config --disable-versioned-symbols | ||
| 51 | --disable-verbose --disable-sspi --disable-crypto-auth \ | ||
| 52 | --disable-ntlm --disable-ntlm-wb --disable-tls-srp \ | ||
| 53 | --disable-unix-sockets --disable-cookies --disable-socketpair \ | ||
| 54 | --disable-http-auth --disable-doh --disable-mime --disable-dateparse \ | ||
| 55 | --disable-netrc --disable-progress-meter --disable-dnsshuffle \ | ||
| 56 | --disable-get-easy-options --disable-alt-svc --disable-websockets \ | ||
| 57 | --without-brotli --without-zstd --without-libpsl --without-libgsasl \ | ||
| 58 | --without-librtmp --without-winidn --disable-threaded-resolver \ | ||
| 59 | --with-openssl=$BUILD_TARGET/ --with-zlib=$BUILD_TARGET/ \ | ||
| 60 | --prefix=$BUILD_TARGET/ | ||
| 61 | make | ||
| 62 | make install | ||
| 63 | cd .. | ||
| 64 | ``` | ||
| 65 | |||
| 66 | Download and build latest snac2 | ||
| 67 | ``` | ||
| 68 | git clone https://codeberg.org/grunfink/snac2.git # or cd to your existing repo | ||
| 69 | cd snac2 | ||
| 70 | make CFLAGS="-g -Wall -Wextra -pedantic -static -DWITHOUT_SHM" \ | ||
| 71 | LDFLAGS="-L$BUILD_TARGET/lib64 -lcurl -lssl -lcrypto -lz" \ | ||
| 72 | PREFIX=$BUILD_TARGET | ||
| 73 | make install PREFIX=$BUILD_TARGET | ||
| 74 | cd .. | ||
| 75 | ``` | ||
| 76 | |||
| 77 | Finally a statically linked snac is ready at $BUILD_TARGET/bin | ||