From: Thomas Walker Lynch Date: Mon, 9 Mar 2026 14:41:30 +0000 (+0000) Subject: using simplified C gating for new Example X-Git-Url: https://git.reasoningtechnology.com/%5B%5E?a=commitdiff_plain;h=096b5ce7d36655fc96fdb9d6bfa1205545be3762;p=Harmony using simplified C gating for new Example --- diff --git a/developer/authored/greeter.lib.c b/developer/authored/greeter.lib.c new file mode 100644 index 0000000..b7be528 --- /dev/null +++ b/developer/authored/greeter.lib.c @@ -0,0 +1,26 @@ +#ifndef GREETER_LIB_C +#define GREETER_LIB_C +#ifndef FACE + #define GREETER_IMPL +#endif + +#define FACE +#include "math.lib.c" +#undef FACE + +void Greet·hello_loop(int count); + +#ifdef GREETER_IMPL + +#include + +void Greet·hello_loop(int count){ + for(int TM = 0; TM < count; ++TM){ + int current_count = Math·add(TM ,1); + printf("Hello iteration: %d\n" ,current_count); + } +} + +#endif // GREETER_IMPL +#endif // GREETER_LIB_C + diff --git a/developer/authored/hello.CLI.c b/developer/authored/hello.CLI.c index a626cac..d498dbf 100644 --- a/developer/authored/hello.CLI.c +++ b/developer/authored/hello.CLI.c @@ -1,2 +1,22 @@ +#include #include -int main(void){ puts("hello from Rabbit CLI"); return 0; } + +#define FACE +#include "math.lib.c" +#include "greeter.lib.c" +#undef FACE + +void CLI(void){ + int base_count = Math·add(1 ,2); + printf("Calculated base loop count: %d\n" ,base_count); + Greet·hello_loop(base_count); +} + +int main(int argc ,char **argv){ + (void)argc; + (void)argv; + + CLI(); + + return EXIT_SUCCESS; +} diff --git a/developer/authored/math.lib.c b/developer/authored/math.lib.c new file mode 100644 index 0000000..6256c7c --- /dev/null +++ b/developer/authored/math.lib.c @@ -0,0 +1,17 @@ +#ifndef MATH_LIB_C +#define MATH_LIB_C + +#ifndef FACE + #define MATH_IMPL +#endif + +int Math·add(int a ,int b); + +#ifdef MATH_IMPL + +int Math·add(int a ,int b){ + return a + b; +} + +#endif // MATH_IMPL +#endif // MATH_LIB_C diff --git a/developer/tool/make b/developer/tool/make index 853149a..740321f 100755 --- a/developer/tool/make +++ b/developer/tool/make @@ -12,7 +12,7 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") set -e set -x - cd "$REPO_HOME"/developer || exit 1 + cd "$REPO_HOME/developer" || exit 1 /bin/make -f tool/makefile $@ set +x diff --git a/developer/tool/makefile b/developer/tool/makefile index 8eaf73c..2d5d057 100644 --- a/developer/tool/makefile +++ b/developer/tool/makefile @@ -3,7 +3,7 @@ .EXPORT_ALL_VARIABLES: RT_MAKEFILE_DP := $(REPO_HOME)/shared/tool/makefile -include $(RT_MAKEFILE_DP)/environment_RT_1.mk +include $(RT_MAKEFILE_DP)/Harmony.mk .PHONY: usage usage: diff --git a/shared/tool/makefile/Harmony.mk b/shared/tool/makefile/Harmony.mk new file mode 100644 index 0000000..da5efc6 --- /dev/null +++ b/shared/tool/makefile/Harmony.mk @@ -0,0 +1,35 @@ +# tool/shared/Harmony.mk +# makefile environment variable defaults. +# cc is the name of the C compiler, a file called .c is C source code. +# RT uses header integrated C source files, i.e. the source and the header are the same file + +SHELL=/bin/bash + +ECHO := printf "%b\n" + +C_SOURCE_DIR ?= authored +C ?= gcc +CFLAGS ?= -std=gnu11 -Wall -Wextra -Wpedantic -finput-charset=UTF-8 +CFLAGS += -MMD -MP +CFLAGS += -include "$(REPO_HOME)/shared/tool/makefile/RT_global.h" +CFLAGS += -I $(C_SOURCE_DIR) + + +# Project administrators can override this in their local makefile +LIBRARY_NAME ?= $(PROJECT) +LIBRARY_NAME := $(subst -,_,$(LIBRARY_NAME)) + +BUILD_DIR ?= scratchpad/build +OBJECT_DIR ?= $(BUILD_DIR)/object +LIBRARY_DIR ?= scratchpad/made +MACHINE_DIR ?= scratchpad/made + +LIBRARY_FILE ?= $(LIBRARY_DIR)/lib$(LIBRARY_NAME).a + +LN_FLAGS ?= -L$(LIBRARY_DIR) -L/lib64 -L/lib -l$(LIBRARY_NAME) + +KMOD_SOURCE_DIR ?= authored +KMOD_CCFLAGS ?= -I $(KMOD_SOURCE_DIR) +# Pass the global header to Kbuild exactly as done for user-space +KMOD_CCFLAGS += -include $(REPO_HOME)/shared/tool/makefile/RT_global.h +KMOD_OUTPUT_DIR ?= scratchpad/kmod diff --git a/shared/tool/makefile/RT_0.h b/shared/tool/makefile/RT_0.h deleted file mode 100644 index e102a5c..0000000 --- a/shared/tool/makefile/RT_0.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef RT·ENVIRONMENT_H -#define RT·ENVIRONMENT_H - #include - #include - - typedef unsigned int uint; - - #define Local static - #define Free(pt) free(pt); (pt) = NULL; - -#endif diff --git a/shared/tool/makefile/RT_global.h b/shared/tool/makefile/RT_global.h new file mode 100644 index 0000000..29f2e63 --- /dev/null +++ b/shared/tool/makefile/RT_global.h @@ -0,0 +1,11 @@ +#ifndef RT_global_H +#define RT_global_H + #include + #include + + typedef unsigned int uint; + + #define Local static + #define Free(pt) free(pt); (pt) = NULL; + +#endif diff --git a/shared/tool/makefile/environment_RT_1.mk b/shared/tool/makefile/environment_RT_1.mk deleted file mode 100644 index 0f23127..0000000 --- a/shared/tool/makefile/environment_RT_1.mk +++ /dev/null @@ -1,30 +0,0 @@ -# enviroment_RT_1.mk -# makefile environment variable defaults. -# cc is the name of the C compiler, a file called .c is C source code. -# RT uses header integrated C source files, i.e. the source and the header are the same file - -SHELL=/bin/bash - -# environment_RT_1.mk - -ECHO := printf "%b\n" - -C_SOURCE_DIR := authored -C := gcc -CFLAGS := -std=gnu11 -Wall -Wextra -Wpedantic -finput-charset=UTF-8 -CFLAGS += -MMD -MP -CFLAGS += -I $(C_SOURCE_DIR) - -LIBRARY_NAME := $(PROJECT) -LIBRARY_NAME := $(subst -,_,$(LIBRARY_NAME)) - -LIBRARY_DIR := scratchpad -LIBRARY_FILE := $(LIBRARY_DIR)/lib$(LIBRARY_NAME).a - -LN_FLAGS := -L$(LIBRARY_DIR) -L/lib64 -L/lib - -MACHINE_DIR := scratchpad/made - -KMOD_SOURCE_DIR := cc -KMOD_CCFLAGS := -I $(KMOD_SOURCE_DIR) -KMOD_OUTPUT_DIR := scratchpad/kmod diff --git a/shared/tool/makefile/target_library_CLI.mk b/shared/tool/makefile/target_library_CLI.mk index 8cf8346..2d28b76 100644 --- a/shared/tool/makefile/target_library_CLI.mk +++ b/shared/tool/makefile/target_library_CLI.mk @@ -8,14 +8,13 @@ #-------------------------------------------------------------------------------- # defaults for environment variables -C ?= gcc -CFLAGS ?= -C_SOURCE_DIR ?= cc -BUILD_DIR ?= scratchpad/build -LIBRARY_FILE ?= $(BUILD_DIR)/made/lib$(PROJECT).a -MACHINE_DIR ?= $(BUILD_DIR)/made -OBJECT_DIR ?= $(BUILD_DIR)/object -LN_FLAGS ?= +C ?= cc +CFLAGS ?= -O2 -Wall -Wextra -pedantic +C_SOURCE_DIR ?= src +OBJECT_DIR ?= obj +LIBRARY_DIR ?= lib +MACHINE_DIR ?= bin +LN_FLAGS ?= -L$(LIBRARY_DIR) -L/usr/local/lib -L/usr/lib #-------------------------------------------------------------------------------- # derived variables