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