From d0c2dd2c307b799bfe52c32a9d66b3bdd025d743 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Thu, 15 May 2025 06:55:56 +0000 Subject: [PATCH] some doc and script updates --- README.md | 14 +++- .../README.org" | 42 +++++----- .../RT_extensions_install.sh" | 56 +++++++++++++ .../RT_extensions_libcpp_capture.sh" | 81 +++++++++++++++++++ .../deprecated/stuff.cc" | 0 .../expand_assign_arg_try_0.cc" | 67 --------------- .../get_paren_balanced_chars.cc" | 48 ----------- .../library/directives.cc" | 0 .../library/macro.cc" | 0 9 files changed, 174 insertions(+), 134 deletions(-) create mode 100755 "script_gcc_min-12\360\237\226\211/RT_extensions_install.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/RT_extensions_libcpp_capture.sh" rename "script_gcc_min-12\360\237\226\211/deprecated_stuff.cc" => "script_gcc_min-12\360\237\226\211/deprecated/stuff.cc" (100%) delete mode 100644 "script_gcc_min-12\360\237\226\211/expand_assign_arg_try_0.cc" delete mode 100644 "script_gcc_min-12\360\237\226\211/get_paren_balanced_chars.cc" rename "script_gcc_min-12\360\237\226\211/directives.cc" => "script_gcc_min-12\360\237\226\211/library/directives.cc" (100%) rename "script_gcc_min-12\360\237\226\211/macro.cc" => "script_gcc_min-12\360\237\226\211/library/macro.cc" (100%) diff --git a/README.md b/README.md index 442c17a..d5c424a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Standalone GCC Installation with Option for RT Mods -As of 2025-05-14: +As of 2025-05-15: + +This is pre-release development. * Based on GCC 12.4.1 * Builds on Debian 12 @@ -9,6 +11,16 @@ As of 2025-05-14: --- +## General Notes + +The scripts in the script_gcc_min-12🖉/ directory are working on Debian 12.10, though 'build_all.sh' has not been run yet. It currently functions as documentation as to how to do the install. Though you might run it if you are brave, mightbe that it will work. + +The scripts in the script_gcc-15🖉/ directory do not work. It was difficult to bootstrap a standalone install of the latest gcc. Hence the fall back to the + +The gcc 12 scripts are working. + +With the esception of this file, all documents are in emacs org format. + ## Standalone Build For those who wish to let the chips fall where they may: diff --git "a/script_gcc_min-12\360\237\226\211/README.org" "b/script_gcc_min-12\360\237\226\211/README.org" index 44936b8..01bb29b 100755 --- "a/script_gcc_min-12\360\237\226\211/README.org" +++ "b/script_gcc_min-12\360\237\226\211/README.org" @@ -1,34 +1,40 @@ +* General Notes -This was a bear to get running, and I have given up on it for now. +GNU `cpp` is integrated with the gcc repo. -It dies early in the chain at the making of glibc and the crt.o -etc. files. +There is a lot more to GCC than one might imagine. It was developed as though an integral part of Unix. Hence, the standalone build has top-level directories that resemble the top level of a Unix system. -# Scripts for building standalone gcc +The scripts here will download source and build a standalone GCC 12 along with version-compatible tools. It is common for a toolsmith to read the scripts and copy paste the commands. -The scripts here will build a standalone gcc along with version compatible tools. +* RT extensions -There is a lot more to a gcc than one might imagine. It was developed as though an integral part of Unix. Hence, the standalone build has top level directories with many things in them, in parallel to the top level directories a person would find on a Unix system. +If you want the RT extensions, the install_RT_extensions.sh must be run after the gcc sources are expanded. -## .gitignore +* environment -* If there is no top level `.gitignore`, `setup_project.sh` will create one. -* The synthesized `.gitignore` references itself, so it will not get checked in. -* No script, including`clean_dist.sh`, will delete an existing `.gitignore`. +Don't forget `source env_toolsmith` in your shell. -## Clean +* Setup -* clean_build.sh - for saving space after the build is done. The build scripts are idempotent, so in an ideal world this need not be run to do a rebuild. +- `setup_project.sh` :: Makes the directory structure for the build, creates a `tmp/` directory under the project. If it does not already exist, creates a `.gitignore` file with all the created directories listed. -* clean_dist.sh - with on exception, this will delete everything that was synthesized. The one exception is that .gitignore is moved to the tmp directory so as to preserve any changes a user might have been made, and the contents of the tmp directory are not removed. +* Top level .gitignore -* clean_tmp.sh - wipes clean all contents of the temporary directory. +- There is no `.gitignore` at the top level when the project is cloned. The `.gitignore` created by `setup_project.sh` ignores itself, so it will not be checked in. +- No script deletes the top level `.gitignore`, including the clean scripts, so the toolsmith can make edits there that persist locally. -## Setup +* Clean -* setup_project.sh - makes the directory structure for the build, creates a `tmp/` directory under the project. If it does not already exist, creates a .gitignore file with all the created directories listed. +- `clean_build.sh` :: For saving space after the build is done. The build scripts are idempotent, so in an ideal world this need not be run to do a rebuild. -## Download +- `clean_dist.sh` :: With one exception, this will delete everything that was synthesized. The one exception is that `.gitignore` is moved to the `tmp/` directory to preserve any changes a user might have made, and the contents of the `tmp/` directory are not removed. -* download_upstream_sources.sh - goes to the Internet, fetches all the sources that have not already been fetched. Then expands the sources into the proper sub-directory under `source/1. +- `clean_tmp.sh` :: Wipes clean all contents of the temporary directory. +* Download + +- `download_upstream_sources.sh` :: Goes to the Internet, fetches all the sources that have not already been fetched. Then expands the sources into the proper sub-directory under `source/1`. + +* Build + +See the script build_all.sh for a description of the complete build process. diff --git "a/script_gcc_min-12\360\237\226\211/RT_extensions_install.sh" "b/script_gcc_min-12\360\237\226\211/RT_extensions_install.sh" new file mode 100755 index 0000000..634f148 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/RT_extensions_install.sh" @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +# Check ROOT is set +if [[ -z "${ROOT:-}" ]]; then + echo "❌ ROOT environment variable is not set. Aborting." + exit 1 +fi + +SRCDIR="$ROOT/script_gcc_min-12🖉/library" +DESTDIR="$ROOT/source/gcc-12.2.0/libcpp" + +if [[ ! -d "$SRCDIR" ]]; then + echo "❌ Source directory '$SRCDIR' does not exist." + exit 1 +fi + +if [[ ! -d "$DESTDIR" ]]; then + echo "❌ Destination directory '$DESTDIR' does not exist." + exit 1 +fi + +FILES=(init.cc directives.cc macro.cc) + +echo "📋 Installing files from $SRCDIR to $DESTDIR..." + +for file in "${FILES[@]}"; do + SRC="$SRCDIR/$file" + DEST="$DESTDIR/$file" + + if [[ ! -f "$SRC" ]]; then + echo "⚠️ Source file '$SRC' not found. Skipping." + continue + fi + + if [[ ! -f "$DEST" || "$SRC" -nt "$DEST" ]]; then + echo "📥 Installing (newer or missing): $file" + cp "$SRC" "$DEST" + elif [[ "$DEST" -nt "$SRC" ]]; then + echo "⚠️ Destination file '$file' is newer than the source." + echo "🔍 Showing diff:" + diff -u "$DEST" "$SRC" || true + echo -n "❓ Overwrite destination '$file' with older source? [y/N]: " + read -r response + if [[ "$response" == "y" || "$response" == "Y" ]]; then + echo "📥 Overwriting: $file" + cp -p "$SRC" "$DEST" + else + echo "⏭️ Skipping: $file" + fi + else + echo "✅ Up-to-date: $file" + fi +done + +echo "✅ Installation complete." diff --git "a/script_gcc_min-12\360\237\226\211/RT_extensions_libcpp_capture.sh" "b/script_gcc_min-12\360\237\226\211/RT_extensions_libcpp_capture.sh" new file mode 100755 index 0000000..59d482a --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/RT_extensions_libcpp_capture.sh" @@ -0,0 +1,81 @@ +#!/bin/bash +set -euo pipefail + +echo "⚠️ You probably don't want to run this script. The files in \$ROOT/script_gcc_min-12🖉/library are intended to be the authoritative copies." +echo "So you did the bad thing and edited the files directly in the GCC source tree? Then this script is for you. ;-)" +echo + +# Check ROOT is set +if [[ -z "${ROOT:-}" ]]; then + echo "❌ ROOT environment variable is not set. Aborting." + exit 1 +fi + +SRCDIR="$ROOT/source/gcc-12.2.0/libcpp" +DESTDIR="$ROOT/script_gcc_min-12🖉/library" + +if [[ ! -d "$SRCDIR" ]]; then + echo "❌ Source directory '$SRCDIR' does not exist." + exit 1 +fi + +if [[ ! -d "$DESTDIR" ]]; then + echo "❌ Destination directory '$DESTDIR' does not exist." + exit 1 +fi + +FILES=(init.cc directives.cc macro.cc) + +echo "📋 Checking files in $SRCDIR to copy to $DESTDIR..." + +for file in "${FILES[@]}"; do + SRC="$SRCDIR/$file" + DEST="$DESTDIR/$file" + + if [[ ! -f "$SRC" ]]; then + echo "⚠️ Source file '$SRC' not found. Skipping." + continue + fi + + if [[ ! -f "$DEST" ]]; then + echo "📤 No destination file. Copying: $file" + cp -p "$SRC" "$DEST" + continue + fi + + if cmp -s "$SRC" "$DEST"; then + echo "✅ No changes: $file" + continue + fi + + if [[ "$SRC" -nt "$DEST" ]]; then + echo "📤 Source is newer and differs. Copying: $file" + cp -p "$SRC" "$DEST" + elif [[ "$DEST" -nt "$SRC" ]]; then + echo "⚠️ Destination file '$file' is newer than source and differs." + echo "🔍 Showing diff:" + diff -u "$DEST" "$SRC" || true + echo -n "❓ Overwrite the authoritative '$file' with the older source version? [y/N]: " + read -r response + if [[ "$response" == "y" || "$response" == "Y" ]]; then + echo "📤 Overwriting with older source: $file" + cp -p "$SRC" "$DEST" + else + echo "❌ Skipping: $file" + fi + else + echo "⚠️ Files differ but timestamps are equal: $file" + echo "🔍 Showing diff:" + diff -u "$DEST" "$SRC" || true + echo -n "❓ Overwrite anyway? [y/N]: " + read -r response + if [[ "$response" == "y" || "$response" == "Y" ]]; then + cp -p "$SRC" "$DEST" + echo "📤 Overwritten." + else + echo "❌ Skipped." + fi + fi +done + +echo "✅ Capture complete." diff --git "a/script_gcc_min-12\360\237\226\211/deprecated_stuff.cc" "b/script_gcc_min-12\360\237\226\211/deprecated/stuff.cc" similarity index 100% rename from "script_gcc_min-12\360\237\226\211/deprecated_stuff.cc" rename to "script_gcc_min-12\360\237\226\211/deprecated/stuff.cc" diff --git "a/script_gcc_min-12\360\237\226\211/expand_assign_arg_try_0.cc" "b/script_gcc_min-12\360\237\226\211/expand_assign_arg_try_0.cc" deleted file mode 100644 index e2e925d..0000000 --- "a/script_gcc_min-12\360\237\226\211/expand_assign_arg_try_0.cc" +++ /dev/null @@ -1,67 +0,0 @@ -/* - Given the cpp_reader and an assignment argument in the form of a macro. - Returns ... through the `result` argument. - Returns ... - - Assign name_expr and body_expr arguments are each placed into a - macro instance, then are sent here to be expanded. - - Push the context of a macro onto the context stack. If we can - successfully expand the macro, we push a context containing its - yet-to-be-rescanned replacement list and return one. LOCATION is - the location of the expansion point of the macro. - - derived from enter_macro_context() -*/ -static int -enter_macro_context_RT_assign( - cpp_reader *pfile - ,cpp_macro *macro - ,const cpp_token *result - ,location_t location -){ - /* The presence of a macro invalidates a file's controlling macro. */ - pfile->mi_valid = false; - pfile->state.angled_headers = false; - pfile->about_to_expand_macro_p = true; - - // not expanding a pragma - - // Disable the macro within its expansion. - // assign has no node at this point - // node->flags |= NODE_DISABLED; - - // not lazy, doing it now - // no need to notify of macro use - // macro->paramc is indeed zero when we get here (assign has no parameters) - - unsigned tokens_count = macro_real_token_count (macro); - - // no need to check for the track_macro_expansion option - - //_cpp_push_token_context (pfile, node, macro->exp.tokens, tokens_count); - // _cpp_push_token_context allows for a NULL node - _cpp_push_token_context (pfile, NULL, macro->exp.tokens, tokens_count); - - num_macro_tokens_counter += tokens_count; - - // not inside of a pragma (inside of a #assign) - - pfile->about_to_expand_macro_p = false; - return 1; - - pfile->about_to_expand_macro_p = false; - /* Handle built-in macros and the _Pragma operator. */ - { - location_t expand_loc; - - // not function like - - /* Otherwise, the location of the end of the macro invocation is - the location of the expansion point of that top-level macro - invocation. */ - expand_loc = pfile->invocation_location; - - return builtin_macro (pfile, node, location, expand_loc); - } -} diff --git "a/script_gcc_min-12\360\237\226\211/get_paren_balanced_chars.cc" "b/script_gcc_min-12\360\237\226\211/get_paren_balanced_chars.cc" deleted file mode 100644 index 21cd614..0000000 --- "a/script_gcc_min-12\360\237\226\211/get_paren_balanced_chars.cc" +++ /dev/null @@ -1,48 +0,0 @@ -bool -cpp_get_paren_balanced_chars(cpp_reader *pfile) -{ - const unsigned char *cur = pfile->buffer->cur; - const unsigned char *rlimit = pfile->buffer->rlimit; - cpp_buffer *buffer = pfile->buffer; - - // Skip leading whitespace - while (cur < rlimit && ISSPACE(*cur)) - cur++; - - if (cur == rlimit || *cur != '(') - { - cpp_error(pfile, CPP_DL_ERROR, "expected opening parenthesis for macro body"); - return false; - } - - int depth = 0; - const unsigned char *scan = cur; - while (scan < rlimit) - { - if (*scan == '(') - depth++; - else if (*scan == ')') - { - depth--; - if (depth == 0) - { - // Copy from opening ( to matching ) inclusive - size_t len = scan - cur + 1; - unsigned char *copy = (unsigned char *)_cpp_unaligned_alloc(pfile, len + 1); - memcpy(copy, cur, len); - copy[len] = '\0'; - - // Point lexer buffer to just this region - buffer->cur = copy; - buffer->rlimit = copy + len; - buffer->next_line = NULL; // Signals EOF to lexer - return true; - } - } - scan++; - } - - // If we got here, closing paren was never found - cpp_error(pfile, CPP_DL_ERROR, "unclosed parenthesis in macro body"); - return false; -} diff --git "a/script_gcc_min-12\360\237\226\211/directives.cc" "b/script_gcc_min-12\360\237\226\211/library/directives.cc" similarity index 100% rename from "script_gcc_min-12\360\237\226\211/directives.cc" rename to "script_gcc_min-12\360\237\226\211/library/directives.cc" diff --git "a/script_gcc_min-12\360\237\226\211/macro.cc" "b/script_gcc_min-12\360\237\226\211/library/macro.cc" similarity index 100% rename from "script_gcc_min-12\360\237\226\211/macro.cc" rename to "script_gcc_min-12\360\237\226\211/library/macro.cc" -- 2.20.1