Skip to content
Fangrui Song edited this page Dec 3, 2022 · 77 revisions
cd
git clone https://github.com/MaskRay/Config
cd Config
./deploy.bash

Emacs

sudo apt install libjansson-dev => --with-json (default) => native json-parse-string

apt install libgif-dev libgtk-3-dev libgnutls28-dev libjpeg-dev libxpm-dev texinfo

apt install libgccjit-12-dev

mkdir -p ~/Dev/Emacs
cd ~/Dev/Emacs
git clone https://github.com/emacs-mirror/emacs
cd emacs
./autogen.sh

# Delete files like lisp/*.elc
# mkdir -p out/release; cd out/release
# apt install libwebkit2gtk-4.0-dev
mkdir -p out/native; cd out/native
../../configure --with-native-compilation --with-xwidgets CFLAGS='-O3 -march=native' LDFLAGS=-fuse-ld=lld

make -j
git clone --depth=1 https://github.com/hlissner/doom-emacs ~/.emacs.d

Neovim

apt install libtool-bin pkg-config

git clone --depth=1 https://github.com/neovim/neovim ~/projects/neovim
cd ~/projects/neovim
make CMAKE_EXTRA_FLAGS=-DCMAKE_INSTALL_PREFIX=$HOME/.local
make install

ccls

If you compile with local clang+llvm, ninja clangFormat clangIndex clangTooling should be sufficient.

# link against local clang to leverage latest features
LLVM=$(realpath ~/llvm)
cmake -H. -Bout/release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld' -DCMAKE_PREFIX_PATH="$LLVM/out/stable;$LLVM/out/stable/tools/clang;$LLVM/llvm;$LLVM/clang"

# Build with the prebuilt 9.0.0 package
cmake -H. -Bout/prebuilt-9 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_PREFIX_PATH=$(realpath ~/llvm-prebuilt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04)

# Debug build with local clang
LLVM=$(realpath ~/llvm)
cmake -H. -Bout/debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_CXX_FLAGS=-gsplit-dwarf=single -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld -Wl,--gdb-index' -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_PREFIX_PATH="$LLVM/Release;$LLVM/Release/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug build with local Debug clang
cmake -H. -Bout/debug-clang -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_CXX_FLAGS=-gsplit-dwarf=single -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld -Wl,--gdb-index' -DCMAKE_PREFIX_PATH="$out/Debug;$out/Debug/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug+ASAN build with local clang
cmake -H. -Bout/asan -G Ninja -DASAN=on -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$LLVM/Release/bin/clang++ -DCMAKE_CXX_LINK_FLAGS=-fuse-ld=lld -DCMAKE_PREFIX_PATH="$LLVM/out/release;$LLVM/out/release/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug build with bundled clang+llvm downloaded from releases.llvm.org
cmake -H. -Bout/debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_LINK_FLAGS='-fuse-ld=lld -Wl,-export-dynamic'
  • Faster linking: -gsplit-dwarf=single, -fuse-ld=lld
  • Function name in symbolizer: -DCMAKE_CXX_LINK_FLAGS=-Wl,-export-dynamic

glibc

mkdir Debug; cd Debug
../configure --prefix=/tmp/opt/glibc CFLAGS='-g3 -O2'

Linux

wget 'https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux' -O .config
yes '' | make config
bear make -j bzImage modules

Pre-built clang

curl -s https://raw.githubusercontent.com/chromium/chromium/master/tools/clang/scripts/update.py | python - --output-dir=~/Stable

cd /usr/local/bin
sudo ln -s ~/Stable/bin/{clang,clang++,lld} .
sudo ln -s lld ld

binutils-gdb

https://sourceware.org/git/?p=binutils-gdb.git;a=summary

apt install bison dejagnu flex texinfo

binutils + ld + gas + gdb + gold

mkdir Debug; cd Debug
../configure --enable-binutils --enable-gas --enable-gdb --enable-gold --disable-gprof --enable-ld --enable-plugins --without-guile --prefix=~/.local/stow/gdb CFLAGS='-O0 -g' CXXFLAGS='-O0 -g'
bear make -j

mkdir DebugAll; cd DebugAll
../configure --enable-targets=all CFLAGS='-g3 -O0' --disable-gdb

# i686
mkdir -p out/i686; cd out/i686
CC='gcc -m32' CXX='g++ -m32' ../../configure --prefix=~/.local/stow/gdb --disable-gdb --disable-readline i686-linux

## riscv
mkdir -p out/riscv; cd out/riscv
../../configure --target riscv --enable-binutils --enable-gas --enable-gdb --enable-gold --disable-gprof --enable-ld --enable-plugins --without-guile CFLAGS='-O0 -g' CXXFLAGS='-O0 -g'

GCC

mkdir Debug; cd Debug
../configure --enable-languages=c CFLAGS='-O0 -g' --disable-multilib --disable-libsanitizer
# apt install binutils-riscv64-linux-gnu
# (cd /usr/riscv64-linux-gnu/usr; sudo ln -s ../include; sudo ln -s .. riscv64-linux-gnu)
mkdir out/riscv64; cd out/riscv64
../../configure --prefix=/tmp/opt/gcc-riscv64 --with-sysroot=/usr/riscv64-linux-gnu --target=riscv64-linux-gnu --enable-languages=c,c++ --disable-multilib --disable-libsanitizer --disable-bootstrap CFLAGS='-O0 -g'
# make install
# /tmp/opt/gcc-riscv64/bin/riscv64-linux-gnu-g++ -B /usr/riscv64-linux-gnu/bin a.cc

Julia

https://github.com/JuliaLang/julia

make -j O=out configure  # edit out/Make.user
bear make -j O=out debug
make -j O=out release

ldc

git clone --recursive https://github.com/ldc-developers/ldc.git

cmake -H. -BDebug9 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$HOME/Stable/bin/clang -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DD_COMPILER=$HOME/dlang/ldc-1.18.0/bin/ldmd2 -DCMAKE_CXX_STANDARD=14 -DLLVM_ROOT_DIR=$HOME/ccls/build/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04

musl

mkdir debug; cd debug
../configure --enable-optimize=no --enable-debug --prefix=~/.local/stow/musl CFLAGS=-fuse-ld=lld
# CFLAGS=-mlong-double-64 on powerpc64le
# ~/Dev/Bin/musl-gcc.specs
*srcdir:
/home/ray/musl

*bindir:
/home/ray/musl/Debug

%rename cpp_options old_cpp_options

*cpp_options:
-nostdinc -isystem %(srcdir)/arch/x86_64 -isystem %(srcdir)/arch/generic -isystem %(srcdir)/include -isystem %(bindir)/obj/include -isystem include%s %(old_cpp_options)

*cc1:
%(cc1_cpu) -isystem %(srcdir)/arch/x86_64 -isystem %(srcdir)/arch/generic -isystem %(srcdir)/include -isystem %(bindir)/obj/include -nostdinc -isystem include%s
# arm-linux-musleabihf
../configure AR=~/llvm/Release/bin/llvm-ar RANLIB=: CC="$HOME/llvm/Release/bin/clang -target arm-linux-musleabihf" LDFLAGS=-fuse-ld=lld
# powerpc gcc
../configure CROSS_COMPILE=powerpc-linux-gnu- LDFLAGS=-fuse-ld=gold CFLAGS=-mlong-double-64
# riscv64
../configure --target riscv64 CROSS_COMPILE=/home/maskray/.local/opt/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed- CFLAGS='-march=rv64imafdc -mabi=lp64d'

libc-test

git clone git://repo.or.cz/libc-test.git
cd libc-test
# config.mak
CFLAGS += -specs ~/Dev/Bin/musl-gcc.specs
LDFLAGS += -specs ~/Dev/Bin/musl-gcc.specs

# config.mak.def minus glibc

radare2

(cd test; ln -s ~/Dev/Bin/radare2-testbins bins)

## ASAN
CFLAGS='-fsanitize=address,undefined -gsplit-dwarf' LDFLAGS='-fuse-ld=lld' meson . out/asan --buildtype=debug --prefix ~/.opt/radare2/asan -Db_lundef=false
## Debug
CFLAGS=-gsplit-dwarf meson . out/debug --buildtype=debug --prefix ~/.opt/radare2/debug
## Release
meson . out/release --buildtype=release --prefix ~/.opt/radare2/release
mkdir -p ~/.local/share/radare2
cd ~/.local/share/radare2
ln -s ~/Dev/radare2/libr/cons/d cons
ln -s ~/Dev/radare2/Release/libr/anal/d anal
ln -s ~/Dev/radare2/Release/libr/asm/d asm
ln -s ~/Dev/radare2/Release/libr/bin/d bin
ln -s ~/Dev/radare2/Release/libr/flag/d flag
ln -s ~/Dev/radare2/Release/libr/syscall/d syscall

radare2-regressions:

export PKG_CONFIG_PATH=~/.config/radare2/Release/lib/x86_64-linux-gnu/pkgconfig

radare2-extras:

cd ~/Dev && git clone https://github.com/radareorg/radare2-extras
# R2_CFLAGS for r_asm.h
# R2PM_PREFIX for correct -Wl,-R
PKG_CONFIG_PATH=~/Dev/Bin/keystone/Release R2_CFLAGS=-I$HOME/.config/radare2/Release/include/libr R2PM_PREFIX=~/Dev/Bin/keystone/Release/llvm make -C keystone

mkdir -p ~/.local/share/radare2/plugins && cd ~/.local/share/radare2/plugins
for i in ~/Dev/radare2-extras/keystone/*.so; do ln -s $i; done

keystone:

cd ~/Dev/Bin
git clone https://github.com/keystone-engine/keystone
cd keystone
mkdir Release; cd Release
../make-lib.sh
# Modify Release/keystone.pc
# Release/llvm/lib/libkeystone.so
sed -i 's,^includedir=.*,includedir=/home/maskray/Dev/Bin/keystone/include,' keystone.pc
sed -i 's,^libdir=.*,includedir=/home/maskray/Dev/Bin/keystone/Release/llvm/lib,' keystone.pc

wabt

git clone https://github.com/WebAssembly/wabt

cmake -G Ninja -H. -Bout/clang/Release -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Release
cmake --build out/clang/Release

bpftrace

apt install clang-8 libclang-8-dev

bcc

git clone https://github.com/iovisor/bcc; cd bcc
cmake -GNinja -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/llvm/bin/clang++ -DCMAKE_C_COMPILER=$HOME/llvm/bin/clang -DCMAKE_INSTALL_PREFIX=~/.local/stow/bcc -DLLVM_DIR=/usr/loca/llvm-7/cmake
ninja -C Release install

bpftrace

git clone https://github.com/iovisor/bpftrace; cd bpftrace
cmake -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DLIBBCC_INCLUDE_DIRS=$HOME/.local/stow/bcc/include/bcc -DLIBBCC_LIBRARIES=~/.local/stow/bcc/lib/libbcc.so -DLLVM_DIR=/usr/lib/llvm-8/cmake
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DLIBBCC_INCLUDE_DIRS=$HOME/.local/stow/bcc/include/bcc -DLIBBCC_LIBRARIES=~/.local/stow/bcc/lib/libbcc.so -DLLVM_DIR=/usr/lib/llvm-8/cmake

qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -m 2048 -kernel vmlinuz-vanilla -initrd initramfs-vanilla -append "console=ttyAMA0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main/"

ruby

git clone https://github.com/ruby/ruby; cd ruby
autoreconf
mkdir Debug; cd Debug
../configure --prefix=/tmp/opt CFLAGS='-gsplit-dwarf=single' CC=~/Stable/bin/clang
bear make -j install-doc
cd ..; ln -s Debug/compile_commands.json

xmonad

sudo apt install libx11-dev libxss-dev
stack install xmonad xmonad-contrib xmobar
Clone this wiki locally