mirror of
https://github.com/notwa/rc
synced 2024-06-30 19:07:11 -07:00
add ad-hoc MSVC support
This commit is contained in:
parent
d427464c50
commit
f2a34d9b16
144
sh/compile
144
sh/compile
|
@ -24,49 +24,109 @@ deb $site/$name/ llvm-toolchain-$name-$version main\n\
|
||||||
}
|
}
|
||||||
|
|
||||||
compile() {
|
compile() {
|
||||||
|
local gcc="$(whence -p gcc 2>/dev/null)"
|
||||||
|
local gxx="$(whence -p g++ 2>/dev/null)"
|
||||||
|
local clang="$(whence -p clang 2>/dev/null)"
|
||||||
|
local clangxx="$(whence -p clang++ 2>/dev/null)"
|
||||||
|
|
||||||
|
local cl
|
||||||
|
local vc
|
||||||
|
if [ -n "$MSYSTEM" ]; then
|
||||||
|
local clarch
|
||||||
|
[ "$MSYSTEM" = MINGW64 ] && clarch="/amd64" || clarch=""
|
||||||
|
local arch
|
||||||
|
[ "$MSYSTEM" = MINGW64 ] && arch="x64" || arch="x86"
|
||||||
|
printf "%s\n" "/c/Program Files (x86)/Microsoft Visual Studio "*(On[1]) | read vc
|
||||||
|
vc="$vc/VC"
|
||||||
|
if [ -d "$vc/bin$clarch" ] && [ -e "${vc}/bin$clarch/$cl" ]; then
|
||||||
|
cl="${vc}/bin$clarch/cl"
|
||||||
|
vc="$vc"
|
||||||
|
|
||||||
|
local winkit
|
||||||
|
printf "%s\n" "/c/Program Files (x86)/Windows Kits/"*(on/[1]) | read winkit
|
||||||
|
[ -n "$winkit" ] || { echo "failed glob; missing winkit" >&2; return 1 }
|
||||||
|
printf "%s\n" "$winkit/Lib/"*(On/[1]) | read winkit
|
||||||
|
[ -n "$winkit" ] || { echo "failed glob; missing winkit" >&2; return 1 }
|
||||||
|
|
||||||
|
export PATH="$PATH:$vc/bin$clarch"
|
||||||
|
export INCLUDE="$vc/INCLUDE;$vc/ATLMFC/INCLUDE"
|
||||||
|
export LIB="$vc/LIB$clarch;$vc/ATLMFC/LIB$clarch;$winkit/um/$arch;$winkit/ucrt/$arch"
|
||||||
|
export LIBPATH="$vc/LIB$clarch;$vc/ATLMFC/LIB$clarch"
|
||||||
|
|
||||||
|
# convert msys2 paths to windows paths
|
||||||
|
export INCLUDE="${${INCLUDE//\/c\//C:\\}//\//\\}"
|
||||||
|
export LIB="${${LIB//\/c\//C:\\}//\//\\}"
|
||||||
|
export LIBPATH="${${LIBPATH//\/c\//C:\\}//\//\\}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
echo "usage: compile [clang|gcc] {debug|release} [flags...] {source file}" >&2
|
echo -n "usage: compile [" >&2
|
||||||
|
local once=0
|
||||||
|
if [ -n "$clang" ]; then
|
||||||
|
if [ $once -eq 1 ]; then echo -n "|" >&2; fi; once=1
|
||||||
|
echo -n "clang" >&2
|
||||||
|
fi
|
||||||
|
if [ -n "$gcc" ]; then
|
||||||
|
if [ $once -eq 1 ]; then echo -n "|" >&2; fi; once=1
|
||||||
|
echo -n "gcc" >&2
|
||||||
|
fi
|
||||||
|
if [ -n "$cl" ]; then
|
||||||
|
if [ $once -eq 1 ]; then echo -n "|" >&2; fi; once=1
|
||||||
|
echo -n "msvc" >&2
|
||||||
|
fi
|
||||||
|
echo "] {debug|release} [flags...] {source file}" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local sepples=0
|
local sepples=0
|
||||||
|
# TODO: autodetect here
|
||||||
local CC=gcc
|
local CC=gcc
|
||||||
local CXX=g++
|
local CXX=g++
|
||||||
local our_flags=(-I.)
|
local our_flags=(-I.)
|
||||||
|
|
||||||
|
local file=${@[-1]}
|
||||||
|
[ "${file##*.}" = "c" ] || [ "${file##*.}" = "h" ] || sepples=1
|
||||||
|
|
||||||
|
{ [ $1 = clang ] && CC="clang" && CXX="clang++" && shift } || \
|
||||||
|
{ [ $1 = gcc ] && CC="gcc" && CXX="g++" && shift } || \
|
||||||
|
{ [ $1 = msvc ] && CC="cl" && CXX="cl" && shift }
|
||||||
|
|
||||||
maybe_include() {
|
maybe_include() {
|
||||||
[ -d "$1" ] && our_flags+=("-I$1")
|
[ -d "$1" ] && our_flags+=("-I$1")
|
||||||
}
|
}
|
||||||
maybe_include "-I$HOME/opt/local/include"
|
maybe_include "-I$HOME/opt/local/include"
|
||||||
maybe_include "-I$HOME/src/ustl"
|
maybe_include "-I$HOME/src/ustl"
|
||||||
|
|
||||||
local debug_flags=(-O1 -g -D_DEBUG);
|
if [ $CC = cl ]; then
|
||||||
local release_flags=(-Ofast -march=native -g0 -fomit-frame-pointer -s -DNDEBUG)
|
our_flags+=(-nologo -utf-8)
|
||||||
local dr_flags=(-Ofast -march=native -g -fomit-frame-pointer -DNDEBUG)
|
local debug_flags=(-Od -Zi -ZI -sdl);
|
||||||
local hardened_flags=(-O3 -march=native -g0 -s
|
local release_flags=(-Ox)
|
||||||
-DNDEBUG -D_FORTIFY_SOURCE=2
|
local dr_flags=(-Ox -Zi)
|
||||||
-Wformat -Wformat-security -Werror=format-security)
|
local hardened_flags=(-Ox -sdl)
|
||||||
|
else
|
||||||
|
local debug_flags=(-O1 -g -D_DEBUG);
|
||||||
|
local release_flags=(-Ofast -march=native -g0 -fomit-frame-pointer -s -DNDEBUG)
|
||||||
|
local dr_flags=(-Ofast -march=native -g -fomit-frame-pointer -DNDEBUG)
|
||||||
|
local hardened_flags=(-O3 -march=native -g0 -s
|
||||||
|
-DNDEBUG -D_FORTIFY_SOURCE=2
|
||||||
|
-Wformat -Wformat-security -Werror=format-security)
|
||||||
|
|
||||||
if [ -z "$MSYSTEM" ]; then
|
if [ -z "$MSYSTEM" ]; then
|
||||||
hardened_flags+=(-fPIE -pie)
|
hardened_flags+=(-fPIE -pie)
|
||||||
hardened_flags+=(-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now)
|
hardened_flags+=(-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now)
|
||||||
|
fi
|
||||||
|
|
||||||
|
local nomalloc=(-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free)
|
||||||
|
if [ -e /usr/bin/pprof ]; then
|
||||||
|
#debug_flags+=(-ltcmalloc $nomalloc)
|
||||||
|
dr_flags+=(-lprofiler $nomalloc)
|
||||||
|
elif [ -e /usr/bin/google-pprof ]; then
|
||||||
|
#debug_flags+=(-l:libtcmalloc.so.4 $nomalloc)
|
||||||
|
dr_flags+=(-l:libtcmalloc_and_profiler.so.4 $nomalloc)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local nomalloc=(-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free)
|
|
||||||
if [ -e /usr/bin/pprof ]; then
|
|
||||||
#debug_flags+=(-ltcmalloc $nomalloc)
|
|
||||||
dr_flags+=(-lprofiler $nomalloc)
|
|
||||||
elif [ -e /usr/bin/google-pprof ]; then
|
|
||||||
#debug_flags+=(-l:libtcmalloc.so.4 $nomalloc)
|
|
||||||
dr_flags+=(-l:libtcmalloc_and_profiler.so.4 $nomalloc)
|
|
||||||
fi
|
|
||||||
|
|
||||||
local file=${@[-1]}
|
|
||||||
[ "${file##*.}" = "c" ] || [ "${file##*.}" = "h" ] || sepples=1
|
|
||||||
|
|
||||||
{ [ $1 = clang ] && CC="clang" && CXX="clang++" && shift } || \
|
|
||||||
{ [ $1 = gcc ] && CC="gcc" && CXX="g++" && shift }
|
|
||||||
|
|
||||||
if [ $CC = clang ]; then
|
if [ $CC = clang ]; then
|
||||||
debug_flags+=(-ftrapv)
|
debug_flags+=(-ftrapv)
|
||||||
if [ -z "$MSYSTEM" ]; then # only available on linux
|
if [ -z "$MSYSTEM" ]; then # only available on linux
|
||||||
|
@ -94,10 +154,17 @@ compile() {
|
||||||
local compiler=
|
local compiler=
|
||||||
if [ $sepples -eq 1 ]; then
|
if [ $sepples -eq 1 ]; then
|
||||||
compiler=$CXX
|
compiler=$CXX
|
||||||
std="-std=gnu++1z"
|
[ $CC = cl ] && std="-TP" || std="-std=gnu++1z"
|
||||||
else
|
else
|
||||||
compiler=$CC
|
compiler=$CC
|
||||||
std="-std=gnu11"
|
[ $CC = cl ] && std="-TC" || std="-std=gnu11"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local clang_msvc=0
|
||||||
|
if [ $CC = clang ]; then
|
||||||
|
if $compiler --version | grep -q windows-msvc; then
|
||||||
|
clang_msvc=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local flags=(${@[1,-2]})
|
local flags=(${@[1,-2]})
|
||||||
|
@ -120,15 +187,32 @@ compile() {
|
||||||
for flag in $our_flags $flags; do
|
for flag in $our_flags $flags; do
|
||||||
if [[ $flag == -l* ]]; then
|
if [[ $flag == -l* ]]; then
|
||||||
libraries+=($flag)
|
libraries+=($flag)
|
||||||
elif [[ $flag == -W* ]]; then
|
elif [[ $flag == -W* ]] && [[ $flag != -Wl* ]]; then
|
||||||
warnings+=($flag)
|
warnings+=($flag)
|
||||||
|
if [ $CC = cl ] && [ $flag = -Wall ]; then
|
||||||
|
warnings+=(-wd4711 -wd4505 -wd4514 -wd4625 -wd4626)
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
if [ $clang_msvc -eq 1 ]; then
|
||||||
|
if [ $flag = "-findirect-inlining" ] \
|
||||||
|
|| [ $flag = "-finline-small-functions" ] \
|
||||||
|
|| [ $flag = "-finline-small-functions" ] \
|
||||||
|
|| [ $flag = "-Wl,--gc-sections" ] \
|
||||||
|
|| [ $flag = "-s" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
final_flags+=($flag)
|
final_flags+=($flag)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo $compiler $std ${final_flags[@]} $file ${libraries[@]} -o $out >&2
|
if [ $CC = cl ]; then
|
||||||
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} -o $out >&2
|
echo $compiler $std ${final_flags[@]} $file ${libraries[@]} -Fe: $out >&2
|
||||||
|
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} -Fe: $out >&2
|
||||||
|
else
|
||||||
|
echo $compiler $std ${final_flags[@]} $file ${libraries[@]} -o $out >&2
|
||||||
|
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} -o $out >&2
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
compile "$@"
|
compile "$@"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user