mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
add a dumb compile script with my usual settings
This commit is contained in:
parent
f40da177ed
commit
94851854dc
1 changed files with 52 additions and 0 deletions
52
sh/compile
Executable file
52
sh/compile
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
compile() {
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "usage: compile [clang|gcc] {debug|release} [flags...] {source file}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local sepples=0
|
||||
local CC=gcc
|
||||
local CXX=g++
|
||||
local our_flags=(-I. "-I$HOME/src/ustl")
|
||||
local debug_flags=(-O1 -g);
|
||||
local release_flags=(-Ofast -march=native -g0 -fomit-frame-pointer -s -DNDEBUG)
|
||||
local dr_flags=(-Ofast -march=native -g -fomit-frame-pointer -DNDEBUG)
|
||||
|
||||
if [ -e /usr/bin/pprof ]; then
|
||||
local malloc=(-ltcmalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free)
|
||||
debug_flags+=($malloc[@])
|
||||
derelease_flags+=($malloc[@])
|
||||
derelease_flags+=(-lprofiler)
|
||||
fi
|
||||
|
||||
local file=${@[-1]}
|
||||
[ "${file##*.}" = "c" ] || sepples=1
|
||||
|
||||
{ [ $1 = clang ] && CC="clang" && CXX="clang++" && shift } || \
|
||||
{ [ $1 = gcc ] && CC="gcc" && CXX="g++" && shift }
|
||||
|
||||
{ [ $1 = debug ] && our_flags+=($debug_flags) && shift } || \
|
||||
{ [ $1 = release ] && our_flags+=($release_flags) && shift } || \
|
||||
{ [ $1 = derelease ] && our_flags+=($dr_flags) && shift }
|
||||
|
||||
# TODO add static option
|
||||
|
||||
local compiler=
|
||||
if [ $sepples -eq 1 ]; then
|
||||
compiler=$CXX
|
||||
std="-std=gnu++1z"
|
||||
else
|
||||
compiler=$CC
|
||||
std="-std=gnu11"
|
||||
fi
|
||||
|
||||
local flags=(${@[1,-2]})
|
||||
|
||||
local out=/tmp/${${file%%.*}##*/}
|
||||
|
||||
$compiler $std ${our_flags[@]} ${flags[@]} $file -o $out && echo "$out"
|
||||
}
|
||||
|
||||
compile "$@"
|
Loading…
Add table
Reference in a new issue