From 0da5c2feb480bc51dd552388c13d20643756b784 Mon Sep 17 00:00:00 2001 From: Nayan <33187059+GShadow5@users.noreply.github.com> Date: Wed, 7 May 2025 23:47:05 -0400 Subject: [PATCH] rewrite makefile to handle all the files with pattern matching --- Makefile | 49 ++++++++++++++++++++++++++++++++++++------------- readme.md | 2 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7016b53..49d3bcb 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,43 @@ -all: webserver.o client_handler.o request_handler.o http_stuff.o - gcc -o webserver.out *.o -lpthread +# Compiler and flags +CC = gcc +DEBUG_FLAGS = -g -Wall -Wextra +RELEASE_FLAGS = -Wall -Wextra +LFLAGS = -lpthread -debug: - gcc -g -o webserver.out webserver.c client_handler.h client_handler.c request_handler.h request_handler.c http_stuff.h http_stuff.c -lpthread +# Source files +SRCS = webserver.c client_handler.c request_handler.c http_stuff.c -webserver: webserver.c - gcc -c webserver webserver.c +# Object files definition +OBJS = $(SRCS:.c=.o) -client_handler: client_handler.c client_handler.h request_handler.h - gcc -c client_handler client_handler.c +TARGET = webserver.out -request_handler: request_handler.c request_handler.h http_stuff.h - gcc -c request_handler request_handler.c -http_stuff: http_stuff.c http_stuff.h - gcc -c http_stuff http_stuff.c +# BUILD STUFF + +# Default to debug +all: debug + +debug: CFLAGS = $(DEBUG_FLAGS) +debug: $(TARGET) + +release: CFLAGS = $(RELEASE_FLAGS) +release: $(TARGET) + +# Link object files +$(TARGET): $(OBJS) + $(CC) -o $(TARGET) $(OBJS) $(LFLAGS) + +# Compile object files +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +# Object dependencies +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o *.out \ No newline at end of file + rm -f $(OBJS) + rm -f $(TARGET) + +.PHONY: all debug release clean \ No newline at end of file diff --git a/readme.md b/readme.md index fe51248..077d51a 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,7 @@ I also plan to publish this as a portfolio project for my resume. - [x] Get url parsing working - [x] Fix existing bugs in socket handling and TCP buffering - [x] Finish code to parse HTTP requests -- [ ] Update makefile to be more flexible +- [x] Update makefile to be more flexible - [ ] Finish code to build HTTP responses - [ ] Get html file serving working - [ ] Implement file uploads (with restricted file types)