EX_03/powerset/Makefile
2025-09-22 17:29:05 +01:00

71 lines
1.6 KiB
Makefile

# Program name
NAME = powerset
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -Werror
# Source files
SRCS = powerset.c
OBJS = $(SRCS:.c=.o)
# Header files
HEADERS = powerset.h
# Colors for output
GREEN = \033[0;32m
RED = \033[0;31m
RESET = \033[0m
# Default target
all: $(NAME)
# Build the program
$(NAME): $(OBJS)
@echo "$(GREEN)Linking $(NAME)...$(RESET)"
@$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
@echo "$(GREEN)$(NAME) compiled successfully!$(RESET)"
# Compile source files to object files
%.o: %.c $(HEADERS)
@echo "$(GREEN)Compiling $<...$(RESET)"
@$(CC) $(CFLAGS) -c $< -o $@
# Clean object files
clean:
@echo "$(RED)Cleaning object files...$(RESET)"
@rm -f $(OBJS)
# Clean everything
fclean: clean
@echo "$(RED)Cleaning $(NAME)...$(RESET)"
@rm -f $(NAME)
# Rebuild everything
re: fclean all
# Test the program with the examples from the subject
test: $(NAME)
@echo "$(GREEN)Running tests...$(RESET)"
@echo "\n$(GREEN)Test 1: powerset 3 1 0 2 4 5 3$(RESET)"
@./$(NAME) 3 1 0 2 4 5 3
@echo "\n$(GREEN)Test 2: powerset 12 5 2 1 8 4 3 7 11$(RESET)"
@./$(NAME) 12 5 2 1 8 4 3 7 11
@echo "\n$(GREEN)Test 3: powerset 0 1 -1$(RESET)"
@./$(NAME) 0 1 -1
@echo "\n$(GREEN)Test 4: powerset 7 3 8 2 (should be empty)$(RESET)"
@./$(NAME) 7 3 8 2
@echo "$(GREEN)✓ All tests completed!$(RESET)"
# Help
help:
@echo "Available targets:"
@echo " all - Build the program (default)"
@echo " clean - Remove object files"
@echo " fclean - Remove object files and executable"
@echo " re - Rebuild everything"
@echo " test - Run test cases"
@echo " help - Show this help message"
# Declare phony targets
.PHONY: all clean fclean re test help