static-linking-with-musl.md (2780B)
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