From 3b48433ec910b0b21cbc86ce7ca9dff5d62ca22f Mon Sep 17 00:00:00 2001 From: Wesley Irvin Date: Sun, 4 Feb 2024 13:17:57 -0500 Subject: [PATCH] First build system First draft of a build system. This will run the hello function from our library. --- .gitignore | 2 ++ build-all.sh | 29 +++++++++++++++++++++++++++++ quantum/build.sh | 23 +++++++++++++++++++++++ quantum/src/test.c | 5 +++++ quantum/src/test.h | 1 + test_stuff/build.sh | 15 +++++++++++++++ test_stuff/src/main.c | 7 +++++++ 7 files changed, 82 insertions(+) create mode 100755 build-all.sh create mode 100755 quantum/build.sh create mode 100644 quantum/src/test.c create mode 100644 quantum/src/test.h create mode 100755 test_stuff/build.sh create mode 100644 test_stuff/src/main.c diff --git a/.gitignore b/.gitignore index cd531cf..a9c7abd 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ Module.symvers Mkfile.old dkms.conf +# Ignore /bin directory +/bin diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..04b478f --- /dev/null +++ b/build-all.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Build script to build everything + +set echo on + +mkdir -p bin/ + +echo "Building all.." + +pushd quantum +source build.sh +popd + +ERRORLEVEL=$? +if [ $ERRORLEVEL -ne 0 ]; then + echo "Error:"$ERRORLEVEL && exit +fi + +pushd test_stuff +source build.sh +popd + +ERRORLEVEL=$? +if [ $ERRORLEVEL -ne 0 ]; then + echo "Error:"$ERRORLEVEL && exit +fi + +echo "All assemblies built successfully!!!!" diff --git a/quantum/build.sh b/quantum/build.sh new file mode 100755 index 0000000..2a8ec71 --- /dev/null +++ b/quantum/build.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Build script for quantum + +set echo on + +mkdir -p build/ + +# Get a list of all the .c files. +cFilenames=$(find . -type f -name "*.c") + +assembly="quantum" +objLocation="build/libquantum.o" +compilerFlags="-g -c -fpic" +includeFlags="-Isrc" + +echo "Building $assembly..." + +# First we need to compile down to .o files +gcc $cFilenames $compilerFlags -o $objLocation $includeFlags + +compilerFlags="-g -shared" +gcc $objLocation $compilerFlags -o ../bin/libquantum.so $includeFlags diff --git a/quantum/src/test.c b/quantum/src/test.c new file mode 100644 index 0000000..aa57d7b --- /dev/null +++ b/quantum/src/test.c @@ -0,0 +1,5 @@ +#include + +#include "test.h" + +void hello_quantum() { printf("Hello from Quantum!\n"); } diff --git a/quantum/src/test.h b/quantum/src/test.h new file mode 100644 index 0000000..db254d7 --- /dev/null +++ b/quantum/src/test.h @@ -0,0 +1 @@ +void hello_quantum(); diff --git a/test_stuff/build.sh b/test_stuff/build.sh new file mode 100755 index 0000000..6241524 --- /dev/null +++ b/test_stuff/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash +#Build script for test_stuff + +set echo on + +# Get a list of all the .c files. +cFilenames=$(find . -type f -name "*.c") + +assembly="test_stuff" +compilerFlags="-g -fpic" +includeFlags="-Isrc -I../quantum/src/" +linkerFlags="-L../bin/ -lquantum -Wl,-rpath,." + +echo "Building $assembly..." +gcc $cFilenames $compilerFlags -o ../bin/$assembly $includeFlags $linkerFlags diff --git a/test_stuff/src/main.c b/test_stuff/src/main.c new file mode 100644 index 0000000..c3564fa --- /dev/null +++ b/test_stuff/src/main.c @@ -0,0 +1,7 @@ +#include + +int main() { + hello_quantum(); + + return 0; +}