aboutsummaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh98
1 files changed, 49 insertions, 49 deletions
diff --git a/build.sh b/build.sh
index cac8275..26edf31 100755
--- a/build.sh
+++ b/build.sh
@@ -4,48 +4,45 @@ set -e
this_script_path=$(readlink -f "$0")
this_script_dir=$(dirname "$this_script_path")
-source_files=$(readlink -f $(find "$this_script_dir/src" -name "*.c"))
+cd "$this_script_dir"
+source_files=$(find "src" -name "*.c")
+
+cpu_arch="$ARCH"
+if [ -z "$ARCH" ]; then
+ cpu_arch=$(uname -m)
+ echo "Cpu architecture detected: $cpu_arch." 'You can override the architecture with the environment variable $ARCH'
+fi
+
+if [ "$cpu_arch" = "x86_64" ]; then
+ source_files="$source_files $(find "executor/x86_64" -name "*.c")"
+else
+ echo "WARNING: There is no machine code implementation for your cpu architecture: $cpu_arch. An interpreter will be used instead"
+fi
if [ -z "$CC" ]; then
CC=cc
fi
-CFLAGS="-Wall -Wextra -Werror -Wno-format-security -Wnull-dereference -std=c89 -D_GNU_SOURCE "
+CFLAGS="-Wall -Wextra -Werror -Wno-format-security -Wno-error=attributes -Wno-attributes -Wnull-dereference -std=c89 -D_GNU_SOURCE"
LIBS="-pthread "
-if [ ! -z "$SANITIZE_ADDRESS" ]; then
- CFLAGS+="-fsanitize=address "
-elif [ ! -z "$SANITIZE_THREAD" ]; then
- CFLAGS+="-fsanitize=thread "
+if [ -n "$SANITIZE_ADDRESS" ]; then
+ CFLAGS="$CFLAGS -fsanitize=address "
+elif [ -n "$SANITIZE_THREAD" ]; then
+ CFLAGS="$CFLAGS -fsanitize=thread "
fi
-if [ ! -z "$PEDANTIC" ]; then
- CFLAGS+="-DAMAL_PEDANTIC -pedantic "
+if [ -n "$PEDANTIC" ]; then
+ CFLAGS="$CFLAGS -DAMAL_PEDANTIC -pedantic "
fi
-build_test() {
- CFLAGS+="-g -O0 -DDEBUG"
-
- BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o "$this_script_dir/libamalgam.so""
- set -x
- time $CC $BUILD_ARGS
- if [ ! -z "$SCAN_BUILD" ]; then
- scan-build $CC $BUILD_ARGS
- fi
- set +x
-
- if [ -z "$NO_TEST" ]; then
- source_files_tests=$(readlink -f $(find "$this_script_dir/tests" -name "*.c"))
- set -x
- time $CC $source_files_tests $CFLAGS $LIBS -o test "$this_script_dir/libamalgam.so"
- fi
-
+build_compile_commands() {
set +x
compile_commands=$(
first=0
echo "["
- for source_file in $source_files $source_files_tests; do
- if [ $first == 1 ]; then
+ for source_file in $@; do
+ if [ $first = 1 ]; then
echo " ,"
fi
first=1
@@ -57,38 +54,41 @@ build_test() {
echo " }"
done
echo "]")
- echo "$compile_commands" > "$this_script_dir/compile_commands.json"
+ echo "$compile_commands" > "compile_commands.json"
}
-build_release() {
- CFLAGS+="-O2 -DNDEBUG -s"
+build_test() {
+ CFLAGS="$CFLAGS -g -O0 -DDEBUG"
- BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o "$this_script_dir/libamalgam.so""
+ BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o libamalgam.so"
set -x
time $CC $BUILD_ARGS
- if [ ! -z "$SCAN_BUILD" ]; then
+ if [ -n "$SCAN_BUILD" ]; then
scan-build $CC $BUILD_ARGS
fi
set +x
+ source_files_test=$(find "tests" -name "*.c")
+ if [ -z "$NO_TEST" ]; then
+ set -x
+ time $CC $source_files_test $CFLAGS $LIBS -o test "./libamalgam.so"
+ fi
+
+ build_compile_commands $source_files $source_files_test
+}
+
+build_release() {
+ CFLAGS="$CFLAGS -O2 -DNDEBUG -s"
+
+ BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o libamalgam.so"
+ set -x
+ time $CC $BUILD_ARGS
+ if [ -n "$SCAN_BUILD" ]; then
+ scan-build $CC $BUILD_ARGS
+ fi
set +x
- compile_commands=$(
- first=0
- echo "["
- for source_file in $source_files; do
- if [ $first == 1 ]; then
- echo " ,"
- fi
- first=1
- o_file="${source_file}.o"
- echo " {"
- echo " \"file\": \"$source_file\","
- echo " \"directory\": \"$this_script_dir\","
- echo " \"command\": \"$CC -o $o_file $CFLAGS $LIBS -c $source_file\""
- echo " }"
- done
- echo "]")
- echo "$compile_commands" > "$this_script_dir/compile_commands.json"
+
+ build_compile_commands $source_files
}
case "$1" in