Skip to main content

Prerequisites

Before building Minishell, ensure you have the following installed on your system:
  • GCC or Clang: C compiler supporting C99 standard
  • GNU Make: Build automation tool
  • Readline library: Development headers and library files
    • On Ubuntu/Debian: sudo apt-get install libreadline-dev
    • On macOS: brew install readline
  • Git: For cloning the repository
Minishell follows the 42 school norm and compiles with strict compiler flags: -Wall -Wextra -Werror

Build Process

1

Clone the Repository

git clone <repository-url>
cd minishell
2

Compile the Project

Build the executable using the default target:
make
This compiles all source files and links them with the readline library to produce the minishell executable.
3

Run Minishell

./minishell

Makefile Targets

The Makefile provides several targets for building and cleaning:

make or make all

Compiles all source files and creates the minishell executable.
CC       = cc
CFLAGS   = -Wall -Wextra -Werror -g
READLINE = -lreadline
NAME     = minishell

make clean

Removes object files (.o files) while preserving the executable:
make clean

make fclean

Removes both object files and the executable:
make fclean

make re

Performs a complete rebuild by running fclean followed by all:
make re
The re target is useful when you want to ensure a completely clean build, especially after modifying header files.

Compiler Flags Explained

Minishell uses strict compilation flags to ensure code quality:
FlagPurpose
-WallEnable all common warnings
-WextraEnable extra warnings not covered by -Wall
-WerrorTreat all warnings as errors (compilation fails on warnings)
-gInclude debugging information for use with debuggers like GDB
The -Werror flag means your code must be completely warning-free to compile. This enforces clean, high-quality code.

Linking Requirements

Minishell requires the GNU Readline library for interactive input:
READLINE = -lreadline
The Makefile links against readline using the -lreadline flag. This library provides:
  • Command line editing
  • Command history (add_history() in main.c:19)
  • Input reading with prompts (readline() in main.c:110)

Debugging Builds

The -g flag is included by default in CFLAGS, enabling debugging:

Using GDB

# Compile with debug symbols (already included)
make

# Run with GDB
gdb ./minishell
Useful GDB commands:
(gdb) break main           # Set breakpoint at main
(gdb) run                  # Start execution
(gdb) next                 # Step to next line
(gdb) print variable       # Print variable value
(gdb) backtrace            # Show call stack

Using LLDB (macOS)

lldb ./minishell
The debug symbols included with -g don’t affect the functionality of the program but increase the binary size and enable debugging.

Common Build Errors

Problem: Readline development headers are not installed.Solution:
# Ubuntu/Debian
sudo apt-get install libreadline-dev

# macOS
brew install readline

# If on macOS and still failing, you may need to specify the path:
export CFLAGS="-I/usr/local/opt/readline/include"
export LDFLAGS="-L/usr/local/opt/readline/lib"
Problem: The readline library is not being linked properly.Solution: Ensure your system has a recent version of readline (version 6.0+). Update the library:
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install --reinstall libreadline-dev
Problem: Function used without proper header inclusion or prototype.Solution:
  • Check that all necessary headers are included in minishell.h
  • Verify function prototypes are declared before use
  • Remember: -Werror treats this warning as an error
Problem: Global variable defined in multiple source files.Solution: The global variable g_status should only be defined once in main.c (line 15) and declared as extern in minishell.h (line 178).
Problem: Source file listed in Makefile doesn’t exist or is misspelled.Solution:
  • Verify all files in CFILES exist in the project directory
  • Check for typos in filenames
  • Ensure no trailing spaces in the Makefile

Build Performance

The project contains 24 source files. Typical build times:
  • Full build (make): 2-5 seconds
  • Incremental build (after modifying one file): < 1 second
  • Clean rebuild (make re): 2-5 seconds
Make automatically handles dependencies. Only modified files and their dependents are recompiled during incremental builds.

Next Steps

After successfully building Minishell:

Build docs developers (and LLMs) love