Build System & Toolchain
Overview
The FreeWorld OS build system provides cross-compilation toolchain setup, kernel headers, and build scripts for compiling programs for FreeWorld OS.
Components
1. Cross-Compilation Toolchain
Location: build-toolchain.sh
Sets up GCC wrapper scripts for FreeWorld target:
- Creates
x86_64-freeworld-gccwrapper - Configures FreeWorld-specific compiler flags
- Sets up include and library paths
- Creates tool wrappers (ar, as, ld, etc.)
Usage
./build-toolchain.sh
Creates toolchain in build/toolchain/bin/
2. Kernel Headers
Location: scripts/create-kernel-headers.sh
Creates system headers in build/sysroot/usr/include/:
sys/syscall.h- System call numbersfreeworld/kernel.h- Kernel types and structuresunistd.h- POSIX system call wrapperserrno.h- Error codesstddef.h- Standard definitionsstdint.h- Integer typesstdarg.h- Variable argumentsstring.h- String function declarations
Usage
./scripts/create-kernel-headers.sh
3. Minimal C Library Build
Location: libc-minimal/Makefile
Builds the minimal C library:
cd libc-minimal
make
make install
4. glibc Build Scripts (Future)
Location: scripts/configure-glibc.sh, scripts/build-glibc.sh
Scripts for building glibc (requires FreeWorld sysdeps implementation):
- Configure glibc for FreeWorld target
- Build glibc (will take hours)
- Install to filesystem
Note: Full glibc build requires extensive FreeWorld-specific implementation.
5. Node.js Build Scripts (Future)
Location: scripts/configure-nodejs.sh, scripts/build-nodejs.sh
Scripts for building Node.js (requires OS abstraction layer):
- Configure Node.js for FreeWorld target
- Build Node.js and V8 (will take many hours)
- Install to filesystem
Note: Full Node.js build requires extensive FreeWorld-specific implementation.
Build Process
Step 1: Set Up Toolchain
./build-toolchain.sh
This creates the cross-compiler wrappers.
Step 2: Create Kernel Headers
./scripts/create-kernel-headers.sh
This creates all system headers.
Step 3: Build Minimal C Library
cd libc-minimal
make
make install
This builds and installs the C library.
Step 4: Compile Programs
# Add toolchain to PATH
export PATH="$(pwd)/build/toolchain/bin:$PATH"
# Compile a program
x86_64-freeworld-gcc -o hello hello.c -Lbuild/sysroot/lib -lc
Compiler Flags
The cross-compiler uses these flags automatically:
-ffreestanding- Freestanding environment (no standard library)-fno-stack-protector- No stack protection-fno-pic- No position-independent code-mno-red-zone- No red zone (required for kernel)-nostdlib- Don't link standard library-nostdinc- Don't use standard include paths-Ibuild/sysroot/usr/include- Kernel headers path-Lbuild/sysroot/lib- Library path
Directory Structure
build/
├── toolchain/ # Cross-compiler toolchain
│ └── bin/ # Compiler wrappers
├── sysroot/ # System root
│ ├── usr/
│ │ └── include/ # Kernel headers
│ └── lib/ # Libraries (libc.a)
└── glibc-build/ # glibc build directory (future)
└── nodejs-build/ # Node.js build directory (future)
libc-minimal/ # Minimal C library source
├── src/ # Source files
├── include/ # Header files
├── lib/ # Built library
└── Makefile # Build configuration
scripts/ # Build scripts
├── create-kernel-headers.sh
├── configure-glibc.sh
├── build-glibc.sh
├── configure-nodejs.sh
└── build-nodejs.sh
Future: Full glibc Build
To build full glibc (when ready):
- Implement FreeWorld sysdeps (
dev/glibc/sysdeps/freeworld/) - Run
./scripts/configure-glibc.sh - Run
./scripts/build-glibc.sh(will take hours)
See BUILD-GLIBC-NODEJS.md for details.
Future: Node.js Build
To build Node.js (when ready):
- Implement FreeWorld OS abstraction layer
- Port V8 platform support
- Run
./scripts/configure-nodejs.sh - Run
./scripts/build-nodejs.sh(will take many hours)
See BUILD-GLIBC-NODEJS.md for details.
Related Documentation
- Minimal C Library - C runtime library
- System Calls - System call interface
- ELF Loader - Loading executables
- Building glibc and Node.js - Full build guide