๐ CAmalgamator
August 1, 2025 ยท View on GitHub
A powerful C amalgamator CLI tool that combines multiple C files into a single file โจ
Perfect for creating single-header libraries, distributing projects, and simplifying builds!
๐ฏ What is CAmalgamator? (Super Simple Explanation!)
Imagine you have a LEGO castle made of many pieces scattered around your room. ๐ฐ
CAmalgamator is like a magic tool that:
- Finds all your LEGO pieces (C files) ๐ฆ
- Connects them together ๐
- Gives you one complete castle (single C file) โจ
๐ In Programming Terms:
If you have a C project with files like:
main.c(your main program)helper.c(some useful functions)math.c(math functions)helper.handmath.h(header files)
CAmalgamator combines ALL of these into ONE single file! ๐
๐ค Why is this AMAZING for beginners?
โ SUPER EASY to Share
- Before: "Hey, here are 20 files you need to compile my program..."
- After: "Hey, here's 1 file - just compile and run!" ๐
โ NO Complex Build Systems
- Before: Need Makefiles, CMake, or other scary build tools ๐ฐ
- After: Just
gcc single_file.c -o my_programโจ
โ Perfect for Learning
- See exactly what code is included
- No mysterious "where does this function come from?" moments
- Easy to understand the entire program flow
โ Great for Competitions
- Programming contests often want single files
- Easy to submit to online judges
- No dependency headaches
๐ฅ Download & Installation (Choose Your Adventure!)
๐จ Total Beginner? Start with the "๐ฎ Super Easy Download" section below!
๐ฎ Super Easy Download (No Compilation Needed!)
Just want to use it RIGHT NOW? Download the ready-to-run version for your computer:
| ๐ฅ๏ธ Your Computer | ๏ฟฝ Download This | ๐โโ๏ธ How to Use |
|---|---|---|
| ๏ฟฝ Linux | CAmalgamator.out | Download โ Make executable โ Run! |
| ๐ช Windows (64-bit) | CAmalgamator64.exe | Download โ Double-click โ Use! |
| ๐ช Windows (32-bit) | CAmalgamatori32.exe | Download โ Double-click โ Use! |
๐ Super Quick Installation (Copy & Paste!)
๐ง Linux Users (Easiest Way Ever!):
# Just copy and paste this into your terminal!
curl -L https://github.com/OUIsolutions/CAmalgamator/releases/download/0.0.4/CAmalgamator.out -o CAmalgamator
chmod +x CAmalgamator
# Now you can use it like this:
./CAmalgamator --help
๐ง Ubuntu/Debian Users (Even Easier!):
# Download the package
wget https://github.com/OUIsolutions/CAmalgamator/releases/download/0.0.4/CAmalgamator.deb
# Install it (you'll need to enter your password)
sudo dpkg -i CAmalgamator.deb
# Now it's installed system-wide! Use it anywhere:
CAmalgamator --help
๐งโ๐ป Advanced Downloads (For Developers)
| ๐ File | ๐ฏ Best For | ๐ Description |
|---|---|---|
| ๏ฟฝ๏ธ CAmalgamator.c | Developers who want to compile | Complete source code |
| ๏ฟฝ CAmalgamatorApiOne.h | Use in your C programs | Full API library |
| ๏ฟฝ CAmalgamatorApiNoDependenciesIncluded.h | Minimal integration | Lightweight version |
| ๐ฆ CAmalgamator.rpm | Fedora/RHEL/CentOS | RPM package |
๐โโ๏ธ Quick Start Guide (For Total Beginners!)
Don't panic! This is easier than making instant noodles! ๐
๐ฌ Step 1: Your First Amalgamation (The Basics)
Let's start with the simplest possible example:
# This is THE most basic command you'll ever need!
./CAmalgamator --file main.c --output combined.c
๐ค What just happened?
--file main.cโ "Hey CAmalgamator, start with this file!"--output combined.cโ "Put the final result in this file!"
That's it! CAmalgamator will:
- ๐ Look at
main.c - ๐ต๏ธโโ๏ธ Find all the
#includestatements - ๐ Follow each include and grab that code
- ๐ Put everything together in
combined.c
๐ฌ Step 2: Real-World Example (Let's Do This Together!)
Imagine you have these files:
my_awesome_project/
โโโ main.c โ Your main program
โโโ calculator.h โ Calculator functions
โโโ calculator.c โ Calculator implementation
โโโ helpers.h โ Helper functions
โโโ helpers.c โ Helper implementation
๐งโ๐ป What's in each file:
main.c:
#include <stdio.h>
#include "calculator.h"
#include "helpers.h"
int main() {
printf("Hello from my awesome program!\n");
int result = add(5, 3);
print_result(result);
return 0;
}
calculator.h:
#ifndef CALCULATOR_H
#define CALCULATOR_H
int add(int a, int b);
int subtract(int a, int b);
#endif
calculator.c:
#include "calculator.h"
int add(int a, int b) { return a + b; }
int subtract(int a, int b) { return a - b; }
helpers.h:
#ifndef HELPERS_H
#define HELPERS_H
void print_result(int result);
#endif
helpers.c:
#include <stdio.h>
#include "helpers.h"
void print_result(int result) {
printf("The result is: %d\n", result);
}
๐ Now, let's combine everything:
./CAmalgamator --file main.c --output single_awesome_program.c
๐ BOOM! Now you have ONE file called single_awesome_program.c with EVERYTHING inside!
You can compile and run it with just:
gcc single_awesome_program.c -o my_program
./my_program
No more worrying about:
- โ "Did I include all the files?"
- โ "Why can't the compiler find my functions?"
- โ "How do I link all these files together?"
๐ฌ Step 3: Test It Yourself!
Create a simple test:
- Create
test_main.c:
#include <stdio.h>
#include "test_math.h"
int main() {
printf("Testing CAmalgamator!\n");
printf("2 + 3 = %d\n", simple_add(2, 3));
return 0;
}
- Create
test_math.h:
#ifndef TEST_MATH_H
#define TEST_MATH_H
int simple_add(int a, int b);
#endif
- Create
test_math.c:
#include "test_math.h"
int simple_add(int a, int b) {
return a + b;
}
- Run CAmalgamator:
./CAmalgamator --file test_main.c --output combined_test.c
- Compile and run:
gcc combined_test.c -o test_program
./test_program
Expected output:
Testing CAmalgamator!
2 + 3 = 5
๏ฟฝ Congratulations! You just used CAmalgamator successfully!
โ๏ธ Command-Line Options (All the Cool Features!)
๐ฏ Beginner Tip: Start with just
--fileand--output. Learn the other options later!
๐ฅ Essential Options (You NEED These!)
| ๐ท๏ธ Flag | ๐ What It Does | ๐จ Required? | ๐ก Example |
|---|---|---|---|
--file or --f | The starting file (where to begin) | โ YES | --file main.c |
--output or --o | Where to save the result | โ YES | --output combined.c |
๐ก๏ธ Safety Options (Protect Yourself!)
| ๐ท๏ธ Flag | ๐ What It Does | ๐ง Default | ๐ก When to Use |
|---|---|---|---|
--maxbyte | Max size in bytes | 100MB | When you want to limit file size exactly |
--maxmega | Max size in megabytes | 100MB | Easier! --maxmega 50 for 50MB limit |
--maxreq | Max recursion depth | 1000 | If includes go too deep |
๐๏ธ Advanced Control Options (For Power Users!)
| ๐ท๏ธ Flag | ๐ What It Does | ๐ฏ Perfect For | ๐ก Example |
|---|---|---|---|
--nochange or --nc | Don't replace these includes | Keep system includes as-is | --nochange stdio.h |
--noinclude or --ni | Skip these files completely | Exclude external libraries | --noinclude dependencies/ |
--perpetual or --p | Allow multiple inclusions | Headers that can be included many times | --perpetual common_macros.h |
๐ Real-World Examples:
๐ฅ Beginner Example:
# Just combine everything - simple!
./CAmalgamator --file src/main.c --output build/single_file.c
๐ฅ Intermediate Example:
# Limit size and exclude system headers
./CAmalgamator --file main.c --output combined.c --maxmega 10 --nochange stdio.h
๐ฅ Advanced Example:
# Skip dependencies folder but allow perpetual includes
./CAmalgamator --file src/main.c --output release/final.c \
--noinclude dependencies/ \
--perpetual common_macros.h \
--maxmega 50
๐จ Common Beginner Mistakes (And How to Avoid Them!)
โ DON'T DO THIS:
# Missing required flags - this will fail!
./CAmalgamator main.c
โ DO THIS INSTEAD:
# Always include both --file and --output
./CAmalgamator --file main.c --output combined.c
โ DON'T DO THIS:
# Using same name for input and output - BAD!
./CAmalgamator --file main.c --output main.c
โ DO THIS INSTEAD:
# Use different names to avoid overwriting
./CAmalgamator --file main.c --output main_combined.c
๐งโ๐ป API Usage (For Programmers Who Want to Integrate!)
๐ฏ Beginner Note: This section is for people who want to use CAmalgamator inside their own C programs. If you just want to use the command-line tool, you can skip this section!
๐ Quick Setup (Get the API Library)
Download the API header file:
# Get the complete API (easiest way)
curl -L https://github.com/OUIsolutions/CAmalgamator/releases/download/0.002/CAmalgamatorApiOne.h -o CAmalgamatorApiOne.h
๐ฌ Simple Example (Your First API Program!)
Create a file called my_amalgamator.c:
#include <stdio.h>
#include "CAmalgamatorApiOne.h"
int main() {
// Initialize the amalgamator
CAmalgamatorNamesapce amalgamator = newCAmalgamatorNamesapce();
// Settings (you can change these!)
const char *starting_file = "src/cli/main.c"; // Where to start
int max_recursion = 1000; // How deep to go
int max_size = amalgamator.ONE_MB * 10; // Max 10MB output
// Do the magic! โจ
CAmalgamatorErrorOrContent *result = amalgamator.generate_amalgamation_simple(
starting_file,
max_size,
max_recursion
);
// Check if it worked
if(result->error) {
printf("โ Oops! Something went wrong: %s\n", result->error_msg);
amalgamator.free_error_or_string(result);
return 1;
}
// Success! Print the combined code
printf("โ
Success! Here's your combined code:\n\n%s", result->content);
// Clean up memory (important!)
amalgamator.free_error_or_string(result);
printf("\n๐ All done!\n");
return 0;
}
Compile and run:
gcc my_amalgamator.c -o my_amalgamator
./my_amalgamator
๐๏ธ Advanced Example (With Custom Control!)
Want more control over what gets included? Here's how:
#include <stdio.h>
#include "CAmalgamatorApiOne.h"
CAmalgamatorNamesapce amalgamator;
// This function decides what to do with each file
short my_custom_callback(const char *filename, const char *include_name, void *args) {
printf("๐ Found: %s (included from %s)\n", include_name, filename);
// You can add your own logic here!
// For example, skip all .txt files:
if (strstr(include_name, ".txt") != NULL) {
printf("โญ๏ธ Skipping .txt file: %s\n", include_name);
return amalgamator.DONT_INCLUDE;
}
// Include everything else once
return amalgamator.INCLUDE_ONCE;
}
int main() {
amalgamator = newCAmalgamatorNamesapce();
const char *starting_file = "src/cli/main.c";
int max_recursion = 1000;
int max_size = amalgamator.ONE_MB * 10;
void *custom_args = NULL; // You can pass custom data here
// Use the custom callback for more control
CAmalgamatorErrorOrContent *result = amalgamator.generate_amalgamation(
starting_file,
max_size,
max_recursion,
my_custom_callback, // Our custom function!
custom_args
);
if(result->error) {
printf("โ Error: %s\n", result->error_msg);
amalgamator.free_error_or_string(result);
return 1;
}
printf("โ
Success! Here's your custom amalgamation:\n\n%s", result->content);
amalgamator.free_error_or_string(result);
return 0;
}
๐ฏ Callback Return Values (What Each One Does)
When you use a custom callback, you can return different values to control behavior:
| ๐ท๏ธ Namespace | ๐ท๏ธ Pure Constant | ๐ What It Does | ๐ก When to Use |
|---|---|---|---|
amalgamator.DONT_INCLUDE | CAMALGAMATOR_DONT_INCLUDE | Skip this file completely | External libraries you don't want |
amalgamator.DONT_CHANGE | CAMALGAMATOR_DONT_CHANGE | Keep the #include as-is | System headers like <stdio.h> |
amalgamator.INCLUDE_ONCE | CAMALGAMATOR_INCLUDE_ONCE | Include the file once | Most normal files |
amalgamator.INCLUDE_PERPETUAL | CAMALGAMATOR_INCLUDE_PERPETUAL | Include every time it's found | Macros that can be included multiple times |
๐จ Important Notes for Beginners:
- Always check for errors! The API can fail if files don't exist or are too big.
- Don't forget to free memory! Always call
free_error_or_string()when done. - Start simple! Use
generate_amalgamation_simple()first, then try the advanced version.
๐จ Building from Scratch (For Advanced Users!)
๐ฏ Beginner Note: You don't need this section if you just downloaded the ready-made executables above! This is only for people who want to compile CAmalgamator themselves.
๐ Prerequisites (What You Need First)
You'll need these tools installed:
- ๐ฆ Darwin Build System (Version 0.020+)
- ๐ณ Docker OR ๐ซ Podman (for containerized builds)
- ๐ง Linux Environment (recommended)
๐ One-Line Darwin Installation (Linux Only!)
# Install Darwin build system in one command
curl -L https://github.com/OUIsolutions/Darwin/releases/download/0.7.0/darwin.out -o darwin.out && sudo chmod +x darwin.out && sudo mv darwin.out /usr/bin/darwin
๐ Clone and Build
# 1. Clone the repository
git clone https://github.com/OUIsolutions/CAmalgamator.git
cd CAmalgamator
# 2. Build all variants (this will take a while!)
darwin run_blueprint build/ --mode folder amalgamation_build alpine_static_build windowsi32_build windowsi64_build rpm_static_build debian_static_build
๐ After building, you'll have:
- Linux executables
- Windows executables (32-bit and 64-bit)
- RPM packages
- DEB packages
- Static builds
- And more!
๐ค What Gets Built?
| ๐๏ธ Build Target | ๐ Description | ๐ฏ Output |
|---|---|---|
amalgamation_build | Single C file version | CAmalgamator.c |
alpine_static_build | Static Linux binary | Linux executable |
windowsi32_build | 32-bit Windows | .exe file |
windowsi64_build | 64-bit Windows | .exe file |
rpm_static_build | RPM package | .rpm file |
debian_static_build | Debian package | .deb file |
๐จ Troubleshooting Common Build Issues
โ "darwin: command not found"
- Solution: Make sure Darwin is installed and in your PATH
โ "Docker/Podman not found"
- Solution: Install Docker or Podman for containerized builds
โ "Permission denied"
- Solution: Make sure you have execute permissions on build scripts
๐ Need Help? (We've Got You Covered!)
๐ค Community Support
- ๐ Found a Bug? Create an Issue
- ๐ก Have a Feature Idea? Suggest It Here
- โญ Like the Project? Give us a star on GitHub!
๐ Common Questions
Q: "Can I use this with C++?" A: CAmalgamator is designed for C, but it might work with simple C++ code. Try it and see!
Q: "What about very large projects?"
A: Use the --maxmega flag to set size limits. For huge projects, consider breaking them into smaller parts first.
Q: "Can I exclude certain system headers?"
A: Yes! Use --nochange to keep system includes like <stdio.h> as-is.
Q: "Is it safe to use in production?" A: Absolutely! Many developers use amalgamation for distribution. Just test thoroughly first.
๐ Success Stories & Use Cases
๐ Perfect For:
- ๐ Students: Submit single-file assignments easily
- ๐ Competitive Programming: Many contests prefer single files
- ๐ฆ Library Distribution: Create easy-to-use single-header libraries
- ๐ Embedded Systems: Simplify builds for microcontrollers
- ๐ฑ Mobile Development: Reduce complexity in mobile C libraries
๐ฌ What Users Say:
"CAmalgamator saved me hours of build configuration headaches!" - DevStudent2024
"Perfect for my competitive programming setup. One command and I'm ready to submit!" - CodeWarrior
"Made distributing my C library so much easier. My users love the single-header approach!" - LibraryMaker
๐ Ready to Simplify Your C Development?
โฌ๏ธ Download Now | โญ Star on GitHub | ๐ Report Issues
Made with โค๏ธ by OUIsolutions
Simplifying C development, one amalgamation at a time! โจ