Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Sep 25, 2024
1 parent a357d38 commit 41b225c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 0 additions & 2 deletions build.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define CC_ARGS "-g -ggdb"

#include "build_c/build.h"

/* ========================================================================= */
Expand Down
56 changes: 45 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,39 @@

set -e

: ${CFLAGS:="-Wall -Wextra -Wno-unused -Wno-comment -Wno-format -Wno-sign-compare -Wno-analyzer-malloc-leak -Wno-char-subscripts -Wno-implicit-fallthrough -Wno-missing-braces -Wno-analyzer-deref-before-check -Werror -std=c11"}
: ${CC:=clang}
: ${CFLAGS:="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-comment -Wno-format -Wno-sign-compare -Wno-char-subscripts -Wno-implicit-fallthrough -Wno-missing-braces -Werror -std=c11"}

if [ -z $EMPATH ]; then
: ${CC:=clang}
: ${BUILD_CC:=$CC}
: ${EX_CFLAGS:=""}
: ${AR:="ar"}
else
: ${CC:=$EMPATH/emcc}
: ${BUILD_CC:=clang}
: ${EX_CFLAGS:="-O3"}
: ${AR:=$EMPATH/emar}
fi

ANALYZER_FLAGS="$CFLAGS -Wno-analyzer-malloc-leak -Wno-analyzer-deref-before-check"
CFLAGS="$CFLAGS $EX_CFLAGS"

#CFG_HASH=$(sum <<< "$CC $BUILD_CC $AR $CLAGS")
#CLEAN=1
#if [ -f "_settings.chksum" ]; then
# OLD=$(cat _settings.chksum)
# if [[ "$CFG_HASH" == "$OLD" ]]; then
# CLEAN=0
# fi
#fi
#echo $CFG_HASH > _settings.chksum
#
#if [ -f "build" ]; then
# if (( $CLEAN == 1 )); then
# echo "# completely re-building"
# rm -r build
# fi
#fi

FILES="ir/*.c common/*.c ir/opt/*.c ir/transform/*.c cg/x86_stupid/*.c"

Expand All @@ -12,7 +43,7 @@ FILES="ir/*.c common/*.c ir/opt/*.c ir/transform/*.c cg/x86_stupid/*.c"
function prepare() {
if [ -z $python ]; then
echo \# detecting python...
if venv/bin/python3 --help &>/dev/null; then
if venv/bin/python3 --help &>/dev/null; then
python=venv/bin/python3
elif venv/Scripts/python --help &>/dev/null; then
python=venv/Scripts/python
Expand All @@ -21,13 +52,14 @@ function prepare() {
elif python3 --help &>/dev/null; then
python=python3
else
echo "python not found! tried \"python\" and \"python3\"! Set \"python\" variable or install python!"
echo "python not found! tried \"python\" and \"python3\"! Set \"python\" variable or install python!"
exit 1
fi
fi
echo "found python at: $python"
echo "# found python at: $python"
$python -m pip install generic-lexer &>/dev/null
$CC build.c -lpthread -DVERBOSE=1 -DPYTHON="\"$python\"" -DCC="\"$CC\"" -o build.exe
echo "# pip generic-lexer installed"
$BUILD_CC build.c -lpthread -DVERBOSE=1 -DPYTHON="\"$python\"" -DCC="\"$CC\"" -DCC_ARGS="\"$CFLAGS\"" -DAR="\"$AR\"" -o build.exe
echo "# build.exe compiled"
echo "# gen cdef files"
./build.exe gen
Expand All @@ -37,12 +69,12 @@ if [[ $1 == "analyze" ]]; then
echo "# analyzing..."
prepare
echo "# starting analyzer"
clang --analyze -Xclang -analyzer-werror $CFLAGS $FILES
clang --analyze -Xclang -analyzer-werror $ANALYZER_FLAGS $FILES
elif [[ $1 == "ganalyze" ]]; then
echo "analyzing (gcc) ..."
prepare
echo "# starting analyzer (gcc)"
gcc -fanalyzer -fsanitize-trap=undefined $CFLAGS $FILES
gcc -fanalyzer -fsanitize-trap=undefined $ANALYZER_FLAGS $FILES
elif [[ $1 == "info" ]]; then
echo clang:
clang --version
Expand All @@ -53,12 +85,14 @@ elif [[ $1 == "info" ]]; then
echo cc:
"$CC" --version
elif [[ $1 == "build" ]]; then
echo "compile Debug"
prepare
echo "# compile Debug"
prepare
echo "# lib.a"
./build.exe lib.a
./build.exe lib.a
else
echo "invalid arguments; usage: ./build.sh [ganalyze|analyze|build]"
echo "you can set CC, CFLAGS, BUILD_CC, python, EX_CFLAGS, AR"
echo "if you set EMPATH, these flags get added automatically (you can overwrite them manually): CC=\$EMPATH/emcc BUILD_CC=clang EX_CFLAGS="-O3" AR=\$EMPATH/emar"
fi

# shellcheck enable=SC2086

0 comments on commit 41b225c

Please sign in to comment.