From e87795a6c8d7f2f5047616d948bedcdb8b49df0b Mon Sep 17 00:00:00 2001 From: seajee Date: Sat, 2 Aug 2025 23:47:19 +0200 Subject: [PATCH] Simplify Makefile --- Makefile | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 088ef99..f17f912 100644 --- a/Makefile +++ b/Makefile @@ -2,47 +2,18 @@ CC=gcc CFLAGS=-Wall -Wextra -ggdb -I. LDFLAGS=-lpthread +EXAMPLES=$(wildcard examples/*.c) +BUILDS=$(patsubst examples/%.c, build/%, $(EXAMPLES)) + .PHONY: all clean -all: build/hello_server build/hello_client build/hello_server_v6 \ - build/hello_client_v6 build/chat_server build/chat_client \ - build/udp_server build/udp_client build/http_request +all: $(BUILDS) -build/hello_server: examples/hello_server.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/hello_server examples/hello_server.c $(LDFLAGS) +build/%: examples/%.c sock.h build + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -build/hello_client: examples/hello_client.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/hello_client examples/hello_client.c $(LDFLAGS) - -build/hello_server_v6: examples/hello_server_v6.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/hello_server_v6 examples/hello_server_v6.c $(LDFLAGS) - -build/hello_client_v6: examples/hello_client_v6.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/hello_client_v6 examples/hello_client_v6.c $(LDFLAGS) - -build/chat_server: examples/chat_server.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/chat_server examples/chat_server.c $(LDFLAGS) - -build/chat_client: examples/chat_client.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/chat_client examples/chat_client.c $(LDFLAGS) - -build/udp_server: examples/udp_server.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/udp_server examples/udp_server.c $(LDFLAGS) - -build/udp_client: examples/udp_client.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/udp_client examples/udp_client.c $(LDFLAGS) - -build/http_request: examples/http_request.c sock.h - @mkdir -p build - $(CC) $(CFLAGS) -o build/http_request examples/http_request.c $(LDFLAGS) +build: + mkdir -p build clean: rm -rf build