nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

musl-static-ubuntu.sh (2524B)


      1 #!/usr/bin/env sh
      2 
      3 # Statically compile nnn with netbsd-curses, musl-fts and musl libc on Ubuntu
      4 #
      5 # netbsd-curses: https://github.com/sabotage-linux/netbsd-curses
      6 # musl-fts: https://github.com/void-linux/musl-fts
      7 # musl libc: https://www.musl-libc.org/
      8 #
      9 # Dependencies: git
     10 #
     11 # Usage: musl-static-ubuntu.sh [no_run]
     12 #        # optional argument - do not to execute the binary after compilation
     13 #
     14 # Notes:
     15 #   - run the script within the top-level nnn directory
     16 #   - installs musl & gits netbsd-curses, musl-fts libs
     17 #
     18 # Tested on Ubuntu 20.04 x86_64
     19 # Author: Arun Prakash Jana
     20 
     21 # Exit on first failure
     22 set -e
     23 
     24 # Output binary names
     25 BIN=nnn-musl-static
     26 EMOJIBIN=nnn-musl-emoji-static
     27 
     28 # Install musl
     29 sudo apt install -y --no-install-recommends musl musl-dev musl-tools
     30 
     31 # Get netbsd-curses
     32 [ ! -d "./netbsd-curses" ] && git clone https://github.com/sabotage-linux/netbsd-curses
     33 
     34 # Enter the library dir
     35 cd netbsd-curses
     36 
     37 # Get the last known working version
     38 git checkout v0.3.2
     39 
     40 # Compile the static netbsd-curses libraries
     41 if [ ! -d "./libs" ]; then
     42     mkdir libs
     43 else
     44     rm -vf -- libs/*
     45 fi
     46 make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static all-static -j$(($(nproc)+1))
     47 cp -v libcurses/libcurses.a libterminfo/libterminfo.a libs/
     48 
     49 # Get musl-fts library
     50 cd ..
     51 [ ! -d "./musl-fts" ] && git clone https://github.com/void-linux/musl-fts --depth=1
     52 
     53 # Compile the static musl-fts library
     54 cd musl-fts
     55 ./bootstrap.sh
     56 ./configure
     57 make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static -j$(($(nproc)+1))
     58 
     59 cd ..
     60 
     61 # Compile nnn with Emoji
     62 [ -d "./netbsd-curses" ] && [ -d ./musl-fts ] || rm -- "$EMOJIBIN"
     63 musl-gcc -DEMOJI -std=c11 -Wall -Wextra -Wshadow -O3 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DICONS_GENERATE -o src/icons-hash-gen src/icons-hash.c
     64 ./src/icons-hash-gen > src/icons-generated-emoji.h
     65 musl-gcc -O3 -DNORL -DNOMOUSE -DEMOJI -DICONS_INCLUDE=\"icons-generated-emoji.h\" -std=c11 -Wall -Wextra -Wshadow -I./netbsd-curses/libcurses -I./musl-fts -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -o "$EMOJIBIN"  src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L./netbsd-curses/libs -lcurses -lterminfo -static -L./musl-fts/.libs -lfts
     66 
     67 # Compile nnn
     68 [ -d "./netbsd-curses" ] && [ -d ./musl-fts ] || rm -- "$BIN"
     69 musl-gcc -O3 -DNORL -DNOMOUSE -std=c11 -Wall -Wextra -Wshadow -I./netbsd-curses/libcurses -I./musl-fts -o "$BIN" src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L./netbsd-curses/libs -lcurses -lterminfo -static -L./musl-fts/.libs -lfts
     70 strip "$BIN"
     71 
     72 if [ -z "$1" ]; then
     73     # Run the binary with it selected
     74     ./"$BIN" -d "$BIN"
     75 fi