summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2024-12-13 07:13:08 +0000
committerGravatar grunfink2024-12-13 07:13:08 +0000
commite94db271d130a348fdff4940fed4a8b0950bac86 (patch)
treefcd0264989556f1c84bed39d4ec872bbc485704d
parentVersion 2.66 RELEASED. (diff)
parentexamples: add instructions to statically link snac with musl libc (diff)
downloadpenes-snac2-e94db271d130a348fdff4940fed4a8b0950bac86.tar.gz
penes-snac2-e94db271d130a348fdff4940fed4a8b0950bac86.tar.xz
penes-snac2-e94db271d130a348fdff4940fed4a8b0950bac86.zip
Merge pull request 'Makefile: enable static compilation with musl' (#229) from Shamar/snac2:build-with-musl into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/229
-rw-r--r--Makefile8
-rw-r--r--examples/static-linking-with-musl.md77
2 files changed, 81 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 600419d..05e65f5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
1PREFIX=/usr/local 1PREFIX?=/usr/local
2PREFIX_MAN=$(PREFIX)/man 2PREFIX_MAN=$(PREFIX)/man
3CFLAGS?=-g -Wall -Wextra -pedantic 3CFLAGS?=-g -Wall -Wextra -pedantic
4 4
@@ -6,16 +6,16 @@ all: snac
6 6
7snac: snac.o main.o data.o http.o httpd.o webfinger.o \ 7snac: 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
14clean: 14clean:
15 rm -rf *.o *.core snac makefile.depend 15 rm -rf *.o *.core snac makefile.depend
16 16
17dep: 17dep:
18 $(CC) -I/usr/local/include -MM *.c > makefile.depend 18 $(CC) -I$(PREFIX)/include -MM *.c > makefile.depend
19 19
20install: 20install:
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
3Prepare the environment
4```
5mkdir build
6cd build
7export BUILD_TARGET=$PWD
8export CC="musl-gcc"
9```
10
11Download and build latest zlib
12```
13wget http://zlib.net/current/zlib.tar.gz
14tar xvf zlib.tar.gz
15cd zlib-1.3.1/
16./configure --prefix=$BUILD_TARGET --static
17make
18make install
19cd ..
20```
21
22Download and build latest openssl
23```
24wget https://github.com/openssl/openssl/releases/download/openssl-3.4.0/openssl-3.4.0.tar.gz
25tar xvf openssl-3.4.0.tar.gz
26cd openssl-3.4.0
27CC="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
29make depend
30make
31make install
32cd ..
33```
34
35Download and build latest curl
36```
37wget https://curl.se/download/curl-7.88.1.tar.gz
38tar xvf curl-7.88.1.tar.gz
39cd 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/
61make
62make install
63cd ..
64```
65
66Download and build latest snac2
67```
68git clone https://codeberg.org/grunfink/snac2.git # or cd to your existing repo
69cd snac2
70make CFLAGS="-g -Wall -Wextra -pedantic -static -DWITHOUT_SHM" \
71 LDFLAGS="-L$BUILD_TARGET/lib64 -lcurl -lssl -lcrypto -lz" \
72 PREFIX=$BUILD_TARGET
73make install PREFIX=$BUILD_TARGET
74cd ..
75```
76
77Finally a statically linked snac is ready at $BUILD_TARGET/bin