Update Makefile

Update for better understating the progress stage
This commit is contained in:
2025-02-28 19:57:53 +01:00
committed by GitHub
parent 3815b2d32a
commit eaf6e27154

View File

@@ -1,5 +1,12 @@
# Makefile for HTTP Server
# Colors for output
GREEN := \033[1;32m
YELLOW := \033[1;33m
RED := \033[1;31m
BLUE := \033[1;34m
NC := \033[0m
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE
@@ -17,29 +24,44 @@ HEADERS = server_config.h
# Include directories
INCLUDES = -I/usr/include/cjson
# Count total number of source files
TOTAL_FILES := $(words $(SRCS))
CURRENT_FILE = 0
# Default target
all: $(TARGET)
@echo "$(GREEN)Build complete! ✓$(NC)"
# Linking
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS) $(LIBS)
@echo "$(BLUE)Linking...$(NC)"
@$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS) $(LIBS) \
|| (echo "$(RED)Linking failed ✗$(NC)" && exit 1)
@echo "$(GREEN)Linking successful ✓$(NC)"
# Compilation
# Compilation with progress
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
@$(eval CURRENT_FILE=$(shell echo $$(($(CURRENT_FILE)+1))))
@echo "$(YELLOW)Building [$$(( $(CURRENT_FILE) * 100 / $(TOTAL_FILES) ))%] $<$(NC)"
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ \
|| (echo "$(RED)Compilation failed for $< ✗$(NC)" && exit 1)
# Clean build files
clean:
rm -f $(OBJS) $(TARGET)
@echo "$(BLUE)Cleaning build files...$(NC)"
@rm -f $(OBJS) $(TARGET)
@echo "$(GREEN)Clean complete ✓$(NC)"
# Install dependencies (for Debian/Ubuntu/Raspberry Pi OS)
install-deps:
sudo apt-get update
sudo apt-get install -y \
@echo "$(BLUE)Installing dependencies...$(NC)"
@sudo apt-get update
@sudo apt-get install -y \
libssl-dev \
libcjson-dev \
libmagic-dev \
build-essential
@echo "$(GREEN)Dependencies installed ✓$(NC)"
# Debug build
debug: CFLAGS += -g -DDEBUG
@@ -49,4 +71,4 @@ debug: clean all
release: CFLAGS += -O3 -march=native -flto
release: clean all
.PHONY: all clean install-deps debug release
.PHONY: all clean install-deps debug release