Skip to content

Conversation

steven-studio
Copy link

@steven-studio steven-studio commented Sep 29, 2025

Changes

This PR improves the Makefile with better organization and more robust bootstrap verification while maintaining full self-hosting capabilities.

Key Improvements

  1. Fixed bootstrap verification - Changed from @if to $(Q)if and replaced $(VECHO) with plain echo inside shell conditionals to avoid /bin/sh: @env: not found error

  2. Better organization

    • Added clear section comments for readability
    • Consolidated .PHONY declarations
    • Made .DEFAULT_GOAL explicit
  3. Enhanced bootstrap process

    • Used cmp -s instead of diff -q for more reliable binary comparison
    • Added informative success/failure messages
    • Clearer error reporting
  4. Improved directory handling

    • Used order-only prerequisites (| $(OUT)) to prevent unnecessary rebuilds
    • Better mkdir -p usage in compilation rules
  5. Added help target - Provides quick reference for available targets and variables

  6. Consistency improvements

    • Changed --silent to --no-print-directory for clearer intent
    • Added CC ?= gcc for easier compiler override
    • Renamed deps to DEPS for naming consistency

Testing

  • ✅ Verified bootstrap process completes successfully
  • ✅ Stage 1 and Stage 2 compilers are identical
  • ✅ All existing functionality preserved

What's Preserved

  • Complete self-hosting capability (Stage 0 → Stage 1 → Stage 2)
  • All test targets and snapshot functionality
  • Architecture switching mechanism (ARM/RISC-V)
  • Sanitizer support
  • Dependency tracking

Summary by cubic

Strengthens Makefile bootstrap verification and fixes shell conditional errors to make the self-hosting build reliable. Also simplifies targets, flags, and directory handling for a cleaner build experience.

  • Bug Fixes

    • Fixed /bin/sh error in conditionals by switching from @if to $(Q)if and using plain echo.
    • Switched bootstrap check to cmp -s with clear success/failure messages.
  • Refactors

    • Added CC ?= gcc, explicit .DEFAULT_GOAL, and consolidated .PHONY.
    • Added help target; replaced --silent with --no-print-directory for clarity.
    • Used order-only prerequisites and mkdir -p; added an OUT rule to create dirs predictably.
    • Renamed deps to DEPS and improved clean/distclean; ensured tool builds use | $(OUT).

Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check https://cbea.ms/git-commit/ carefully and improve git commit message.

@jserv
Copy link
Collaborator

jserv commented Sep 29, 2025

Don't mix independent changes into a single commit.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@steven-studio steven-studio force-pushed the feature/makefile-improvements branch from f71718f to 09464aa Compare September 29, 2025 06:59
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decouple the changes for fixing bootstrapping from those for consolidating the Makefile. There should be at least two separate commits.

The bootstrap target was failing with '/bin/sh: @env: not found'
because the original implementation used complex shell conditionals
that could cause @ to be interpreted as a shell command.

Changes:
- Replace 'diff -q' with 'cmp -s' for reliable binary comparison
- Restructure conditional to test for success rather than failure
- Use plain echo for messages to avoid macro expansion issues
- Add explicit success/error messages for clarity
@steven-studio steven-studio force-pushed the feature/makefile-improvements branch from 09464aa to edd3db2 Compare September 29, 2025 07:24
$(Q)if ! diff -q $(OUT)/$(STAGE1) $(OUT)/$(STAGE2); then \
echo "Unable to bootstrap. Aborting"; false; \
$(Q)if cmp -s $(OUT)/$(STAGE1) $(OUT)/$(STAGE2); then \
echo "Bootstrap successful: Stage 1 and Stage 2 are identical"; \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the true case, it is not necessary to display messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants