Prerequisites
Before building Push Swap, ensure you have the following tools installed:- C Compiler:
ccorgcc - Make: GNU Make build system
- POSIX-compliant system: Linux, macOS, or Unix-like environment
Build System Overview
Push Swap uses a Makefile-based build system with standard 42 School conventions. The build process compiles all source files with strict error checking enabled.Compiler Configuration
The project is compiled with the following flags:- -Wall: Enable all common warning messages
- -Wextra: Enable additional warning messages
- -Werror: Treat all warnings as errors (ensures clean code)
Source Files
The project consists of 14 C source files:Building the Project
Clone or navigate to the source directory
Navigate to the directory containing the Makefile and source files.
Run the default build target
Compile the project using the Or explicitly:This will:
all target (default):- Compile each
.cfile into a.oobject file - Link all object files into the
push_swapexecutable
Makefile Targets
The Makefile provides several targets for different build operations:make all
Default target. Compiles all source files and creates the push_swap executable.
make clean
Removes all object files (.o files) but preserves the executable.
- Cleaning up intermediate build artifacts
- Reducing disk space usage
- Preparing for a fresh compilation
make fclean
Removes all object files AND the executable. Complete cleanup.
- Calls
cleanto remove object files - Removes the
push_swapexecutable
make re
Performs a complete rebuild from scratch.
- You’ve made changes to header files
- You want to ensure a completely fresh build
- You’re troubleshooting build issues
Build Output
Successful Build
During compilation, you’ll see output similar to:push_swap will be located in the project root directory.
Build Artifacts
After building, your directory will contain:- Object files:
*.o(one for each source file) - Executable:
push_swap - Source files:
*.cand*.h(unchanged)
Troubleshooting
Compilation Errors
If you encounter compilation errors:The project uses
-Werror, which treats warnings as errors. This ensures code quality but means even minor issues will prevent compilation.-
Check compiler version: Ensure you have a modern C compiler
-
Clean and rebuild: Try a fresh build
-
Check for missing files: Verify all source files are present
Make Not Found
Ifmake command is not available:
Manual Compilation
If you need to compile manually without Make:Next Steps
After successfully building the project:- Learn how to test the program
- Understand the algorithm implementation
- Try different usage examples