From: Thomas Walker Lynch Date: Mon, 9 Mar 2026 04:05:09 +0000 (+0000) Subject: doc tweaks, make work X-Git-Url: https://git.reasoningtechnology.com/%5B%5E?a=commitdiff_plain;h=7977d9ef43b2bf27813e2ecb855216bb8708ef79;p=Harmony doc tweaks, make work --- diff --git a/developer/document/.gitkeep b/developer/document/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/developer/document/02_RT_Code_Format.html b/developer/document/02_RT_Code_Format.html deleted file mode 100644 index 45a471d..0000000 --- a/developer/document/02_RT_Code_Format.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - RT Prescriptive Code Format Guide - - - - - - - - - - -

Object vs. Instance Nomenclature

-

- We reserve the word 'object' for its general English meaning. When discussing data that is manipulated solely through a defined interface, use the term instance. -

- -

Identifier Naming Conventions

- - -

Proper Nouns and Acronyms

-

- Even in PascalCase and snake_case, proper nouns and acronyms remain capitalized, as per standard English language conventions (e.g., IEEE_publication_count). -

- -

Expanded Suffix Semantics

-

Add a container or type suffix instead of making variable names plural. Never use plurals.

- - -

Primary and Secondary Separators (snake-kebab_case)

-

- If a language supports the hyphen (-) in identifiers (such as Common Lisp and Emacs Lisp), the identifier is written in snake-kebab_case. The hyphen is used as the primary word separator. The underscore (_) is then used as a secondary separator to denote logically related portions or namespace boundaries within the identifier. -

-

- Otherwise, if the language does not support hyphens in identifiers (such as C, Python, and Java), the identifier falls back to standard snake_case and only the underscore (_) is used for all separation. In C specifically, a center dot (·) is used for ad hoc namespaces. -

- -

Comma Separated Lists

- -

Horizontal Comma List

-

The comma is preceded by a space and abuts the item it follows.

- - int x ,y ,z; - - -

Vertical Comma List

-

The comma is placed before the item on the new line, aligned with the item's indentation.

- - result = some_function( - first_argument - ,second_argument - ,third_argument - ); - - -

Enclosure Spacing

- -

Single-Level Enclosures

-

No space padding inside the enclosure punctuation.

- - if(condition){ - do_something(); - } - - -

Multi-Level Enclosures

-

One space of padding is applied only to the outermost enclosure punctuation.

- - if( f(g(x)) ){ - do_something(); - } - - -

Short Stuff Rule

-

If a statement can fit on a single line and is short, keep it on a single line without braces.

- - if(x == 0) return; - - -

Indentation

- - -

Example: The CLI Pattern

-

Here is an example demonstrating the separation of work logic from the command line interface.

- - def calculate_area(length ,width): - # The Work Function. Pure logic. Reusable by any other module. - return length * width - - def CLI(): - # The Command Line Interface. Parses strings, calls work, handles output. - import sys - - if len(sys.argv) < 3: - print("Usage: ./area.py ") - sys.exit(1) - - # Parse Strings -> Native Types - l = int(sys.argv[1]) - w = int(sys.argv[2]) - - # Invoke Work - result = calculate_area(l ,w) - - # Output - print(f"Area: {result}") - - if __name__ == "__main__": - CLI() - - -

The CLI vs. Work Function Pattern

-

- To avoid the "String Trap"—where logic is tightly coupled to the terminal and requires string serialization to reuse—executable modules must separate the Command Line Interface from the core logic. -

- -

When a module is executed directly, the only top-level action should be calling CLI().

- -

Exercises

-

To ensure a full understanding of the RT code format, please complete the following exercises.

- - -

Exercise 1: Comma and Function Call Formatting

-

Reformat the following C code snippet to strictly adhere to the RT code format rules. Pay close attention to the horizontal and vertical comma lists, and the enclosure spacing for the function call.

- - void my_function(int a, int b, int c) { - int result = calculate_value(a, b, c); - printf("Result: %d, a: %d, b: %d, c: %d\n", result, a, b, c); - } - - result = my_function( - rediculously_long_first_argument, - rediculously_long_second_argument, - rediculously_long_third_argument - ); - - -

Exercise 2: Multi-Level Enclosure and Short Stuff Rule

-

Reformat the following C code snippet. The if statement should use the multi-level enclosure rule, and the for loop body should use the short stuff rule.

- - if (check_permissions(user_id, file_path) && is_valid(file_path)) { - for (int i = 0; i < 10; i++) { - if (i % 2 == 0) { - printf("Even: %d\n", i); - } - } - } - - -
- - diff --git a/developer/document/03_Naming_and_Directory_Conventions.html b/developer/document/03_Naming_and_Directory_Conventions.html deleted file mode 100644 index b90203f..0000000 --- a/developer/document/03_Naming_and_Directory_Conventions.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - Naming and Directory Conventions - - - - - - - - -

- A directory name is taken as a property for a set of files. Consequently, directory names are rarely plural. For example, suppose we have a number of test files in a directory. The directory would be named test, as each file in the directory has the property of being a test. -

- -

- It would be nice if we could attach multiple properties to a file as part of the file system framework, but conventional file systems do not support this. Consequently, when needed, people add a second property to a file using dot extensions to the file's name. Hence, we get something like sqrt.c in a directory called source. The first property is that the file is source code, and the second property is that it is C code. -

- -

- We could extend the dot suffix model of adding a property to a file by using multiple dot suffixes. Our C makefile structure makes use of this. -

- -

So what is a reasonable primary property for a set of files? Perhaps:

- - -

- As for the names src and executable, those come from times when almost all programs were compiled. We prefer instead the names authored and made. authored files are those written by humans (or these days, perhaps AI), while made files are products of tools. For a Python program, we put packages in authored with a module called CLI.py for the command line interface. Then we link from made into authored so as to give the program a name. -

- -

- Hence, with the default makefile for C, compiler fodder is found in the authored/ directory. File name extensions are used to signal to the build tools how the file is to be processed: -

- - -

- The RT C coding environment does not use separate source and header files. Instead, a variable is set that gates off the implementation if the source code is to be used as a header. Hence, all of our C source fits fine within an authored directory. -

-
- - diff --git a/developer/document/04_Language_Addenda.html b/developer/document/04_Language_Addenda.html deleted file mode 100644 index d33208e..0000000 --- a/developer/document/04_Language_Addenda.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - Language Addenda (C, Python, Bash, Lisp) - - - - - - - - - - -

Purpose

-

- The RT code format is language-agnostic, but actual languages differ in syntax and constraints. This document explains how the RT rules are applied in C, Python, Bash, and Lisp dialects. -

- -

1. C Addendum

-

1.1 Control Structure and File Layout

-

- Each module has an Interface section and an Implementation section in the same file. The sections are toggled using preprocessor macros (e.g., FACE). Interface declarations are processed even when included multiple times; the implementation is compiled only when used as an implementation. -

- -

1.2 Indentation and Comma Lists

-

C code follows the RT two-space indentation and vertical comma lists:

- -result = some_function( - first_argument - ,second_argument_with_longer_name - ,third_argument -); - - -

1.3 Error Handling and Ownership

- - -

2. Python Addendum

-

2.1 Indentation and Layout

-

Python enforces indentation syntactically, so the RT two-space rule becomes:

- - -

2.2 Modules and CLI Separation

-

Python scripts distinguish between:

-
    -
  1. Work functions (importable API).
  2. -
  3. CLI entry points (argument parsing, printing, exit codes).
  4. -
-

Put argument parsing and if __name__ == "__main__": in the CLI section. Keep side effects out of import time.

- -

3. Bash Addendum

-

3.1 Shebang and Safety

-

Bash scripts should start with:

- -#!/usr/bin/env bash -set -euo pipefail - - -

3.2 Functions vs. Top-Level Code

-

RT-style Bash separates a small top-level CLI harness (argument parsing, usage, dispatch) from a set of functions that implement the work. Parse arguments into variables, call a main function with explicit parameters, and avoid relying on global mutable state where possible.

- -

4. Lisp / Emacs Lisp Addendum

-

4.1 Identifier Separators (snake-kebab_case)

-

- Because Lisp dialects support the hyphen (-) in symbols, they utilize snake-kebab_case as the standard for functions and variables. The hyphen replaces the underscore as the primary word separator. -

-

- The underscore (_) is reserved strictly as a secondary separator. It is used to group logically related portions of an identifier or to denote semantic boundaries, acting as a structural namespace within the symbol (e.g., city-scape_building-height). -

- -

4.2 Enclosures and Indentation

-

- Lisp relies entirely on parentheses for evaluation boundaries. The RT multi-level enclosure rule applies: one space of padding is applied to the outermost parentheses of an evaluated list, while inner lists receive no padding. Indentation remains strictly two spaces. -

- -

5. Using the Addenda

-

- When in doubt, start with 02_RT_Code_Format.html for the core rules, then apply the relevant language section here. If a language requires deviation from the generic rules, document that deviation in this file instead of ad-hoc decisions. -

-
- - diff --git a/developer/document/File and directory naming conventions.html b/developer/document/File and directory naming conventions.html new file mode 100644 index 0000000..afa4ad3 --- /dev/null +++ b/developer/document/File and directory naming conventions.html @@ -0,0 +1,55 @@ + + + + + File and directory naming conventions + + + + + + + + +

Case

+

+ Directory and file names follow the exact same casing rules as the identifiers they represent. Because standard file systems support the hyphen (-), file and directory names use snake-kebab_case for functions and scripts, and PascalCase for types and modules. The hyphen serves as the primary word separator, while the underscore (_) is reserved for structural or namespace boundaries. (Currently many file names use primarily `_`, but we will transition to this more uniform approach.) +

+ +

Directory properties

+

+ A directory name is taken as a property for a set of files. Consequently, directory names are rarely plural. For example, suppose we have a number of test files in a directory. The directory would be named test, as each file in the directory has the property of being a test. +

+

+ What is a reasonable primary property for a set of files? Perhaps: +

+ + +

Dot extensions as properties

+

+ We add a second property to a file using dot extensions to the file's name. We can extend the dot suffix model by using multiple dot suffixes. File name extensions are used to signal to the build tools how the file is to be processed: +

+ + +

C source file structure

+

+ The RT C coding environment does not use separate source and header files. Each module has an Interface section and an Implementation section in the same file. A preprocessor macro (e.g., FACE) is used to gate off the implementation if the source code is to be used as a header. +

+
+ + diff --git a/developer/document/RT_code_format.html b/developer/document/RT_code_format.html new file mode 100644 index 0000000..d9085a2 --- /dev/null +++ b/developer/document/RT_code_format.html @@ -0,0 +1,186 @@ + + + + + RT code format conventions + + + + + + + + + + +

Object vs. instance nomenclature

+

+ We reserve the word 'object' for its general English meaning. When discussing data that is manipulated solely through a defined interface, use the term instance. +

+ +

Identifier Names

+ +

Case

+ + +

Primary and secondary separators (snake-kebab_case)

+

+ If a language supports the hyphen (-) in identifiers (such as Common Lisp and Emacs Lisp), the identifier is written in snake-kebab_case. The hyphen is used as the primary word separator. The underscore (_) is then reserved strictly as a secondary separator to group logically related portions of an identifier or to denote semantic boundaries, acting as a structural namespace within the symbol (e.g., city-scape_building-height). +

+

+ Otherwise, if the language does not support hyphens in identifiers (such as C, Python, and Java), the identifier falls back to standard snake_case and only the underscore (_) is used for all separation. In C specifically, a center dot (·) is used for ad hoc namespaces. +

+ +

Suffixes

+ +

Add a container type suffix instead of making variable names plural.

+ + +

Add a type suffix when it adds clarity.

+ + + + +

Proper nouns and acronyms

+

+ Even in PascalCase and snake_case, proper nouns and acronyms remain capitalized, as per standard English language conventions (e.g., IEEE_publication_count). +

+ +

Comma separated lists

+ +

Horizontal comma list

+

The comma is preceded by a space and abuts the item it follows.

+ + int x ,y ,z; + + +

Vertical comma list

+

The comma is placed before the item on the new line, aligned with the item's indentation. This applies to all languages, including Python and C.

+ + result = some_function( + first_argument + ,second_argument + ,third_argument + ); + + +

Enclosure spacing

+ +

Single-level enclosures

+

No space padding inside the enclosure punctuation.

+ + if(condition){ + do_something(); + } + + +

Multi-level enclosures

+

One space of padding is applied only to the outermost enclosure punctuation.

+ + + if( f(g(x)) ){ + do_something(); + } + + +

This rule is not applied to function calls in Lisp.

+ +

Short stuff rule

+

If a statement can fit on a single line and is short, keep it on a single line without braces.

+ + if(x == 0) return; + + +

Indentation

+ +

Python enforces indentation syntactically. Use two-space indentation for all Python code, even though four is common in the wider ecosystem.

+ +

The CLI vs. work function pattern

+

+ To avoid the "String Trap" — where logic is tightly coupled to the terminal and requires string serialization to reuse — executable modules must separate the Command Line Interface from the core logic. +

+ + +

Python application

+

Put argument parsing and if __name__ == "__main__": in the CLI section. Keep side effects out of import time.

+ +

Bash application

+

Bash scripts should start with #!/usr/bin/env bash and set -euo pipefail. RT-style Bash separates a small top-level CLI harness from a set of functions that implement the work. Parse arguments into variables, call a main function with explicit parameters, and avoid relying on global mutable state where possible.

+ +

C addendum: error handling and ownership

+ + +

Exercises

+

Exercise 1: Comma and function call formatting

+

Reformat the following C code snippet to strictly adhere to the RT code format rules.

+ + void my_function(int a, int b, int c) { + int result = calculate_value(a, b, c); + printf("Result: %d, a: %d, b: %d, c: %d\n", result, a, b, c); + } + + +

Exercise 2: Multi-level enclosure and short stuff rule

+

Reformat the following C code snippet to use the multi-level enclosure rule and the short stuff rule.

+ + if (check_permissions(user_id, file_path) && is_valid(file_path)) { + for (int i = 0; i < 10; i++) { + if (i % 2 == 0) { + printf("Even: %d\n", i); + } + } + } + + +

Exercise 3: Identifier Naming Conventions

+

+ Rename the following poorly named variables to strictly adhere to the RT code format rules. Assume these are variables in a C or Python program (using standard snake_case). Pay close attention to proper nouns, acronyms, and the expanded suffix semantics. +

+ + + +
+ + diff --git a/developer/tool/make b/developer/tool/make index 7adb889..853149a 100755 --- a/developer/tool/make +++ b/developer/tool/make @@ -13,14 +13,7 @@ set -e set -x cd "$REPO_HOME"/developer || exit 1 - # /bin/make -f tool/makefile $@ - - mkdir -p scratchpad/authored - cp authored/HTTP_server.js scratchpad/authored/ - cp authored/port_forwarder scratchpad/authored/ - cp authored/port_forwarder_CLI scratchpad/authored/ - cp authored/permission_RT scratchpad/authored/ - cp authored/permission_UPG scratchpad/authored/ + /bin/make -f tool/makefile $@ set +x echo "$(script_fn) done." diff --git a/developer/tool/makefile b/developer/tool/makefile index 65408ed..0b79a95 100644 --- a/developer/tool/makefile +++ b/developer/tool/makefile @@ -2,7 +2,7 @@ .SUFFIXES: .EXPORT_ALL_VARIABLES: -RT_INCOMMON := $(REPO_HOME)/shared/third_party/RT-project-share/release +RT_MAKEFILE_DP := $(REPO_HOME)/shared/tool/makefile include $(RT_INCOMMON)/make/environment_RT_1.mk .PHONY: usage @@ -14,9 +14,9 @@ version: @printf "local ----------------------------------------\n" @echo tool/makefile version 2.0 @printf "target_library_CLI.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_kmod.mk version + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_kmod.mk version @printf "target_kmod.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_library_CLI.mk version + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_library_CLI.mk version .PHONY: information information: @@ -26,29 +26,29 @@ information: @echo KMOD_BUILD_DIR="/lib/modules/$(shell uname -r)/build" @echo CURDIR="$(CURDIR)" @printf "target_library_CLI.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_library_CLI.mk information + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_library_CLI.mk information @printf "target_kmod.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_kmod.mk information + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_kmod.mk information .PHONY: all all: library CLI kmod .PHONY: library lib library lib: - @$(MAKE) -f $(RT_INCOMMON)/make/target_library_CLI.mk library + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_library_CLI.mk library .PHONY: CLI CLI: - @$(MAKE) -f $(RT_INCOMMON)/make/target_library_CLI.mk CLI + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_library_CLI.mk CLI .PHONY: kmod kmod: - @$(MAKE) -f $(RT_INCOMMON)/make/target_kmod.mk kmod + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_kmod.mk kmod .PHONY: clean clean: @printf "local ----------------------------------------\n" @printf "target_library_CLI.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_library_CLI.mk clean + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_library_CLI.mk clean @printf "target_kmod.mk ----------------------------------------\n" - @$(MAKE) -f $(RT_INCOMMON)/make/target_kmod.mk clean + @$(MAKE) -f $(RT_MAKEFILE_DP)/target_kmod.mk clean diff --git a/document/Introduction_to_Harmony.html b/document/Introduction_to_Harmony.html index 531f62e..917a3f8 100644 --- a/document/Introduction_to_Harmony.html +++ b/document/Introduction_to_Harmony.html @@ -253,91 +253,87 @@

The version 2.2 Harmony directory tree

- 2026-03-07 14:50:50 Z [Harmony:administrator] Thomas_PM@ManhattanSquare - §/home/Thomas/subu_data/PM/project§ + 2026-03-09 01:42:16 Z [Harmony:administrator] Thomas_developer@StanleyPark + §/home/Thomas/subu_data/developer/project§ > tree Harmony Harmony ├── 0pus_Harmony ├── administrator - │   ├── authored - │   ├── document - │   │   ├── 00_Project_Structure.html - - - │   │   ├── 01_Workflow_Build_Contract.html - │   │   ├── Harmony.md - │   │   └── setup.js - │   └── tool - │   ├── after_pull - │   ├── archive - │   ├── release - │   └── setup + │ ├── authored + │ ├── document + │ │ └── setup.js + │ └── tool + │ ├── archive + │ └── setup ├── consumer - - - │   ├── scratchpad - │   └── tool - │   └── env + │ ├── scratchpad + │ └── tool + │ └── env ├── developer - │   ├── authored - │   │   └── hello.cli.c - │   ├── document - │   │   ├── 02_RT_Code_Format.html - │   │   ├── 03_Naming_and_Directory_Conventions.html + │ ├── authored + │ │ └── hello.cli.c - │   │   ├── 04_Language_Addenda.html - │   │   ├── ontology.org - │   │   └── setup.js - │   ├── experiment - │   ├── made - │   ├── scratchpad - │   └── tool - │   ├── do_all - │   ├── make + │ ├── document + │ │ ├── 02_RT_Code_Format.html + │ │ ├── 03_Naming_and_Directory_Conventions.html + │ │ ├── 04_Language_Addenda.html + │ │ └── setup.js + │ ├── experiment + │ ├── made + │ ├── scratchpad + │ └── tool + │ ├── do_all + │ ├── make + │ ├── makefile + │ ├── release + │ └── setup + ├── document + │ ├── Introduction_to_Harmony.html + │ ├── Product_Development_Roles_and_Workflow.html + │ └── setup.js + ├── LICENSE - │   ├── makefile - │   ├── release - │   └── setup - ├── LICENSE + ├── README.md ├── scratchpad - │   └── Harmony__79f9d52__2026-03-07_085628Z.tar + │ ├── Harmony__79f9d52__2026-03-07_085628Z.tar + │ └── Harmony__e665bb7__2026-03-09_013712Z.tar ├── setup ├── shared - │   ├── authored + │ ├── authored + │ ├── document + │ │ ├── install_generic.org + │ │ ├── install_Python.org + │ │ └── setup.js + │ ├── made + │ ├── style_directory_dict.js + │ ├── third_party + │ │ ├── RT-style-JS_public -> ../../../RT-style-JS_public/ + │ │ └── upstream + │ └── tool + │ ├── scratchpad + │ ├── setup - │   ├── document - │   │   ├── install_generic.org - │   │   ├── install_Python.org - │   │   └── setup.js - │   ├── made - │   ├── style_directory_dict.js - │   ├── third_party - │   │   ├── RT-style-JS_public -> ../../../RT-style-JS_public/ - │   │   └── upstream - - - │   └── tool - │   ├── scratchpad - │   ├── setup - │   ├── style - │   └── version + │ ├── style + │ └── version └── tester ├── authored - │   └── test_routine.sh + │ └── test_routine.sh ├── RT_Format - - - │   ├── RT_Format - │   ├── RT_Format.el - │   ├── test_0_data.c - │   └── test_1_data.py + │ ├── RT_Format + │ ├── RT_Format.el + │ ├── test_0_data.c + │ └── test_1_data.py └── tool └── setup - 29 directories, 37 files + 30 directories, 36 files + + 2026-03-09 01:42:19 Z [Harmony:administrator] Thomas_developer@StanleyPark + §/home/Thomas/subu_data/developer/project§ + > diff --git a/shared/document/install_Python.org b/shared/document/install_Python.org index 14342f9..0aa11d1 100644 --- a/shared/document/install_Python.org +++ b/shared/document/install_Python.org @@ -10,8 +10,6 @@ This document describes how to install a project-local Python environment under: shared/third_party/Python #+end_src -This environment is shared across the =developer= and =tester= roles and is automatically activated through their respective =env_= scripts. - * Precondition Ensure the following: diff --git a/shared/made/.gitkeep b/shared/made/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/shared/tool/makefile/RT_0.h b/shared/tool/makefile/RT_0.h new file mode 100644 index 0000000..e102a5c --- /dev/null +++ b/shared/tool/makefile/RT_0.h @@ -0,0 +1,11 @@ +#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/environment_RT_1.mk b/shared/tool/makefile/environment_RT_1.mk new file mode 100644 index 0000000..0f23127 --- /dev/null +++ b/shared/tool/makefile/environment_RT_1.mk @@ -0,0 +1,30 @@ +# 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_kmod.mk b/shared/tool/makefile/target_kmod.mk new file mode 100644 index 0000000..9aa8eba --- /dev/null +++ b/shared/tool/makefile/target_kmod.mk @@ -0,0 +1,130 @@ +# make/target_kmod.mk — build *.kmod.c as kernel modules (single-pass, kmod-only) +# invoked from $REPO_HOME/ +# version 1.4 + +.SUFFIXES: +.DELETE_ON_ERROR: + +#-------------------------------------------------------------------------------- +# defaults for environment variables (override from outer make/env as needed) + +# Kernel build tree, which is part of the Linux system, use running kernel if unset +KMOD_BUILD_DIR ?= /lib/modules/$(shell uname -r)/build + +# Authored source directory (single dir) +KMOD_SOURCE_DIR ?= cc + +# Extra compiler flags passed to Kbuild (e.g., -I $(KMOD_SOURCE_DIR)) +KMOD_CCFLAGS ?= + +# Include *.lib.c into modules (1=yes, 0=no) +KMOD_INCLUDE_LIB ?= 1 + +# KMOD_OUTPUT_DIR is constrained, relative path, on the scratchpad, and ends in kmod +# Require: non-empty, relative, no '..', ends with 'kmod' dir +define assert_kmod_output_dir_ok + $(if $(strip $(1)),,$(error KMOD_OUTPUT_DIR is empty)) + $(if $(filter /%,$(1)),$(error KMOD_OUTPUT_DIR must be relative: '$(1)'),) + $(if $(filter %/../% ../% %/.. ..,$(1)),$(error KMOD_OUTPUT_DIR must not contain '..': '$(1)'),) + $(if $(filter %/kmod %/kmod/ kmod,$(1)),,$(error KMOD_OUTPUT_DIR must end with 'kmod': '$(1)')) +endef +KMOD_OUTPUT_DIR ?= scratchpad/kmod +$(eval $(call assert_kmod_output_dir_ok,$(KMOD_OUTPUT_DIR))) + +# The kernel make needs and absolute path to find the output directory +ABS_KMOD_OUTPUT_DIR := $(CURDIR)/$(KMOD_OUTPUT_DIR) + +#-------------------------------------------------------------------------------- +# derived variables (computed from the above) + +# Authored basenames (without suffix) +base_list := $(patsubst %.kmod.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.kmod.c))) + +# Optional library sources (without suffix) to include inside modules +ifeq ($(KMOD_INCLUDE_LIB),1) +lib_base := $(patsubst %.lib.c,%,$(notdir $(wildcard $(KMOD_SOURCE_DIR)/*.lib.c))) +else +lib_base := +endif + +# Staged sources (kept namespaced to prevent .o collisions) +all_kmod_c := $(addsuffix .kmod.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(base_list))) +all_lib_c := $(addsuffix .lib.c,$(addprefix $(KMOD_OUTPUT_DIR)/,$(lib_base))) + + + +#-------------------------------------------------------------------------------- +# targets + +.PHONY: usage +usage: + @printf "Usage: make [kmod|clean|information|version]\n" + +.PHONY: version +version: + @echo target_kmod version 1.4 + +.PHONY: information +information: + @echo "KMOD_SOURCE_DIR: " $(KMOD_SOURCE_DIR) + @echo "KMOD_BUILD_DIR: " $(KMOD_BUILD_DIR) + @echo "KMOD_OUTPUT_DIR: " $(KMOD_OUTPUT_DIR) + @echo "base_list: " $(base_list) + @echo "lib_base: " $(lib_base) + @echo "all_kmod_c: " $(all_kmod_c) + @echo "all_lib_c: " $(all_lib_c) + @echo "KMOD_INCLUDE_LIB=" $(KMOD_INCLUDE_LIB) + + +ifeq ($(strip $(base_list)),) + $(warning No *.kmod.c found under $(KMOD_SOURCE_DIR); nothing to build) +endif + +# --- Parallel-safe preparation as real targets --- + +# ensure the staging dir exists (order-only prereq) +$(KMOD_OUTPUT_DIR): + @mkdir -p "$(KMOD_OUTPUT_DIR)" + +# generate the Kbuild control Makefile +$(KMOD_OUTPUT_DIR)/Makefile: | $(KMOD_OUTPUT_DIR) + @{ \ + printf "ccflags-y += %s\n" "$(KMOD_CCFLAGS)"; \ + printf "obj-m := %s\n" "$(foreach m,$(base_list),$(m).o)"; \ + for m in $(base_list); do \ + printf "%s-objs := %s.kmod.o" "$$m" "$$m"; \ + for lb in $(lib_base); do printf " %s.lib.o" "$$lb"; done; \ + printf "\n"; \ + done; \ + } > "$@" + +# stage kmod sources (one rule per file; parallelizable) +$(KMOD_OUTPUT_DIR)/%.kmod.c: $(KMOD_SOURCE_DIR)/%.kmod.c | $(KMOD_OUTPUT_DIR) + @echo "--- Stage: $@ ---" + @cp -f "$(abspath $<)" "$@" + +# stage library sources (optional; also parallelizable) +$(KMOD_OUTPUT_DIR)/%.lib.c: $(KMOD_SOURCE_DIR)/%.lib.c | $(KMOD_OUTPUT_DIR) + @echo "--- Stage: $@ ---" + @cp -f "$(abspath $<)" "$@" + + +.PHONY: kmod +kmod: $(KMOD_OUTPUT_DIR)/Makefile $(all_kmod_c) $(all_lib_c) +ifeq ($(strip $(base_list)),) + @echo "--- No kmod sources; nothing to do ---" +else + @echo "--- Invoking Kbuild for kmod: $(base_list) ---" + $(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" modules +endif + +# quality-of-life: allow 'make scratchpad/kmod/foo.ko' after batch build +$(KMOD_OUTPUT_DIR)/%.ko: kmod + @true + +.PHONY: clean +clean: + @echo "Cleaning: $(KMOD_BUILD_DIR)" + @$(MAKE) -C "$(KMOD_BUILD_DIR)" M="$(ABS_KMOD_OUTPUT_DIR)" clean >/dev/null 2>&1 || true + @echo "Cleaning: $(KMOD_OUTPUT_DIR)" + @rm -rf -- "$(KMOD_OUTPUT_DIR)" diff --git a/shared/tool/makefile/target_library_CLI.mk b/shared/tool/makefile/target_library_CLI.mk new file mode 100644 index 0000000..ca8c386 --- /dev/null +++ b/shared/tool/makefile/target_library_CLI.mk @@ -0,0 +1,105 @@ +# make/target_lib_CLI.mk — build *.lib.c and *.CLI.c +# written for the Harmony skeleton, always invoked from cwd $REPO_HOME/ +# files have two suffixes by convention, e.g.: X.lib.c or Y.CLI.c + +.SUFFIXES: +.DELETE_ON_ERROR: + +#-------------------------------------------------------------------------------- +# defaults for environment variables + +C ?= gcc +CFLAGS ?= +C_SOURCE_DIR ?= cc +LIBRARY_FILE ?= +MACHINE_DIR ?= scratchpad/machine +LN_FLAGS ?= + +#-------------------------------------------------------------------------------- +# derived variables + +# source discovery (single dir) +c_source_lib := $(wildcard $(C_SOURCE_DIR)/*.lib.c) +c_source_exec := $(wildcard $(C_SOURCE_DIR)/*.CLI.c) + +# remove suffix to get base name +c_base_lib := $(sort $(patsubst %.lib.c,%, $(notdir $(c_source_lib)))) +c_base_exec := $(sort $(patsubst %.CLI.c,%, $(notdir $(c_source_exec)))) + +# two sets of object files, one for the lib, and one for the CLI programs +object_lib := $(patsubst %, scratchpad/%.lib.o, $(c_base_lib)) +object_exec := $(patsubst %, scratchpad/%.CLI.o, $(c_base_exec)) + +# executables are made from exec_ sources +exec_ := $(patsubst %, $(MACHINE_DIR)/%, $(c_base_exec)) + +#-------------------------------------------------------------------------------- +# pull in dependencies + +-include $(object_lib:.o=.d) $(object_exec:.o=.d) + + +#-------------------------------------------------------------------------------- +# targets + +# when no target is given make uses the first target, this one +.PHONY: usage +usage: + @echo example usage: make clean + @echo example usage: make library + @echo example usage: make CLI + @echo example usage: make library CLI + +.PHONY: version +version: + @echo makefile version 7.1 + if [ ! -z "$(C)" ]; then $(C) -v; fi + /bin/make -v + +.PHONY: information +information: + @printf "· → Unicode middle dot — visible: [%b]\n" "·" + @echo "C_SOURCE_DIR: " $(C_SOURCE_DIR) + @echo "c_source_lib: " $(c_source_lib) + @echo "c_source_exec: " $(c_source_exec) + @echo "c_base_lib: " $(c_base_lib) + @echo "c_base_exec: " $(c_base_exec) + @echo "object_lib: " $(object_lib) + @echo "object_exec: " $(object_exec) + @echo "exec_: " $(exec_) + +.PHONY: library +library: $(LIBRARY_FILE) + +$(LIBRARY_FILE): $(object_lib) + @if [ -s "$@" ] || [ -n "$(object_lib)" ]; then \ + echo "ar rcs $@ $^"; \ + ar rcs $@ $^; \ + else \ + rm -f "$@"; \ + fi + +#.PHONY: CLI +#CLI: $(LIBRARY_FILE) $(exec_) + +.PHONY: CLI +CLI: library $(exec_) + + +# generally better to use the project local clean scripts, but this will make it so that the make targets can be run again + +.PHONY: clean +clean: + rm -f $(LIBRARY_FILE) + for obj in $(object_lib) $(object_exec); do rm -f $$obj $${obj%.o}.d || true; done + for i in $(exec_); do [ -e $$i ] && rm $$i || true; done + + +# recipes +scratchpad/%.o: $(C_SOURCE_DIR)/%.c + $(C) $(CFLAGS) -o $@ -c $< + +$(MACHINE_DIR)/%: scratchpad/%.CLI.o + mkdir -p $(MACHINE_DIR) + $(C) -o $@ $< $(LN_FLAGS) + diff --git a/shared/tool/style/.gitkeep b/shared/tool/style/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tester/authored/.gitkeep b/tester/authored/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tester/authored/test_routine.sh b/tester/authored/test_routine.sh deleted file mode 100644 index f22c3ba..0000000 --- a/tester/authored/test_routine.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# test_routing.sh -# Sends mock HTTP requests to the local unix socket to verify domain routing. - -SOCKET_FP="../user/release/scratchpad/network_interface/RT_server.sock" - -if [ ! -S "${SOCKET_FP}" ]; then - echo "Error: Socket not found at ${SOCKET_FP}" >&2 - echo "Make sure the HTTP_server.js process is running in the user workspace." >&2 - exit 1 -fi - -echo "=== Testing Reasoning Technology domain ===" -curl --unix-socket "${SOCKET_FP}" \ - -H "Host: x6.reasoningtechnology.com" \ - http://localhost/ - -echo -e "\n\n=== Testing Thomas Walker Lynch domain ===" -curl --unix-socket "${SOCKET_FP}" \ - -H "Host: x6.thomas-walker-lynch.com" \ - http://localhost/ - -echo -e "\n\n=== Testing Unknown domain ===" -curl --unix-socket "${SOCKET_FP}" \ - -H "Host: nonexistent-domain.com" \ - http://localhost/