]> git.leonardobizzoni.com Git - 8086-decoder/commitdiff
Initial commit
authorLeonardoBizzoni <71130040+LeonardoBizzoni@users.noreply.github.com>
Fri, 16 May 2025 08:38:26 +0000 (10:38 +0200)
committerGitHub <noreply@github.com>
Fri, 16 May 2025 08:38:26 +0000 (10:38 +0200)
.envrc [new file with mode: 0644]
.gitmodules [new file with mode: 0644]
build.sh [new file with mode: 0755]
src/base [new submodule]
src/main.c [new file with mode: 0644]

diff --git a/.envrc b/.envrc
new file mode 100644 (file)
index 0000000..0a722d7
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use nix;
diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..15d12a3
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "src/base"]
+       path = src/base
+       url = git@github.com:LeonardoBizzoni/CSTD.git
diff --git a/build.sh b/build.sh
new file mode 100755 (executable)
index 0000000..8aff95a
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,161 @@
+#!/usr/bin/env bash
+cd "$(dirname "$0")"
+set -eu
+
+file="main.c"
+
+for arg in "$@"; do
+    if [[ $arg == *=* ]]; then
+        var="${arg%%=*}"
+        val="${arg#*=}"
+        declare "$var"="$val"
+    else
+        declare $arg='1'
+    fi
+done
+
+common_link="-lpthread -lm"
+common_flags="-pedantic -Wall -Wno-unused-function -Wno-gnu-anonymous-struct -Wno-nested-anon-types"
+common_cpp="-std=c++23 -fno-exceptions"
+common_gui="-DOS_GUI=1"
+
+common_opt="-O3 -s"
+common_dbg="-O0 -g3 -fvisibility=hidden -DENABLE_ASSERT=1 -DDEBUG=1"
+
+lnx_dbg="-ggdb -fsanitize=address,undefined"
+bsd_dbg="-ggdb"
+
+if [ ! -v release ]; then debug=1; fi
+
+if [ -v cross ]; then
+    case "${cross,,}" in
+        "atmega328p")
+            compiler=$([ -v cpp ] && echo "avr-g++" || echo "avr-gcc")
+            if [ ! -v clock ]; then clock=16000000; fi
+            flags="-Os -ffunction-sections -fdata-sections -mmcu=$cross -DF_CPU=$clock "
+
+            printf "+ [ AVR "
+            if [ -v cpp ]; then
+                flags+=$common_cpp
+                printf "C++ "
+            else
+                printf "C "
+            fi
+            printf "compilation ]\n"
+            [ -v debug ] && echo "+ [ debug mode ]" || echo "+ [ release mode ]"
+
+            (
+                set -x
+                $compiler $flags -c $file -o main.out
+                $compiler $flags main.out -o main.elf
+                avr-objcopy -O ihex -R .eeprom main.elf main.ihex
+            )
+            if [ ! -v noflash ]; then
+                if [ ! -v device ]; then
+                    echo "You didn't provide a device with \`device=/dev/something\`"
+                    exit -1
+                fi
+                (
+                    set -x
+                    sudo avrdude -F -V -c arduino -p atmega328p -P $device \
+                         -b 115200 -U flash:w:main.ihex
+                )
+            fi
+            ;;
+        "cortex-m7")
+            compiler=$([ -v cpp ] && echo "arm-none-eabi-g++" || echo "arm-none-eabi-gcc")
+
+            printf "+ [ ARM-NONE "
+            if [ -v cpp ]; then
+                flags+=$common_cpp
+                printf "C++ "
+            else
+                printf "C "
+            fi
+            printf "compilation ]\n"
+            [ -v debug ] && echo "+ [ debug mode ]" || echo "+ [ release mode ]"
+
+            (
+                set -x
+                $compiler $file -T stm32_linker.ld -o main.elf -mcpu=cortex-m7 -mthumb -nostdlib
+            )
+            if [ ! -v noflash ]; then
+                if [ ! -v device ]; then
+                    echo "You didn't provide a device with \`device=/dev/something\`"
+                    exit -1
+                fi
+                (
+                    set -x
+                )
+            fi
+            ;;
+        *)
+            exit -1
+            ;;
+    esac
+else
+    if [ ! -v gcc ]; then clang=1; fi
+
+    if [ -v gcc ];   then compiler=$([ -v cpp ] && echo "g++" || echo "gcc");         fi
+    if [ -v clang ]; then compiler=$([ -v cpp ] && echo "clang++" || echo "clang");   fi
+
+    case "$(uname)" in
+        "Linux")
+            os="LNX"
+            if [ -v gui ]; then
+                display_server=$(echo "$XDG_SESSION_TYPE")
+            fi
+            ;;
+        *BSD*)
+            os="BSD"
+            if [ -v gui ]; then
+                display_server=$(echo "$XDG_SESSION_TYPE")
+            fi
+            ;;
+        "Darwin")
+            os="MACOS"
+            ;;
+        *)
+            exit -1
+            ;;
+    esac
+
+    flags="$common_flags $common_link "
+    if [ -v cpp ]; then flags+="$common_cpp "; fi
+
+    if [ -v debug ]; then
+        flags+="$common_dbg "
+        if [ "$os" == "LNX" ]; then
+            flags+="$lnx_dbg "
+        elif [ "$os" == "BSD" ]; then
+            flags+="$bsd_dbg "
+        elif [ "$os" == "MACOS" ]; then
+            flags+="$macos_dbg "
+        fi
+    else
+        flags+="$common_opt "
+    fi
+
+    if [ -v gui ]; then
+        flags+="$common_gui "
+        if [[ $os == "LNX" || $os == "BSD" ]]; then
+            if [ "$display_server" == "x11" ]; then
+                flags+="-D${os}_X11=1 -lX11 -lXext "
+            else
+                flags+="-D${os}_Wayland=1 "
+            fi
+        fi
+
+        if [ -v opengl ]; then
+            flags+="-lGL -lGLU -DUSING_OPENGL=1 "
+        fi
+    fi
+
+    if   [ -v gcc ];   then printf "+ [ GNU "
+    elif [ -v clang ]; then printf "+ [ Clang "
+    fi
+
+    [ -v cpp ] && printf "C++ " || printf "C "; printf "compilation ]\n"
+    [ -v debug ] && echo "+ [ debug mode ]" || echo "+ [ release mode ]"
+    (set -x; $compiler $flags $file -o main)
+fi
diff --git a/src/base b/src/base
new file mode 160000 (submodule)
index 0000000..176c61f
--- /dev/null
+++ b/src/base
@@ -0,0 +1 @@
+Subproject commit 176c61f2d310b18f4f1719d494c6cb3eccc26555
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..0596888
--- /dev/null
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+#include <base/base_inc.h>
+#include <OS/os_inc.h>
+
+#include <base/base_inc.c>
+#include <OS/os_inc.c>
+
+fn void start(CmdLine *cli) {
+#if 1
+  printf("Compiler GCC:   %d\n", COMPILER_GCC);
+  printf("Compiler CL:    %d\n", COMPILER_CL);
+  printf("Compiler CLANG: %d\n", COMPILER_CLANG);
+
+  printf("OS GNU/Linux:   %d\n", OS_LINUX);
+  printf("OS BSD:         %d\n", OS_BSD);
+  printf("OS MAC:         %d\n", OS_MAC);
+  printf("OS Windows:     %d\n", OS_WINDOWS);
+
+  printf("Architecture x86 32bit: %d\n", ARCH_X86);
+  printf("Architecture x64 64bit: %d\n", ARCH_X64);
+  printf("Architecture ARM 32bit: %d\n", ARCH_ARM);
+  printf("Architecture ARM 64bit: %d\n", ARCH_ARM64);
+#endif
+
+}