Skip to main content

Prerequisites

Before installing Push Swap, ensure you have:
1

C Compiler

GCC or Clang compiler supporting C99 standard or later
# Check if you have a C compiler
gcc --version
# or
clang --version
2

Make Build Tool

GNU Make for building the project
# Check if make is installed
make --version
3

Git (Optional)

For cloning the repository
git --version
On macOS, you can install the Xcode Command Line Tools to get all prerequisites:
xcode-select --install

Installation Steps

1

Clone the Repository

Download the source code to your local machine:
git clone <repository-url> push_swap
cd push_swap
Or download and extract the source files manually if you don’t have git.
2

Build the Project

Compile the source code using the Makefile:
make
This command:
  • Compiles all .c files with strict flags (-Wall -Wextra -Werror)
  • Links object files into the final executable
  • Creates the push_swap binary
$ make
cc -Wall -Wextra -Werror -c push_swap.c -o push_swap.o
cc -Wall -Wextra -Werror -c ft_error_exit.c -o ft_error_exit.o
cc -Wall -Wextra -Werror -c ft_split.c -o ft_split.o
cc -Wall -Wextra -Werror -c init_a_to_b.c -o init_a_to_b.o
cc -Wall -Wextra -Werror -c init_b_to_a.c -o init_b_to_a.o
cc -Wall -Wextra -Werror -c sort_big_stacks.c -o sort_big_stacks.o
cc -Wall -Wextra -Werror -c stack_utils.c -o stack_utils.o
cc -Wall -Wextra -Werror -c ft_fill_stack.c -o ft_fill_stack.o
cc -Wall -Wextra -Werror -c main.c -o main.o
cc -Wall -Wextra -Werror -c ft_push.c -o ft_push.o
cc -Wall -Wextra -Werror -c ft_reverse_rotate.c -o ft_reverse_rotate.o
cc -Wall -Wextra -Werror -c ft_rotate.c -o ft_rotate.o
cc -Wall -Wextra -Werror -c ft_swap.c -o ft_swap.o
cc -Wall -Wextra -Werror -c min_on_top.c -o min_on_top.o
cc -Wall -Wextra -Werror push_swap.o ft_error_exit.o ft_split.o \
  init_a_to_b.o init_b_to_a.o sort_big_stacks.o stack_utils.o \
  ft_fill_stack.o main.o ft_push.o ft_reverse_rotate.o ft_rotate.o \
  ft_swap.o min_on_top.o -o push_swap
3

Verify Installation

Test that the executable was created successfully:
./push_swap
You should see no output (the program exits silently with no arguments, which is correct behavior).Try a simple test:
./push_swap 3 2 1
You should see output like:
sa
rra

Makefile Commands

The project includes several useful Make targets:

make or make all

Builds the project (default target).
make

make clean

Removes object files (.o files) but keeps the executable.
make clean

make fclean

Removes all generated files including the executable.
make fclean

make re

Rebuilds the project from scratch (equivalent to make fclean + make).
make re
Use make re when you want to ensure a completely fresh build, especially after modifying header files.

Compilation Flags

The project is compiled with strict warning flags to ensure code quality:
CFLAGS = -Wall -Wextra -Werror
  • -Wall: Enable all common warnings
  • -Wextra: Enable extra warnings not covered by -Wall
  • -Werror: Treat all warnings as errors (compilation fails if warnings exist)
These flags ensure the code is clean and follows best practices.

Project Structure

After building, your directory will contain:
push_swap/
├── push_swap          # Main executable
├── push_swap.h        # Header file
├── *.c                # Source files
├── *.o                # Object files (after compilation)
└── Makefile           # Build configuration

Troubleshooting

You need to install a C compiler.On Ubuntu/Debian:
sudo apt-get update
sudo apt-get install build-essential
On macOS:
xcode-select --install
On Fedora/RHEL:
sudo dnf install gcc make
Install GNU Make:On Ubuntu/Debian:
sudo apt-get install make
On macOS:
xcode-select --install
The project uses strict compilation flags (-Werror). If you see compilation errors:
  1. Ensure you’re using a C99-compatible compiler
  2. Check that all source files are present
  3. Try a clean rebuild:
    make fclean
    make
    
  4. Verify your compiler version is recent enough:
    gcc --version
    
Make the binary executable:
chmod +x push_swap
./push_swap
Check for error messages during compilation. If the build appears successful but no executable exists:
  1. Verify all source files are present
  2. Check disk space: df -h
  3. Try rebuilding: make re
  4. Check the Makefile for the correct output name (should be push_swap)

Uninstallation

To remove all compiled files:
make fclean
To completely remove the project:
cd ..
rm -rf push_swap

Next Steps

Quick Start

Learn how to use Push Swap with examples

Usage Examples

See common usage patterns and commands

Build docs developers (and LLMs) love