diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +* diff --git a/.gitignore b/.gitignore index 7dca835..8e32da8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/dist/ +/build/ .sconsign.dblite diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6414dec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM debian:bookworm + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y \ + clang \ + llvm \ + scons + +RUN useradd rt +USER rt diff --git a/SConscript b/SConscript deleted file mode 100644 index 4cd423c..0000000 --- a/SConscript +++ /dev/null @@ -1,64 +0,0 @@ -import os -import sys - -llvm_flags = [ - "-g", - "-Os", - "-ffunction-sections", - "-fdata-sections", - "-flto", - ] - -env = Environment( - CPPPATH=["include"], - CCFLAGS=llvm_flags, - CFLAGS=["-std=c99"], - LINKFLAGS=llvm_flags, -) - -# for color terminal output when available -if "TERM" in os.environ: - env["ENV"]["TERM"] = os.environ["TERM"] - -if "darwin" in sys.platform: - env["CC"] = "clang" - env.Append( - CCFLAGS=[ - "-Weverything", - "-Werror", - "-Wno-padded", - "-Wno-poison-system-directories", - ], - LINKFLAGS=["-dead_strip"], - ) -elif "linux" in sys.platform: - env["CC"] = "gcc" - env.Append(CPPDEFINES=[("_POSIX_C_SOURCE", "200809L")]) - env.Append(LINKFLAGS=["-Wl,--gc-sections"]) - -librt = env.StaticLibrary( - target="rt", - source=[ - "src/rt.c", - "src/tick.c", - "src/critical.c", - "src/delay.c", - "src/queue.c", - "src/sem.c", - ], -) - -posix_env = env.Clone() -posix_env.Append( - CCFLAGS="-pthread", - LINKFLAGS="-pthread", -) - -posix_port = posix_env.Object("src/port/posix.c") - -posix_simple = posix_env.Object(target="posix_simple", source="examples/simple.c") -posix_delay = posix_env.Object(target="posix_delay", source="examples/delay.c") -posix_queue = posix_env.Object(target="posix_queue", source="examples/queue.c") -posix_env.Program([posix_simple, librt, posix_port]) -posix_env.Program([posix_delay, librt, posix_port]) -posix_env.Program([posix_queue, librt, posix_port]) diff --git a/SConstruct b/SConstruct index 231b0c2..6a2bbb5 100644 --- a/SConstruct +++ b/SConstruct @@ -1,5 +1,66 @@ -SConscript( - dirs=".", - variant_dir="dist", - duplicate=False, +import os +import sys + +llvm_flags = [ + "-g", + "-Os", + "-ffunction-sections", + "-fdata-sections", + "-flto", +] + +env = Environment( + CPPPATH=[Dir("include").srcnode()], + CCFLAGS=llvm_flags, + CFLAGS=["-std=c99"], + LINKFLAGS=llvm_flags, +) + +# for color terminal output when available +if "TERM" in os.environ: + env["ENV"]["TERM"] = os.environ["TERM"] + +env["CC"] = "clang" +env.Append( + CCFLAGS=[ + "-Weverything", + "-Werror", + "-Wno-padded", + "-Wno-poison-system-directories", + "-Wno-declaration-after-statement", + "-Wno-disabled-macro-expansion", + ], +) + +if "darwin" in sys.platform: + env.Append( + LINKFLAGS=["-dead_strip"], + ) +elif "linux" in sys.platform: + env.Append( + CPPDEFINES={"_POSIX_C_SOURCE": "200809L"}, LINKFLAGS=["-Wl,--gc-sections"] + ) + +librt = SConscript( + dirs="src", variant_dir="build/lib", duplicate=False, exports=["env"] +) + +posix_env = env.Clone() +posix_env.Append( + CCFLAGS="-pthread", + LINKFLAGS="-pthread", +) + +libposix = SConscript( + "arch/posix/SConscript", + variant_dir="build/lib/posix", + duplicate=False, + exports={"env": posix_env}, +) + +example_env = posix_env.Clone() +example_env.Append(LIBS=[librt, libposix]) + +SConscript( + dirs="examples", variant_dir="build", duplicate=False, exports={"env": example_env} ) diff --git a/arch/posix/SConscript b/arch/posix/SConscript new file mode 100644 index 0000000..df004a6 --- /dev/null +++ b/arch/posix/SConscript @@ -0,0 +1,5 @@ +Import("env") + +libposix = env.StaticLibrary("posix.c") + +Return("libposix") diff --git a/src/port/posix.c b/arch/posix/posix.c similarity index 100% rename from src/port/posix.c rename to arch/posix/posix.c diff --git a/docker.bash b/docker.bash new file mode 100755 index 0000000..c1e1c78 --- /dev/null +++ b/docker.bash @@ -0,0 +1,19 @@ +#!/bin/bash + +set -xe + +name="rt" +image="$name-builder" + +docker build --tag "$image" . + +workdir="/home/$name/$name" + +docker run \ + --rm \ + --tty \ + --interactive \ + --volume "$(pwd):$workdir" \ + --workdir "$workdir" \ + --cap-add SYS_PTRACE \ + "$image" diff --git a/examples/SConscript b/examples/SConscript new file mode 100644 index 0000000..2358e0a --- /dev/null +++ b/examples/SConscript @@ -0,0 +1,5 @@ +Import("env") + +env.Program("simple.c") +env.Program("delay.c") +env.Program("queue.c") diff --git a/src/SConscript b/src/SConscript new file mode 100644 index 0000000..239e30e --- /dev/null +++ b/src/SConscript @@ -0,0 +1,15 @@ +Import("env") + +librt = env.StaticLibrary( + target="rt", + source=[ + "rt.c", + "tick.c", + "critical.c", + "delay.c", + "queue.c", + "sem.c", + ], +) + +Return("librt") diff --git a/src/tick.c b/src/tick.c index 729f7da..fad5d53 100644 --- a/src/tick.c +++ b/src/tick.c @@ -9,7 +9,7 @@ static rt_tick_t rt_ticks; void rt_tick(void) { ++rt_ticks; -#if RT_LOG +#ifdef RT_LOG printf("tick %lu\n", rt_ticks); fflush(stdout); #endif